Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(signals-react): use isomorphic layout #611

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/react/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ function cleanupTrailingStore() {
currentStore?.f();
}

const useIsomorphicLayoutEffect =
typeof window !== "undefined" ? useLayoutEffect : useEffect;

/**
* Custom hook to create the effect to track signals used during render and
* subscribe to changes to rerender the component when the signals change.
Expand All @@ -334,7 +337,7 @@ export function _useSignalsImplementation(
useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
store._start();
// note: _usage is a constant here, so conditional is okay
if (_usage === UNMANAGED) useLayoutEffect(cleanupTrailingStore);
if (_usage === UNMANAGED) useIsomorphicLayoutEffect(cleanupTrailingStore);

return store;
}
Expand Down