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

Bug: Invalid options to hydrateRoot can error with "This root received an early update" #28792

Open
rickhanlonii opened this issue Apr 9, 2024 · 1 comment · May be fixed by #28934
Open
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@rickhanlonii
Copy link
Member

Overview

https://codesandbox.io/s/5ch3lc

If you call hydrateRoot with (container, options), so forgetting <App /> and then call root.render():

const root = hydrateRoot(container, /* missing react element /* {
  onUncaughtError: (error) => {
   console.error(error);
  }
});

root.render();

Result

We show this error:

This root received an early update, before anything was able hydrate. Switched the entire root to client rendering.

This is common to do when switching from createRoot to hydrateRoot.

Expected

If you don't call root.render(), you see the real error:

Objects are not valid as a React child (found: object with keys {onUncaughtError}). If you meant to render a collection of children, use an array instead.

But we should match the options validation error from createRoot:

Warning: You passed a second argument to root.render(…) but it only accepts one argument.

With an error like:

Warning: You passed an options object as the second argument to `hydrateRoot(...)`, did you forget to pass a React element?

Versions

React version: 18.2.0 - 19.0.0-canary

@rickhanlonii rickhanlonii added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 9, 2024
@rickhanlonii rickhanlonii changed the title Bug: Invalid options to hydrateRoot shows error "" Bug: Invalid options to hydrateRoot can error with "This root received an early update" Apr 9, 2024
@Shubhdeep12
Copy link

Shubhdeep12 commented Apr 27, 2024

Hi @rickhanlonii I also got this issue once 😅..
Can I try fixing this?

I am adding a PR for this.
Love to get your feedback.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
2 participants