-
Notifications
You must be signed in to change notification settings - Fork 115
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
SSR; statics #2
Comments
Thanks for the suggestions!
I'm supportive of us introducing a guard to avoid breakage during server-side rendering. This is a good call and is something we discussed but didn't circle back on. I'd be open to a PR with this change.
Shifting to a model where we treat all hooks short of network as providing static values likely makes sense. We started off our implementation looking at additional APIs that fired change events, but given the current scoped set doesn't heavily do this, a change here sgtm as long as tests pass. |
@addyosmani so your preferred API would still require calling an ersatz hook that returns the static values, in case these values become dynamic in the future? I think the tests can pass by messing with |
ok, the static hooks keep their API and the tests pass in #1 |
No, I can't think of anything else 👍 |
@wmertens @addyosmani Wouldn't this cause hydration to fail? Something like useNetworkStatus would return different results server side and client side, and I'm not sure if react would handle it correctly in all cases. Usually what is done is to move rendering to three phases
|
Right, but in this case you probably want hydration to fail, so
that the conservative estimate that the server did is replaced with the
correct estimate on the client side. React will only fail to hydrate the
subtree, so it should work optimally.
|
I noticed that none of the
x in navigator
statements are guarded, so they will all break when rendering server-side. I propose addingtypeof navigator !== 'undefined'
in front of all those.Furthermore, with the exception of the networking, the hooks return static data and even use
useState
to store the static data, causing extra work and memory use for something that's basically a single static value that can be determined at module load time. This confuses me, I created #1 to explain what I mean.The text was updated successfully, but these errors were encountered: