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
I'm not sure whether this is a preact-ssr-prepass or a Preact bug, but I report here first :)
I'm migrating a project from React to Preact and I noticed a weird difference in prepass during SSR. I know Preact is not guaranteed to be fully compatible with React, so maybe this is not a bug at all :)
But looks like ref values get lost when using Suspense on SSR. Take this component as an example:
constApp=()=>{constinitialised=useRef(false);console.log("initialised",initialised.current);if(!initialised.current){initialised.current=true;}const[{ data }]=useQuery({query: ` { country(code: "HU") { name } } `});return<span>{data.country.name}</span>;};
What happens here is when the component is getting rendered in prepass:
Component sets initialised ref to true (it's false by default)
useQuery uses Suspense, so it throws a promise
Once the promise is resolved, the component gets rendered again
initialised ref value got lost, it's false again (with React it's still true)
I'm not sure whether this is a preact-ssr-prepass or a Preact bug, but I report here first :)
I'm migrating a project from React to Preact and I noticed a weird difference in prepass during SSR. I know Preact is not guaranteed to be fully compatible with React, so maybe this is not a bug at all :)
But looks like ref values get lost when using Suspense on SSR. Take this component as an example:
What happens here is when the component is getting rendered in prepass:
initialised
ref totrue
(it'sfalse
by default)useQuery
uses Suspense, so it throws a promiseinitialised
ref value got lost, it'sfalse
again (with React it's stilltrue
)To Reproduce with Preact
Sandbox with Preact: https://codesandbox.io/s/preact-ref-bug-preact-lswel?file=/src/App.js
The output is:
Expected behaviour with React
Sandbox with React: https://codesandbox.io/s/preact-ref-bug-react-h6ukj?file=/src/App.js
The output is:
Let me know if you need more details!
The text was updated successfully, but these errors were encountered: