Skip to content

Commit

Permalink
remove weird server resource hack, fix hydrated resource state
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Jun 28, 2024
1 parent 5d451be commit a8c2a8f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-pumpkins-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

remove weird server resource hack, fix hydrated resource state
2 changes: 1 addition & 1 deletion packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export function createResource<T, S, R>(
pr = p;
if ("value" in p) {
if ((p as any).status === "success") loadEnd(pr, p.value as T, undefined, lookup);
else loadEnd(pr, undefined, undefined, lookup);
else loadEnd(pr, undefined, castError(p.value), lookup);
return p;
}
scheduled = true;
Expand Down
9 changes: 0 additions & 9 deletions packages/solid/src/server/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ export type ResourceOptions<T> = undefined extends T
};

const SuspenseContext = createContext<SuspenseContextType>();
let resourceContext: any[] | null = null;
export function createResource<T, S = true>(
fetcher: ResourceFetcher<S, T>,
options?: ResourceOptions<undefined>
Expand Down Expand Up @@ -383,7 +382,6 @@ export function createResource<T, S>(
}
const read = () => {
if (error) throw error;
if (resourceContext && p) resourceContext.push(p!);
const resolved =
options.ssrLoadFrom !== "initial" &&
sharedConfig.context!.async &&
Expand Down Expand Up @@ -413,14 +411,7 @@ export function createResource<T, S>(
value = ctx.resources[id].data;
return;
}
resourceContext = [];
const lookup = typeof source === "function" ? (source as () => S)() : source;
if (resourceContext.length) {
p = Promise.all(resourceContext).then(() =>
(fetcher as ResourceFetcher<S, T>)((source as Accessor<S>)(), { value })
);
}
resourceContext = null;
if (!p) {
if (lookup == null || lookup === false) return;
p = (fetcher as ResourceFetcher<S, T>)(lookup, { value });
Expand Down

0 comments on commit a8c2a8f

Please sign in to comment.