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

React 18 SSR hydration failure in MeteorJS #12185

Open
1 of 3 tasks
laakal opened this issue Sep 16, 2022 · 4 comments
Open
1 of 3 tasks

React 18 SSR hydration failure in MeteorJS #12185

laakal opened this issue Sep 16, 2022 · 4 comments
Labels
hacktoberfest hacktoberfest issues for contribuition. Project:HMR

Comments

@laakal
Copy link
Contributor

laakal commented Sep 16, 2022

Description

Hydration failed because the initial UI does not match what was rendered on the server.

  • You are calling ReactDOMClient.createRoot() on a container that has already been passed to createRoot() before. Instead, call root.render() on the existing root instead if you want to update it.
  • Warning: An error occurred during hydration. The server HTML was replaced with client content in <div>.

Steps to reproduce

Screen Shot 2022-09-16 at 09 56 10

Client Setup

Meteor.startup(() => {
  FastRender.onPageLoad(async () => {
    const target = document.getElementById('react-root');
    const root = createRoot(target);
    const app = (
      <ApolloProvider client={apolloClient}>
        <BrowserRouter>
          <App />
        </BrowserRouter>
      </ApolloProvider>
    );
    return !window.noSSR ? hydrateRoot(target, app) : root.render(app);
  });

Meteor Version

v2.7

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

@rj-david
Copy link
Contributor

rj-david commented Sep 17, 2022

When coming from SSR (window.noSSR !== true), no need to call createRoot()

@laakal
Copy link
Contributor Author

laakal commented Sep 17, 2022

Thanks @rj-david. But its did not resolve the following errors:

  • Warning: Expected server HTML to contain a matching <a> in <div>.
  • There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.

@rj-david
Copy link
Contributor

The second error means that the SSR version is mismatched on the hydrated client version. Any chance that you tried this with React 17 without the warning?

P.S. I haven't moved to React 18 yet because of possible issues with Meteor fibers
#12161

@laakal
Copy link
Contributor Author

laakal commented Sep 17, 2022

@rj-david Same error in React v17. So let's wait for Meteor v2.8

@Grubba27 Grubba27 added the hacktoberfest hacktoberfest issues for contribuition. label Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest hacktoberfest issues for contribuition. Project:HMR
Projects
None yet
Development

No branches or pull requests

3 participants