Fix SSR tab hydration when using Strict Mode in development #2231
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here I've reworked the tab and panel counting mechanism to:
Symbol()
when internals aren't available (only in SSR and prod builds where double rendering does not happen)The reason for this is that React’s double rendering in strict mode in development makes SSR + hydration impossible without reaching into internals. We reference the current fiber, walk up the tree of fibers, use the position of each fiber in its list of siblings to generate the key, and then use that as a "stable" reference. It is unfortunate that we have to do this at all but React doesn't give us the ability to do this using public API. The choices you have are basically: 1. No SSR at all; 2. SSR + hydration mismatches; 3. Use internals
Fixes #2220