Skip to content

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


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

let dataRouterContext = {
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 <[email protected]>
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.

4 participants