Skip to content
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

Ensure consistent component tree for useId #9805

Merged
merged 2 commits into from Jan 4, 2023

Conversation

brophdawg11
Copy link
Contributor

We found a useId mismatch when testing Remix 1.10.0-pre.5. It came down to 2 separate issues:

  • The presence of an additional <DataStaticRouterContext> during SSR. This has now been collapsed into an optional staticContext field on <DataRouterContext>
  • An extra fragment and <script>/null in StaticRouterProvider that were not reflected in RouterProvider

@changeset-bot
Copy link

changeset-bot bot commented Jan 3, 2023

🦋 Changeset detected

Latest commit: 190c776

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
react-router Patch
react-router-dom Patch
react-router-dom-v5-compat Patch
react-router-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -119,22 +119,18 @@ export function StaticRouterProvider({

return (
<>
<DataStaticRouterContext.Provider value={context}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This outer <DataStaticRouterContext> is removed in favor of a staticContext field on dataRouterContext. Easiest to see with whitespace hidden 😉

</DataRouterStateContext.Provider>
</DataRouterContext.Provider>
{null}
</>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the structure generated by RouterProvider matches that generated by StaticRouterProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused why we need the null since the docs indicate that only the parent path matters, and our useId calls would be down inside <Routes/>. But without the null I constantly ran into hydration mismatches 😕

Screenshot 2023-01-03 at 4 23 01 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind filing a question / bug over on the react repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems expected - it might just be a docs issue: facebook/react#22733. Added my own comment in there suggesting a docs update

if (__DEV__) {
DataStaticRouterContext.displayName = "DataStaticRouterContext";
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an UNSAFE export so ok to remove and add onto DataRouterContext (which is also exported as UNSAFE)

dataRouterContext.staticContext &&
match.route.errorElement
) {
dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only reason we need staticContext around in the component tree - so we can track render depth to bubble SSR render errors

@@ -98,6 +97,7 @@ export function StaticRouterProvider({
router,
navigator: getStatelessNavigator(),
static: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of the static prop in favor of the existence of the static context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite yet - we still need static for non-data-routers doing SSR

Co-authored-by: Jacob Ebey <jacob.ebey@live.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants