Update useSession to pause before SSR hydration completes#880
Update useSession to pause before SSR hydration completes#880MillanWangGadget wants to merge 1 commit into
useSession to pause before SSR hydration completes#880Conversation
e96b533 to
2651fc1
Compare
| const fallbackApi = useApi(); | ||
| const api = client ?? (fallbackApi as ClientType); | ||
|
|
||
| const [hydrated, setHydrated] = useState(!fallbackApi); |
There was a problem hiding this comment.
should all of our hooks pause until hydrated?
There was a problem hiding this comment.
Hmm - The would feel more correct to have more consistent behaviour. useSession here relies on useGet which could get the same pause until hydrated behaviour, but this useSession hook would need it too to prevent throwing the no currentSession error before hydration
| @@ -69,6 +75,7 @@ export function useSession< | |||
|
|
|||
| const opts: any = { | |||
| suspense: true, | |||
There was a problem hiding this comment.
does this have anything to do with this suspense?
There was a problem hiding this comment.
ok so after some reading I think the issue is that we have a <Suspense> boundary at the top level of the app and what happens on hydration is the useSession hook suspends which suspends up to the top level boundary; if before that suspense resolves some other state changes then we will get this hydration error
I think maybe the better solution is to move the suspense boundary closer to where the useSession is called
|
can you think of a way to test this? |
I'm gonna investigate this. I've been testing this by putting the prerelease into prod apps, and repeatedly refreshing the page
Yes. I've only observed that on prod web apps in logged in areas because of |
|
Closing this in favour of hiding suppressing the hydration error in the same way that we do for other hydration errors |

useSessionsuch asuseSignOutbeing used before the hydration completesPrerelease
🎩 Instructions
please 🎩: