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

v3 site has hydration issues on Ubuntu #9379

Closed
5 of 7 tasks
johnnyreilly opened this issue Oct 7, 2023 · 48 comments · Fixed by #9446
Closed
5 of 7 tasks

v3 site has hydration issues on Ubuntu #9379

johnnyreilly opened this issue Oct 7, 2023 · 48 comments · Fixed by #9446
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Milestone

Comments

@johnnyreilly
Copy link
Contributor

johnnyreilly commented Oct 7, 2023

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

MIgrating my blog over to docusaurus v3 I noticed "Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings." in the console.

Translated, this error means: Hydration failed because the initial UI does not match what was rendered on the server.

You can see it on the Docusaurus site as well as on my own.

You can see a repro of the error at either of the URLs below; simply pop open the devtools console and navigate there:

Steps to reproduce

See description

Expected behavior

No errors in console

Actual behavior

Errors in console
image

The same error appears present on the docusaurus site itself:

image

I run lighthouse in github actions on my blog - it shows up there too:

image

https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1696186829813-4063.report.html

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@johnnyreilly johnnyreilly added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Oct 7, 2023
@slorber
Copy link
Collaborator

slorber commented Oct 8, 2023

I don't see any of those hydration errors on my side

CleanShot 2023-10-08 at 18 57 35@2x CleanShot 2023-10-08 at 18 56 22@2x

Tried on Chrome, Firefox, Safari, no issue found.

Maybe it's related to a local browser extension or something on your computer? I'm surprised Lighthouse reports it though.

@Josh-Cena Josh-Cena changed the title v3 blog posts have hydration issues; Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 v3 blog posts have hydration issues; Minified React error #41818 Oct 8, 2023
@Josh-Cena Josh-Cena changed the title v3 blog posts have hydration issues; Minified React error #41818 v3 blog posts have hydration issues; Minified React error #418 Oct 8, 2023
@johnnyreilly
Copy link
Contributor Author

Lighthouse isn't running on my machine - it's on GitHub actions. So it's not a "my machine" only issue. It was actually the lighthouse report that I first noticed - then I thought I'd have a look on my own machine and found it there too.

I run Ubuntu locally - but I assume the OS isn't necessarily relevant?

@johnnyreilly
Copy link
Contributor Author

BTW when testing, are you opening devtools before navigating? I didn't see them locally until I opened devtools prior to entering the URL in the browser. Also, it only seems to be the blog section that's affected

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 8, 2023

Interesting - cracked open my work computer (Mac OS) and there's no issue there:

image

Also I took a look at the Lighthouse GitHub Action; it runs on Ubuntu also: https://github.com/treosh/lighthouse-ci-action/blob/7f5e1fde07d17cbb1c47873c81441f53c0f72fcf/.github/workflows/main.yml#L5

It looks like this might be an Ubuntu / Linux specific issue. (I haven't tested on Windows - don't know if it surfaces there as well)

@slorber slorber added status: needs more information There is not enough information to take action on the issue. and removed status: needs triage This issue has not been triaged by maintainers labels Oct 9, 2023
@slorber
Copy link
Collaborator

slorber commented Oct 9, 2023

I don't know but that seems hard to reproduce currently 😅

If you are able to reproduce it locally, that would be interesting to compare the DOM html you get with/without JS, and see how they differ.

I have been careful to fix all the hydrations issues we had for v3. Those issues existed before in v2 (but silently ignored). They are now logged to the console due to a new React 18 onRecoverableError callback.

@johnnyreilly
Copy link
Contributor Author

I can reproduce locally super easily on my home Ubuntu machine. My guess is any Ubuntu machine would do the job.

So you'd like the originally served HTML and what the DOM html looks like after it starts?

Is there a best way to surface the DOM html? Devtools and copy outerhtml?

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 9, 2023

As a first test, I tried comparing the supposedly working hydration on my Mac (no errors) and found that non-hydrated and hydrated already look pretty different. But that's appears to be fine.

How did you manage to fix the existing hydration issues @slorber? Doesn't look like there's much to go on looking at facebook/react#26224

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 9, 2023

By the looks of it, there's 2 parameters sent to onRecoverableError:

https://github.com/facebook/react/blob/dddfe688206dafa5646550d351eb9a8e9c53654a/packages/react-reconciler/src/ReactInternalTypes.js#L270-L273

  onRecoverableError: (
    error: mixed,
    errorInfo: {digest?: ?string, componentStack?: ?string},
  ) => void,

I wonder if we could expose that extra information here:

const onRecoverableError = (error: unknown): void => {
console.error('Docusaurus React Root onRecoverableError:', error);
};

So we've got more to go on? The error itself doesn't provide any information about where the issue comes from.

Essentially I'm wondering if we can console.log 2 parameters instead of 1.

@johnnyreilly
Copy link
Contributor Author

I've raised a mini PR to add the errorInfo paramater to what is logged here: #9387

@slorber
Copy link
Collaborator

slorber commented Oct 9, 2023

I can reproduce locally super easily on my home Ubuntu machine. My guess is any Ubuntu machine would do the job.

Unfortunately I don't have one 😅

Afaik our github actions use ubuntu. I was thinking of upgrading my Argos/Playwright visual tests to also ensure there's no console error on all pages of the site and catch such errors, will see how to do that.

So you'd like the originally served HTML and what the DOM html looks like after it starts?

Is there a best way to surface the DOM html? Devtools and copy outerhtml?

I guess you can use the browser with/without JS enabled, and use innerHTML or outerHTML after applying a html formatter/normalizer like Prettier (otherwise it would be hard to compare.

As a first test, I tried comparing the supposedly working hydration on my Mac (no errors) and found that non-hydrated and hydrated already look pretty different. But that's appears to be fine.

Not surprised, differences are expected because we do some updates just after hydrating. What would be interesting to check is if there are blog-specific changes.

How did you manage to fix the existing hydration issues @slorber? Doesn't look like there's much to go on looking at facebook/react#26224

Oh sorry, totally forgot about this but I actually added a yarn docusaurus build --dev option that permits to get better hydration error messages 😄 (see #8961)

FYI there are some reports that I only get in --dev and after checking everything I don't see what's causing them, for example: Warning: Prop className did not match. Server: "null" Client: "" in a navbar item.

@johnnyreilly
Copy link
Contributor Author

image

I'm seeing the issue above - this is the stack trace:

react-dom.development.js:86 Warning: Prop `className` did not match. Server: "null" Client: ""
    at li
    at HtmlNavbarItem (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/NavbarItem/HtmlNavbarItem.js:17:27)
    at NavbarItem (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/NavbarItem/index.js:81:11)
    at ul
    at div
    at DropdownNavbarItemDesktop (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/NavbarItem/DropdownNavbarItem.js:123:11)
    at DropdownNavbarItem (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/NavbarItem/DropdownNavbarItem.js:277:11)
    at DocsVersionDropdownNavbarItem (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js:110:11)
    at NavbarItem (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/NavbarItem/index.js:81:11)
    at ErrorCauseBoundary (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/errorBoundaryUtils.js:143:5)
    at NavbarItems (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/Navbar/Content/index.js:67:24)
    at div
    at div
    at NavbarContentLayout (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/Navbar/Content/index.js:87:32)
    at NavbarContent (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/Navbar/Content/index.js:115:117)
    at nav
    at NavbarLayout (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/Navbar/Layout/index.js:91:25)
    at Navbar
    at NavbarSecondaryMenuDisplayProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/navbarSecondaryMenu/display.js:89:64)
    at NavbarMobileSidebarProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/navbarMobileSidebar.js:70:40)
    at NavbarSecondaryMenuContentProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/navbarSecondaryMenu/content.js:20:64)
    at NavbarProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/navbarUtils.js:40:31)
    at HtmlClassNameProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/metadataUtils.js:108:49)
    at PluginHtmlClassNameProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/metadataUtils.js:141:44)
    at DocsPreferredVersionContextProviderUnsafe (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/docsPreferredVersion.js:177:54)
    at DocsPreferredVersionContextProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/docsPreferredVersion.js:191:52)
    at ScrollControllerProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/scrollUtils.js:40:37)
    at AnnouncementBarProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/announcementBar.js:76:36)
    at ColorModeProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/colorMode.js:144:30)
    at eval (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/reactUtils.js:93:15)
    at LayoutProvider (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/Layout/Provider/index.js:32:27)
    at Layout (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/Layout/index.js:68:13)
    at LayoutWrapper
    at BlogLayout (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/BlogLayout/index.js:101:13)
    at BlogPostPageContent (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/BlogPostPage/index.js:34:32)
    at HtmlClassNameProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/utils/metadataUtils.js:108:49)
    at BlogPostProvider (webpack-internal:///../packages/docusaurus-theme-common/lib/contexts/blogPost.js:38:33)
    at BlogPostPage (webpack-internal:///../packages/docusaurus-theme-classic/lib/theme/BlogPostPage/index.js:74:35)
    at RouteContextProvider (webpack-internal:///../packages/docusaurus/lib/client/routeContext.js:62:33)
    at LoadableComponent (webpack-internal:///../node_modules/react-loadable/lib/index.js:138:32)
    at Route (webpack-internal:///../node_modules/react-router/esm/react-router.js:648:29)
    at Switch (webpack-internal:///../node_modules/react-router/esm/react-router.js:850:29)
    at Route (webpack-internal:///../node_modules/react-router/esm/react-router.js:648:29)
    at ClientLifecyclesDispatcher (webpack-internal:///../packages/docusaurus/lib/client/ClientLifecyclesDispatcher.js:48:39)
    at PendingNavigation (webpack-internal:///../packages/docusaurus/lib/client/PendingNavigation.js:83:9)
    at Root (webpack-internal:///../packages/docusaurus/lib/client/theme-fallback/Root/index.js:22:17)
    at BrowserContextProvider (webpack-internal:///../packages/docusaurus/lib/client/browserContext.js:24:35)
    at DocusaurusContextProvider (webpack-internal:///../packages/docusaurus/lib/client/docusaurusContext.js:36:38)
    at ErrorBoundary (webpack-internal:///../packages/docusaurus/lib/client/exports/ErrorBoundary.js:80:9)
    at App (webpack-internal:///../packages/docusaurus/lib/client/App.js:47:85)
    at Router (webpack-internal:///../node_modules/react-router/esm/react-router.js:267:30)
    at BrowserRouter (webpack-internal:///../node_modules/react-router-dom/esm/react-router-dom.js:58:35)
    at r (webpack-internal:///../node_modules/react-helmet-async/lib/index.module.js:17:7350)

@slorber
Copy link
Collaborator

slorber commented Oct 9, 2023

Yes I also have it in dev mode, on all pages (not just blog pages). As I said above, after inspecting the code I'm unable to troubleshoot this navbar item error that only happens in dev, and not in prod.

I'm not sure it is related to your problem (only affecting the blog pages).
If you want to be sure, remove all navbar items and see if it fixes your prod problem on blog pages: if it doesn't then your issue is something else.

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 9, 2023

If you want to be sure, remove all navbar items and see if it fixes your prod problem on blog pages:

image

removing navbar items has revealed a similar issue in the blog section!

react-dom.development.js:86 Warning: Prop `className` did not match. Server: "null" Client: ""
    at article
    at BlogPostItemContainer (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/BlogPostItem/Container/index.js:19:34)
    at BlogPostItem (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/BlogPostItem/index.js:32:25)
    at main
    at div
    at div
    at ErrorBoundary (webpack-internal:///./node_modules/@docusaurus/core/lib/client/exports/ErrorBoundary.js:80:9)
    at div
    at NavbarSecondaryMenuDisplayProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/navbarSecondaryMenu/display.js:89:64)
    at NavbarMobileSidebarProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/navbarMobileSidebar.js:70:40)
    at NavbarSecondaryMenuContentProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/navbarSecondaryMenu/content.js:20:64)
    at NavbarProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/utils/navbarUtils.js:40:31)
    at HtmlClassNameProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/utils/metadataUtils.js:108:49)
    at PluginHtmlClassNameProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/utils/metadataUtils.js:141:44)
    at DocsPreferredVersionContextProviderUnsafe (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/docsPreferredVersion.js:177:54)
    at DocsPreferredVersionContextProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/docsPreferredVersion.js:191:52)
    at ScrollControllerProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/utils/scrollUtils.js:40:37)
    at AnnouncementBarProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/announcementBar.js:76:36)
    at ColorModeProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/colorMode.js:144:30)
    at eval (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/utils/reactUtils.js:93:15)
    at LayoutProvider (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/Layout/Provider/index.js:32:27)
    at Layout (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/Layout/index.js:68:13)
    at BlogLayout (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/BlogLayout/index.js:101:13)
    at BlogPostPageContent (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/BlogPostPage/index.js:34:32)
    at HtmlClassNameProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/utils/metadataUtils.js:108:49)
    at BlogPostProvider (webpack-internal:///./node_modules/@docusaurus/theme-common/lib/contexts/blogPost.js:38:33)
    at BlogPostPage (webpack-internal:///./node_modules/@docusaurus/theme-classic/lib/theme/BlogPostPage/index.js:74:35)
    at BlogPostPageWrapper (webpack-internal:///./src/theme/BlogPostPage/index.js:43:104)
    at RouteContextProvider (webpack-internal:///./node_modules/@docusaurus/core/lib/client/routeContext.js:62:33)
    at LoadableComponent (webpack-internal:///./node_modules/react-loadable/lib/index.js:138:32)
    at Route (webpack-internal:///./node_modules/react-router/esm/react-router.js:648:29)
    at Switch (webpack-internal:///./node_modules/react-router/esm/react-router.js:850:29)
    at Route (webpack-internal:///./node_modules/react-router/esm/react-router.js:648:29)
    at ClientLifecyclesDispatcher (webpack-internal:///./node_modules/@docusaurus/core/lib/client/ClientLifecyclesDispatcher.js:44:39)
    at PendingNavigation (webpack-internal:///./node_modules/@docusaurus/core/lib/client/PendingNavigation.js:96:9)
    at Root (webpack-internal:///./node_modules/@docusaurus/core/lib/client/theme-fallback/Root/index.js:22:17)
    at BrowserContextProvider (webpack-internal:///./node_modules/@docusaurus/core/lib/client/browserContext.js:24:35)
    at DocusaurusContextProvider (webpack-internal:///./node_modules/@docusaurus/core/lib/client/docusaurusContext.js:36:38)
    at ErrorBoundary (webpack-internal:///./node_modules/@docusaurus/core/lib/client/exports/ErrorBoundary.js:80:9)
    at App (webpack-internal:///./node_modules/@docusaurus/core/lib/client/App.js:47:85)
    at Router (webpack-internal:///./node_modules/react-router/esm/react-router.js:267:30)
    at BrowserRouter (webpack-internal:///./node_modules/react-router-dom/esm/react-router-dom.js:58:35)
    at r (webpack-internal:///./node_modules/react-helmet-async/lib/index.module.js:17:7350)

The issue here is coming from a common pattern in the codebase; something passing className to clsx; and it looks like className is the string "null" on the server and "" on the client:

<Comp
      className={clsx(
        {
          navbar__item: !mobile && !isDropdownItem,
          'menu__list-item': mobile,
        },
        className,
      )}
      dangerouslySetInnerHTML={{__html: value}}
    />
<BlogPostItemContainer className={clsx(containerClassName, className)}>

Yes I also have it in dev mode, on all pages (not just blog pages). As I said above, after inspecting the code I'm unable to troubleshoot this navbar item error that only happens in dev, and not in prod.

Is it possible that the issue here is happening in prod and that the issue is the string of "null" being passed through in server mode? Is this the underlying issue that needs to be fixed?

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 10, 2023

With the new onRecoverableError logging in place I got this:

image

main.78700692.js:2 Docusaurus React Root onRecoverableError: Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at ls (main.78700692.js:2:109705)
    at Oc (main.78700692.js:2:182751)
    at xd (main.78700692.js:2:170225)
    at vd (main.78700692.js:2:170197)
    at sd (main.78700692.js:2:165247)
    at w (main.78700692.js:2:232540)
    at MessagePort.T (main.78700692.js:2:233072) {componentStack: '\n    at div\n    at G (http://localhost:3000/assets…calhost:3000/assets/js/main.78700692.js:2:199606)', digest: null}
n @ main.78700692.js:2
(anonymous) @ main.78700692.js:2
wd @ main.78700692.js:2
sd @ main.78700692.js:2
w @ main.78700692.js:2
T @ main.78700692.js:2
main.78700692.js:2 Docusaurus React Root onRecoverableError: Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at ls (main.78700692.js:2:109705)
    at Oc (main.78700692.js:2:182751)
    at xd (main.78700692.js:2:170225)
    at vd (main.78700692.js:2:170197)
    at sd (main.78700692.js:2:165247)
    at w (main.78700692.js:2:232540)
    at MessagePort.T (main.78700692.js:2:233072) {componentStack: '\n    at div\n    at q (http://localhost:3000/assets…calhost:3000/assets/js/main.78700692.js:2:199606)', digest: null}
n @ main.78700692.js:2
(anonymous) @ main.78700692.js:2
wd @ main.78700692.js:2
sd @ main.78700692.js:2
w @ main.78700692.js:2
T @ main.78700692.js:2
main.78700692.js:2 Docusaurus React Root onRecoverableError: Error: Minified React error #418; visit https://reactjs.org/docs/error-decoder.html?invariant=418 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at ls (main.78700692.js:2:109705)
    at Oc (main.78700692.js:2:182751)
    at xd (main.78700692.js:2:170225)
    at vd (main.78700692.js:2:170197)
    at sd (main.78700692.js:2:165247)
    at w (main.78700692.js:2:232540)
    at MessagePort.T (main.78700692.js:2:233072) {componentStack: '\n    at footer\n    at kn (http://localhost:3000/as…calhost:3000/assets/js/main.78700692.js:2:199606)', digest: null}
n @ main.78700692.js:2
(anonymous) @ main.78700692.js:2
wd @ main.78700692.js:2
sd @ main.78700692.js:2
w @ main.78700692.js:2
T @ main.78700692.js:2
main.78700692.js:2 Docusaurus React Root onRecoverableError: Error: Minified React error #423; visit https://reactjs.org/docs/error-decoder.html?invariant=423 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Oc (main.78700692.js:2:182437)
    at xd (main.78700692.js:2:170225)
    at yd (main.78700692.js:2:170153)
    at hd (main.78700692.js:2:170016)
    at id (main.78700692.js:2:166823)
    at sd (main.78700692.js:2:165375)
    at w (main.78700692.js:2:232540)
    at MessagePort.T (main.78700692.js:2:233072) {componentStack: '', digest: null}

Not actually that helpful.

{
    "componentStack": "\n    at div\n    at G (http://localhost:3000/assets/js/main.78700692.js:2:624664)\n    at Bt (http://localhost:3000/assets/js/main.78700692.js:2:661953)\n    at nav\n    at qt (http://localhost:3000/assets/js/main.78700692.js:2:663366)\n    at sn\n    at q (http://localhost:3000/assets/js/main.78700692.js:2:623699)\n    at p (http://localhost:3000/assets/js/main.78700692.js:2:264647)\n    at r (http://localhost:3000/assets/js/main.78700692.js:2:264973)\n    at http://localhost:3000/assets/js/main.78700692.js:2:672280\n    at g (http://localhost:3000/assets/js/main.78700692.js:2:275178)\n    at b (http://localhost:3000/assets/js/main.78700692.js:2:275363)\n    at y (http://localhost:3000/assets/js/main.78700692.js:2:262590)\n    at v (http://localhost:3000/assets/js/main.78700692.js:2:262676)\n    at l (http://localhost:3000/assets/js/main.78700692.js:2:277407)\n    at b (http://localhost:3000/assets/js/main.78700692.js:2:258340)\n    at f (http://localhost:3000/assets/js/main.78700692.js:2:259271)\n    at http://localhost:3000/assets/js/main.78700692.js:2:276403\n    at En (http://localhost:3000/assets/js/main.78700692.js:2:672394)\n    at Nn (http://localhost:3000/assets/js/main.78700692.js:2:673299)\n    at Ln\n    at v (http://localhost:3000/assets/js/ccc49370.aa459f07.js:1:21579)\n    at g (http://localhost:3000/assets/js/ccc49370.aa459f07.js:1:33004)\n    at g (http://localhost:3000/assets/js/main.78700692.js:2:275178)\n    at l (http://localhost:3000/assets/js/ccc49370.aa459f07.js:1:59429)\n    at h (http://localhost:3000/assets/js/ccc49370.aa459f07.js:1:33429)\n    at c (http://localhost:3000/assets/js/main.78700692.js:2:373197)\n    at n (http://localhost:3000/assets/js/main.78700692.js:2:208520)\n    at t (http://localhost:3000/assets/js/main.78700692.js:2:218284)\n    at t (http://localhost:3000/assets/js/main.78700692.js:2:219232)\n    at t (http://localhost:3000/assets/js/main.78700692.js:2:218284)\n    at M (http://localhost:3000/assets/js/main.78700692.js:2:288684)\n    at z (http://localhost:3000/assets/js/main.78700692.js:2:290015)\n    at g (http://localhost:3000/assets/js/main.78700692.js:2:285165)\n    at i (http://localhost:3000/assets/js/main.78700692.js:2:284800)\n    at p (http://localhost:3000/assets/js/main.78700692.js:2:363422)\n    at b (http://localhost:3000/assets/js/main.78700692.js:2:365297)\n    at Q (http://localhost:3000/assets/js/main.78700692.js:2:292784)\n    at t (http://localhost:3000/assets/js/main.78700692.js:2:216498)\n    at t (http://localhost:3000/assets/js/main.78700692.js:2:211808)\n    at t (http://localhost:3000/assets/js/main.78700692.js:2:199606)",
    "digest": null
}

@slorber
Copy link
Collaborator

slorber commented Oct 10, 2023

The issue here is coming from a common pattern in the codebase; something passing className to clsx; and it looks like className is the string "null" on the server and "" on the client:

As far as I remember, I tried to debug those during the React 18 update and still got errors in dev even after hardcoding a static value for the className. I concluded it might be a React bug.

Are you seeing a mismatch in practice, or is this only your supposition that there must be one? If you see a mismatch, please give me your exact navbar item definition, and what's the JSX/className on server vs client.

In any case it's surprising if we all get different behaviors, and even more surprising if some hydration errors are logged in --dev for me, but not in regular build mode.


We also had this clsx edge case, not sure it's related but in case: #9098

@slorber
Copy link
Collaborator

slorber commented Oct 10, 2023

I just tried again locally on the HtmlNavbarItem.

Using the current code, I couldn't see anything that produces a mismatch (nothing reads from browser APIs), and by logging the className I didn't see any mismatch at runtime either.


This one produces an hydration error, but only in dev: Warning: Prop className did not match. Server: "null" Client: ""

<Comp className="" dangerouslySetInnerHTML={{__html: ''}} />

However this one doesn't produce an hydration error, in both dev/prod:

<Comp className="some-class" dangerouslySetInnerHTML={{__html: ''}} />

This really looks like a React bug to me 😅 it seems to only appear when we use className="", which is kind-of related to #9098

@johnnyreilly
Copy link
Contributor Author

Are you seeing a mismatch in practice, or is this only your supposition that there must be one? If you see a mismatch, please give me your exact navbar item definition, and what's the JSX/className on server vs client.

I'm not sure - I'm doing a yarn build and trying to console.log stuff - but the fancy updating console means I can't see output. How do you deactivate that? I can have another try tonight.

@johnnyreilly
Copy link
Contributor Author

the frusting thing is that the issue in the blogs section is still there when I do a standard yarn build but even with the extra logging I dont' get enough information to diagnose.

@slorber
Copy link
Collaborator

slorber commented Oct 12, 2023

Are you seeing a mismatch in practice, or is this only your supposition that there must be one? If you see a mismatch, please give me your exact navbar item definition, and what's the JSX/className on server vs client.

I'm not sure - I'm doing a yarn build and trying to console.log stuff - but the fancy updating console means I can't see output. How do you deactivate that? I can have another try tonight.

For me console logs are still displayed correctly 🤔 but you can try to disable locally the new WebpackBar() Webpack plugins.

the frusting thing is that the issue in the blogs section is still there when I do a standard yarn build but even with the extra logging I dont' get enough information to diagnose.

Yes, this is frustrating and I still have no idea how to fix that, or if it's even a bug in Docusaurus in the first place. I also wonder if others see those errors or if it's just you. Just asked on Discord to see if we can get more feedback: https://discord.com/channels/398180168688074762/398180168688074765/1161957671352676423

@johnnyreilly
Copy link
Contributor Author

Yes, this is frustrating and I still have no idea how to fix that, or if it's even a bug in Docusaurus in the first place. I also wonder if others see those errors or if it's just you

So because it shows up in the lighthouse GitHub action results that don't run on my machine I'm pretty sure it's not just me. My guess is that anyone who uses Docusaurus v3 and had lighthouse set up would probably see this

@johnnyreilly
Copy link
Contributor Author

I've raised #9393 which points lighthouse to the Docusaurus blog - if my theory is correct, the issue should show up in the lighthouse report on that PR for the /blogs URL.

@slorber
Copy link
Collaborator

slorber commented Oct 12, 2023

In #9395 (comment) it looks like it's not just the blog but actually any Docusaurus page has errors, do you also see that locally? Particularly on docs?

@lebalz
Copy link
Contributor

lebalz commented Oct 12, 2023

Yes, this pops up here aswell:
image

@johnnyreilly
Copy link
Contributor Author

yup seems to be a general issue - this is what I get at https://docusaurus.io/

image

@slorber slorber added this to the 3.0 milestone Oct 23, 2023
@slorber slorber changed the title v3 blog posts have hydration issues; Minified React error #418 v3 site has hydration issues on Ubuntu Oct 24, 2023
@slorber
Copy link
Collaborator

slorber commented Oct 24, 2023

@lebalz are you using Ubuntu as well?
Do we agree that this only happens in Ubuntu?

I will need your help here because I'm using BrowserStack to test this and so far I couldn't reproduce using various combinations of OS/browsers.


Can you try various browsers in incognito mode on Ubuntu and report the exact OS/Browser versions that can reproduce these hydration errors? And check multiple pages (home, docs, blog?)

A clear report like this would help me a lot:

# Ubuntu v22.04

## Firefox v119

- [/](https://docusaurus.io/): ✅
- [/docs](https://docusaurus.io/docs): ❌ (React error 418)
- [/blog](https://docusaurus.io/blog): ❌ (React error 418)

## Chrome v118

- [/](https://docusaurus.io/): ✅
- [/docs](https://docusaurus.io/docs): ❌ (React error 418)
- [/blog](https://docusaurus.io/blog): ❌ (React error 418)

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 24, 2023

I've done some testing - it seems to be Ubuntu / Chrome specific. Interestingly Edge (which is very similar to Chrome) seems fine.

Ubuntu v22.04

Firefox 118.0.2 (64-bit)

Chrome Version 118.0.5993.88 (Official Build) (64-bit)

  • /: ❌ (React error 418)
  • /docs: ❌ (React error 418)
  • /blog: ❌ (React error 418)

image

Edge Version 118.0.2088.61 (Official build) (64-bit)

@lebalz
Copy link
Contributor

lebalz commented Oct 24, 2023

@slorber no, i'm actually on a Windows 11 Laptop (with WSL2(Ubuntu) for dev stuff, but this should not matter).

I can not reproduce the issue anymore, it is now completely gone... hmmm

Windows 11 (22H2, Build Version 22621.2428)

Firefox v119.0

Edge v118

@lebalz
Copy link
Contributor

lebalz commented Oct 24, 2023

ok, could it be somehow content-related? I can reproduce it only on the following blog post, but consistently on each browser in win 11

Windows 11 (22H2, Build Version 22621.2428)

Firefox v119.0

Edge v118.0

Edge v118.0 (Guest Mode)

Chrome v118.0

Brave v1.59.120 (Chromium: 118.0.5993.88)

@slorber
Copy link
Collaborator

slorber commented Oct 25, 2023

Thanks for the infos !


@lebalz yes https://docusaurus.io/blog/releases/2.4 definitively has an hydration problem, it's a quite specific case due to using an embedded iframe with a query-string. I can reproduce it and will see how to fix it.

Do you have any problem on other posts that do not contain an iframe? For example this one?
https://docusaurus.io/blog/preparing-your-site-for-docusaurus-v3

I think what you see is what I see, and the problem is indeed specific to Chrome/Ubuntu, so it's probably not worth it investigating more on your case.


@johnnyreilly are you using guest mode on Chrome and still getting errors?
Do you have any extension enabled that could produce it?
Do you have google chrome autotranslate or something similar in action? That can lead to hydration issues.

Do you see any issue on these pages?

@slorber
Copy link
Collaborator

slorber commented Oct 25, 2023

@johnnyreilly to be honest I'm not sure how I will be able to fix this issue 😅

This Docusaurus page that just prints "Hello" is still producing a lighthouse console error 🤷‍♂️ so I guess you get it too

https://deploy-preview-9446--docusaurus-2.netlify.app/

CleanShot 2023-10-25 at 13 14 56

I'll try to see if there's something in Docusaurus core, but this quite surprising 😅

And the --dev errors do not even report it so 🤷‍♂️

@johnnyreilly
Copy link
Contributor Author

johnnyreilly commented Oct 25, 2023

This Docusaurus page that just prints "Hello" is still producing a lighthouse console error 🤷‍♂️ so I guess you get it too

https://deploy-preview-9446--docusaurus-2.netlify.app/

I initially said "no" but I forgot I'm on a Mac right now. At work. Can check later.

@johnnyreilly are you using guest mode on Chrome and still getting errors?
Do you have any extension enabled that could produce it?
Do you have google chrome autotranslate or something similar in action? That can lead to hydration issues.

I don't think that my extensions should be a cause. I turned them off and nothing changed.

Significantly though, the issues show up in Lighthouse and there's no extensions there I guess?

@johnnyreilly
Copy link
Contributor Author

Did you see my comments on #9447 ? I'm happy to help you get Docusaurus running on Azure Static Web Apps and plug in Lighthouse there.

@slorber
Copy link
Collaborator

slorber commented Oct 25, 2023

Damn, I spent the day on this to figure out the problem is not Ubuntu but mobile viewport.

If you hydrate a page on small device (like Lighthouse does) you get the error.

This should be fixed now: https://deploy-preview-9446--docusaurus-2.netlify.app/

@slorber slorber removed the status: needs more information There is not enough information to take action on the issue. label Oct 25, 2023
@johnnyreilly
Copy link
Contributor Author

Good work on the mobile viewport stuff! I'll test on my home machine when I get a moment. The one thing that's in the back of my mind is that I have seen this on Ubuntu in desktop view - will let you know what I find

@johnnyreilly
Copy link
Contributor Author

It might be good to run lighthouse in desktop and mobile view regardless. There's tips here on how to do it

treosh/lighthouse-ci-action#79 (comment)

@slorber
Copy link
Collaborator

slorber commented Oct 25, 2023

Thanks, I'm not satisfied with our current setup, noted to also test on desktop here: #9449

@lebalz
Copy link
Contributor

lebalz commented Oct 25, 2023

Good catch and thanks for the big effort 💪

@johnnyreilly
Copy link
Contributor Author

I still see the error on the mobile view @slorber - is the change live? Browsing at https://docusaurus.io/ and I've done a hard refresh

image

@slorber
Copy link
Collaborator

slorber commented Oct 26, 2023

Not live yet, deploy failed like often due to our weird i18n setup

If it's ok in the deploy preview it should be soon in prod

@FZambia
Copy link

FZambia commented Nov 4, 2023

@slorber hello, I just updated Centrifugo doc site to Docusaurus v3 and getting similar console errors in production build. I am using v3.0.0 - here is a branch with update, centrifugal/centrifugal.dev#45 (has screenshot with errors I observed). Looking at discussion it seems to be fixed in v3.0.0 - but still sth causes all these errors.

For now I rolled back to using v2.

@slorber
Copy link
Collaborator

slorber commented Nov 6, 2023

@FZambia those errors are likely due to your own site code.

Remove your React code, third party plugins, and if error persist then it's our fault, but I doubt it it.

Or you can provide a minimal repro.

Those errors are not a big deal. With React 18 we only log them while they were there but kind of hidden before in v2. It's likely that your v2 site already has hydration issues, that are simply unreported

@FZambia
Copy link

FZambia commented Dec 31, 2023

Remove your React code, third party plugins, and if error persist then it's our fault, but I doubt it it.

This advice helped me, thanks! In my case this was due to the following plugin in docusaurus.config.js:

  plugins: [
    [
      require.resolve("@easyops-cn/docusaurus-search-local"),
      {
        hashed: true,
      },
    ],

Removing it fixed all the errors.

@ismaelga
Copy link

ismaelga commented Mar 5, 2024

I was facing this issue serving static build with Caddy.

My issue was that I was always serving index.html which wouldn't match what React would render for each other page on the client, obviously!

Just writing this to give a tip on how to debug this:

  • Get the html from what's being rendered (DOM)
  • Get the source served
  • Format both with any formatter and do a diff using any diffing tool to see what's different.
  • That diff should give you good hints on where your issues come from.

Maybe this obvious for some, but might be a good hint for others 🍻

@slorber
Copy link
Collaborator

slorber commented Mar 5, 2024

My issue was that I was always serving index.html

That's a common issue with hosts that do not serve static deployments correctly by default.

You can also use devtools to throttle the network (or even block JS execution) and see that it first renders your homepage, and then it gets "fixed" by the local JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants