Skip to content

Commit bdba4dc

Browse files
authored
Fix resource instances always getting cached on SSR (#2497)
1 parent c65bccc commit bdba4dc

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

.changeset/young-donuts-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
Fix resource instances always getting cached on SSR

packages/solid/src/server/rendering.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export function createResource<T, S>(
439439
const id = sharedConfig.getNextContextId();
440440
let resource: { ref?: any; data?: T } = {};
441441
let value = options.storage ? options.storage(options.initialValue)[0]() : options.initialValue;
442-
let p: Promise<T> | T | null;
442+
let p: Promise<T> | T | null | undefined;
443443
let error: any;
444444
if (sharedConfig.context!.async && options.ssrLoadFrom !== "initial") {
445445
resource = sharedConfig.context!.resources[id] || (sharedConfig.context!.resources[id] = {});
@@ -522,10 +522,9 @@ export function createResource<T, S>(
522522
return ctx.resources[id].data;
523523
}
524524
if (options.ssrLoadFrom !== "initial") load();
525-
return (resource.ref = [
526-
read,
527-
{ refetch: load, mutate: (v: T) => (value = v) }
528-
] as ResourceReturn<T>);
525+
const ref = [read, { refetch: load, mutate: (v: T) => (value = v) }] as ResourceReturn<T>;
526+
if (p) resource.ref = ref;
527+
return ref;
529528
}
530529

531530
export function lazy<T extends Component<any>>(

0 commit comments

Comments
 (0)