Description
- Check if updating to the latest version resolves the issue
Environment
- I am using
@preact/signals-core
- I am using
@preact/signals
- I am using
@preact/signals-react
- I understand usage changed in v2, and I've followed the React Integration instructions
Describe the bug
React Fast Refresh has two modes of updating the view:
- updating the current component tree
- re-rendering the components from scratch
Most operations result in updating the current component tree but some operations, like adding or removing hooks, causes everything to be re-rendered and state to be lost. This is mandatory as trying to call a different number of hooks during rendering will cause React to fail with Error: Rendered fewer hooks than expected. This may be caused by an accidental early return statement.
or Error: Should have a queue. This is likely a bug in React. Please file an issue.
or something similar
When adding @preact/signals-react-transform
, it seems like all operations result in trying to update to current component tree and thus modifying anything related to hooks shows one of the mentioned errors.
To Reproduce
https://github.com/Artur-/react-signals-hmr
Steps to reproduce the behavior:
npm run dev
- Open localhost:5173
- Click the counter a few times to change the state
- Edit src/App.tsx and add a new
useState
hook
The main
branch includes @preact/signals-react-transform
and shows the problem
The without-signals
branch shows how it is supposed to work
Expected behavior
The page should be updated and the counter reset to 0.
Instead, the page is empty and console contains the React error messages