Skip to content

Commit

Permalink
fix #2250 hydration error, fix lazy component loading, better hydrati…
Browse files Browse the repository at this point in the history
…on cancelation
  • Loading branch information
ryansolid committed Aug 8, 2024
1 parent 61dd1e8 commit c8fe58e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-walls-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

fix #2250 hydration error, fix lazy component loading, better hydration cancelation
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"babel-plugin-jsx-dom-expressions": "^0.38.1",
"coveralls": "^3.1.1",
"csstype": "^3.1.0",
"dom-expressions": "0.38.1",
"hyper-dom-expressions": "0.38.1",
"dom-expressions": "0.38.3",
"hyper-dom-expressions": "0.38.3",
"jsdom": "^21.1.1",
"lit-dom-expressions": "0.38.1",
"lit-dom-expressions": "0.38.3",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
Expand Down
26 changes: 13 additions & 13 deletions packages/solid/src/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export function lazy<T extends Component<any>>(
sharedConfig.count || (sharedConfig.count = 0);
sharedConfig.count++;
(p || (p = fn())).then(mod => {
setHydrateContext(ctx);
!sharedConfig.done && setHydrateContext(ctx);
sharedConfig.count!--;
set(() => mod.default);
setHydrateContext();
Expand All @@ -367,18 +367,18 @@ export function lazy<T extends Component<any>>(
comp = s;
}
let Comp: T | undefined;
return createMemo(
() =>
(Comp = comp()) &&
untrack(() => {
if ("_SOLID_DEV_") Object.assign(Comp!, { [$DEVCOMP]: true });
if (!ctx) return Comp!(props);
const c = sharedConfig.context;
setHydrateContext(ctx);
const r = Comp!(props);
setHydrateContext(c);
return r;
})
return createMemo(() =>
(Comp = comp())
? untrack(() => {
if ("_SOLID_DEV_") Object.assign(Comp!, { [$DEVCOMP]: true });
if (!ctx || sharedConfig.done) return Comp!(props);
const c = sharedConfig.context;
setHydrateContext(ctx);
const r = Comp!(props);
setHydrateContext(c);
return r;
})
: ""
) as unknown as JSX.Element;
}) as T;
wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p);
Expand Down
1 change: 1 addition & 0 deletions packages/solid/src/render/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SharedConfig = {
export const sharedConfig: SharedConfig = {
context: undefined,
registry: undefined,
done: false,
getContextId() {
return getContextId(this.context!.count);
},
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8fe58e

Please sign in to comment.