Skip to content

Commit

Permalink
fix: missing dependency on inject function
Browse files Browse the repository at this point in the history
- The missing dependency on the inject function causes the effect to update the store with stale data when the parent store updates
- The destruction has been moved to a separate hook, so it continues to run only on component unmount
  • Loading branch information
notrabs committed May 7, 2024
1 parent 39fe68b commit b4e0e3a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/fiber/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,22 @@ function Portal({
const unsub = previousRoot.subscribe((prev) => usePortalStore.setState((state) => inject(prev, state)))
return () => {
unsub()
usePortalStore.destroy()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [inject])

React.useEffect(() => {
usePortalStore.setState((injectState) => inject(previousRoot.getState(), injectState))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inject])

React.useEffect(() => {
return () => {
usePortalStore.destroy()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return (
<>
{reconciler.createPortal(
Expand Down

0 comments on commit b4e0e3a

Please sign in to comment.