Description
Do you want to request a feature or report a bug?
feature in the development mode
What is the current behavior?
Inside <StrictMode>
, the render function is invoked twice, but always the second one is committed.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/k938koy8mv
I made a tiny change in @gaearon 's code.
// This may not work in concurrent mode.
savedCallback.current = callback;
What is the expected behavior?
Developers can notice the wrong code (unintentionally mutating refs in the render function).
One idea is to occasionally (ex. Math.random() < 0.25
) commit the first result from double-invoked render function.
The other could be to introduce <StrictStrictMode>
which is to triple-invoke the render function and commit the second one.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.8