SSR: make rehydration match initial React.Context #12742
Unanswered
frankandrobot
asked this question in
Help
Replies: 1 comment
-
Update: it looks like i can't consistently repo this---after restarting the dev server, it seems to work fine. The deploy also works w/o issues 🤷 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a simple React.Context that's used to generate a TOC---the idea is that each article adds itself to the TableOfContentsContext. The problem is that if the
setItem
method (used to add an item to the TOC) is part of the React lifecycle, I cannot seem to make the initial SSG render see the TOC. I getWarning: Did not expect server HTML to contain a <a> in <nav>.
Code to follow. Note also that the warning seems to happen only after page reload when running the development server---if I start a brand new browser tab, it seems to run fine but then i'll get the warning if I reload---so in other words, the DX breaks for me.
Here's the code:
So again, to clarify the above approach
setItem
on component initializationNote that the problem may seem to boil down to How do I properly propagate changes to React.state on initialization so that it's visible in the initial SSG render? (That is, if I populate the TOC before React loads, then it should likely work.)
Beta Was this translation helpful? Give feedback.
All reactions