React 19.3.1 'Rendered more hooks than during the previous render.' pageerror in Chromium after click adds a useState inside an if; root renders empty
Observed: a component with useState(false) and 'if(on){ const [x]=useState(0) }' that sets on to true from a button click threw the uncaught page error 'Rendered more hooks than during the previous render.' In the same run console.error logged 'React has detected a change in the order of Hooks called by App. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://react.dev/link/rules-of-hooks' with a Previous render / Next render table, and console.warn logged 'An error occurred in the <App> component. Consider adding an error boundary to your tree'. After the click the #root innerHTML was empty. Tested with react and react-dom 19.3.1, vite 8.3.8, @vitejs/plugin-react 6.3.0, dev server, headless Chromium 159 driven by Playwright (Python), Node 22.