You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check if updating to the latest Preact version resolves the issue
Describe the bug
I was debugging an issue in Zustand over in pmndrs/zustand#1137 and it looks like the issue stems from Preact's implementation of useSyncExternalStore:
exportfunctionuseSyncExternalStore(subscribe,getSnapshot){const[state,setState]=useState(getSnapshot);// TODO: in suspense for data we could have a discrepancy here because Preact won't re-init the "useState"// when this unsuspends which could lead to stale state as the subscription is torn down.useEffect(()=>{returnsubscribe(()=>{setState(getSnapshot());});},[subscribe,getSnapshot]);returnstate;}
Specifically, if getSnapshot returns a function, setState will execute it as per the usual behavior of setState when passed a function.
Describe the bug
I was debugging an issue in Zustand over in pmndrs/zustand#1137 and it looks like the issue stems from Preact's implementation of
useSyncExternalStore
:Specifically, if
getSnapshot
returns a function,setState
will execute it as per the usual behavior ofsetState
when passed a function.However, the documentation for
getSyncExternalStore
doesn't say anything about executing a function returned fromgetSnapshot
nor does the shim version appear to do that so I can only guess that this is a bug in Preact.To Reproduce
Sorry, I haven't had a chance to set up a minimal repro yet.
Expected behavior
It should not execute a function returned by
getSnapshot()
.The text was updated successfully, but these errors were encountered: