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

NavigationMenu not working with hydration (React 18, Suspense) #2350

Open
Makxzod opened this issue Aug 19, 2023 · 7 comments
Open

NavigationMenu not working with hydration (React 18, Suspense) #2350

Makxzod opened this issue Aug 19, 2023 · 7 comments
Labels

Comments

@Makxzod
Copy link

Makxzod commented Aug 19, 2023

If you add a Suspense Await block inside a NavigationMenu Item, you will get the following error:

Code:

<NavigationMenuItem>
        <NavigationMenuTrigger>
          <Suspense>
            <Await resolve={cart}>
              {(data) => {
                const {totalQuantity} = data || {};

                return (
                    {totalQuantity > 0 && (
                      <div className="pointer-events-none absolute bottom-2 right-1.5 h-3 w-3 rounded-full bg-secondary text-center text-[9px] leading-3 text-secondary-foreground">
                        {totalQuantity}
                      </div>
                    )}
                );
              }}
            </Await>
          </Suspense>
        </NavigationMenuTrigger>

        <NavigationMenuContent className="flex-col">
          
        Content here...
          
        </NavigationMenuContent>
      </NavigationMenuItem>

Error:

react-dom.development.js:20702 Uncaught Error: This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.
at updateDehydratedSuspenseComponent (react-dom.development.js:20702:48)
at updateSuspenseComponent (react-dom.development.js:20362:16)
at beginWork (react-dom.development.js:21624:14)
at beginWork$1 (react-dom.development.js:27426:14)
at performUnitOfWork (react-dom.development.js:26560:12)
at workLoopSync (react-dom.development.js:26466:5)
at renderRootSync (react-dom.development.js:26434:7)
at performSyncWorkOnRoot (react-dom.development.js:26085:20)
at flushSyncCallbacks (react-dom.development.js:12042:22)
at commitRootImpl (react-dom.development.js:26959:3)

@Makxzod
Copy link
Author

Makxzod commented Aug 19, 2023

After troubleshooting for 4 hours, i found where the issue lies. It's these lines:

If you uncomment:

onIndicatorTrackChange={setIndicatorTrack}
rootNavigationMenu={rootNavigationMenu}

on line 349 & 358 in https://github.com/radix-ui/primitives/blob/main/packages/react/navigation-menu/src/NavigationMenu.tsx

I would prefer a complete fix, as uncommenting these lines introduce a little minor problem with focusing if you have fields that gets focused it can make the menu close etc..

Can anyone use this to fix it in the radix ui package so everyone can use this with hydration?

@TheMikeyRoss
Copy link

This same thing is happening with me with Tooltip Trigger

@phamik
Copy link

phamik commented Jan 15, 2024

Any updates on this?
facing similar issues when using with NextJS 🙏

@benoitgrelard
Copy link
Contributor

Can someone provide a reproduction sandbox?

@benoitgrelard benoitgrelard added the Resolution: Needs More Information More information is needed on this issue label Mar 8, 2024
@mikestopcontinues
Copy link

Also happening with the dropdown menu trigger. The issue is the generated id field is not stable. Using React 18.3, Remix 2.10.

@stefanvonderkrone
Copy link

Hey there,
I stumbled upon a similar issue, in my case with Radix Toast. I've created a simple project to reproduce this issue:
https://github.com/stefanvonderkrone/radix-hydration-issue

Here is the commit, that leads to the hydration issue:
stefanvonderkrone/radix-hydration-issue@9a24dfb

I hope this helps :)
If I can do anything else, hit me up :)

@stefanvonderkrone
Copy link

here is my issue:
#3301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants