signals: Component doesn't rerender after signal change (static setup)
There is an example html page with counter code from tutorial. It doesn’t work locally, but the same code from ‘script’ section works in REPL.
Steps to reproduce:
- Open https://codesandbox.io/s/preact-signal-bug-s91cfu
- Press ‘+’ button few times
Expected: The count incrementing by 1 after ‘+’ button press.
Actual: The count stays at 0 after ‘+’ button press.
Note:
There is a difference in a logged signal locally and in REPL. Locally property t
is undefined, but in repl it equals to some object. (I assume it is a observer reference or something similar.)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 23 (10 by maintainers)
This is neither an issue with Preact or with signals. The code is not updating because you’re loading multiple copies of Preact in that sandbox which are not aware of each other. Hooks require singletons to work behind the scenes (same in React) which doesn’t play well with multiple copies of the framework being present.
Here is a fixed version of the codesandbox where only one copy of Preact is loaded: https://codesandbox.io/s/preact-signal-bug-forked-055v7z?file=/index.html
Hello Guys, just had the same problem here.
Do you think we could put it somewhere on the docs?
I was really puzzled about it because nothing was working and there wasn’t a single person commenting about it.
The example in preact site isn’t working here either
https://preactjs.com/repl?example=todo-list-signals
What issue is that?