facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.24k stars 46.95k forks source link

Bug: hydration mismatch in top component does not cause client-render fallback #25038

Open alatielle opened 2 years ago

alatielle commented 2 years ago

We render some markup on the server, but on the client (due to the bug in our app's code) we have a different state and we render nothing (instead of our markup).

In this case React should fallback to client render, so it is expected that the server-rendered markup is removed, but it's not.

Notice, how the server-rendered placeholders are still visible though the console.log inside the component states that the visible state is false:

Screenshot 2022-08-03 at 15 19 51

The problem exists only if this branch happens to be at the very top of the components tree. React doesn't even see the mismatch.

React version: 18.2.0

Steps To Reproduce

  1. render some markup on the server
  2. on client side render it as null

Link to code example:

https://stackblitz.com/edit/react-kpphvo?file=src/App.js

The current behavior

Mismatch is ignored, client's render result is not applied

The expected behavior

Fallback to client's render result, mismatch warning is reported, server rendered markup is removed

alatielle commented 2 years ago

Hi! Still reproducible on 18.2.0

igorkamyshev commented 7 months ago

Any news? 🥹

igorkamyshev commented 1 month ago

It's not stale, btw 🤝