facebook/react

Bug: StrictMode remount element that only update

Xiaoooyooo opened this issue · 3 comments

React version: 19.0.0

Steps To Reproduce

  1. use StrictMode
  2. render a list in any way
  3. change the order of the list

Link to code example: codesandbox

The current behavior

When change the order of the list, the list item unmounted and then mounted, except for the first element.

The expected behavior

It should not remount during the update phase.

I test the same code on react 18, which has no problem.

gotten a solution to this yet?

I think this is the expected behavior. Strict Mode double-renders your components to ensure that they remain pure, and it also calls useState updaters (see last point). I'm not sure if an 'updater' implies providing a value or a function or either though. But just to be clear, StrictMode is only used in development to catch bugs, it is not meant for production.

I think this is the expected behavior. Strict Mode double-renders your components to ensure that they remain pure, and it also calls useState updaters (see last point). I'm not sure if an 'updater' implies providing a value or a function or either though. But just to be clear, StrictMode is only used in development to catch bugs, it is not meant for production.

doesnt imply pretty sure