Skip to content

v3 site has hydration issues on Ubuntu #9379

Closed

Description

@johnnyreilly

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.

Activity

  1. added
    bugAn error in the Docusaurus core causing instability or issues with its execution
    status: needs triageThis issue has not been triaged by maintainers
    on Oct 7, 2023
  2. slorber commented on Oct 8, 2023

    @slorber
    Collaborator

    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.

  3. 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[/+] on Oct 8, 2023
  4. changed the title [-]v3 blog posts have hydration issues; Minified React error #41818[/-] [+]v3 blog posts have hydration issues; Minified React error #418[/+] on Oct 8, 2023
  5. johnnyreilly commented on Oct 8, 2023

    @johnnyreilly
    ContributorAuthor

    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?

  6. johnnyreilly commented on Oct 8, 2023

    @johnnyreilly
    ContributorAuthor

    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

  7. johnnyreilly commented on Oct 8, 2023

    @johnnyreilly
    ContributorAuthor

    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)

  8. added
    status: needs more informationThere is not enough information to take action on the issue.
    and removed
    status: needs triageThis issue has not been triaged by maintainers
    on Oct 9, 2023
  9. slorber commented on Oct 9, 2023

    @slorber
    Collaborator

    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.

  10. johnnyreilly commented on Oct 9, 2023

    @johnnyreilly
    ContributorAuthor

    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?

  11. johnnyreilly commented on Oct 9, 2023

    @johnnyreilly
    ContributorAuthor

    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 react/react#26224

  12. johnnyreilly commented on Oct 9, 2023

    @johnnyreilly
    ContributorAuthor

    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.

  13. johnnyreilly commented on Oct 9, 2023

    @johnnyreilly
    ContributorAuthor

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

  14. 29 remaining items

  15. johnnyreilly commented on Oct 25, 2023

    @johnnyreilly
    ContributorAuthor

    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.

  16. slorber commented on Oct 25, 2023

    @slorber
    Collaborator

    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/

  17. johnnyreilly commented on Oct 25, 2023

    @johnnyreilly
    ContributorAuthor

    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

  18. johnnyreilly commented on Oct 25, 2023

    @johnnyreilly
    ContributorAuthor

    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)

  19. slorber commented on Oct 25, 2023

    @slorber
    Collaborator

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

  20. lebalz commented on Oct 25, 2023

    @lebalz
    Contributor

    Good catch and thanks for the big effort 💪

  21. johnnyreilly commented on Oct 25, 2023

    @johnnyreilly
    ContributorAuthor

    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

  22. slorber commented on Oct 26, 2023

    @slorber
    Collaborator

    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

  23. FZambia commented on Nov 4, 2023

    @FZambia

    @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.

  24. slorber commented on Nov 6, 2023

    @slorber
    Collaborator

    @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

  25. FZambia commented on Dec 31, 2023

    @FZambia

    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.

  26. ismaelga commented on Mar 5, 2024

    @ismaelga

    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 🍻

  27. slorber commented on Mar 5, 2024

    @slorber
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its execution

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions