Closed roo7690 closed 8 months ago
In which environment do you using signals? Webpack? Vite? Next.js?
Just as speculation from my time working with Preact Signals, the issue could be because the count.value
and double.value
in your JSX are not being used in the proper way. Any signal or computed value within the JSX should be inserted without explicitly saying .value
. Preact Signals handles the rendering behind the scenes. But as @XantreGodlike asked above, I've noticed Vite and Webpack can have different results at times.
Any signal or computed value within the JSX should be inserted without explicitly saying
.value
.
Not quite, no. Using .value
just opts you out of the direct text node binding, you absolutely can do it though. Just need a full rerender of the component to update.
Just as speculation from my time working with Preact Signals, the issue could be because the
count.value
anddouble.value
in your JSX are not being used in the proper way. Any signal or computed value within the JSX should be inserted without explicitly saying.value
. Preact Signals handles the rendering behind the scenes. But as @XantreGodlike asked above, I've noticed Vite and Webpack can have different results at times.
Omitting .value
is fully optional performance optimization. It should work any way - it will rerender SignalValue or the parent component
@XantreGodlike Oops, I should have mentioned. It's on Nextjs; through this increment, we can see that there is an omission.
"use client"
import { effect, signal } from "@preact/signals-react";
const i=signal(0)
setInterval(()=>i.value++,1000)
effect(()=>{
console.log(i.value)
})
export default function Page () {
return i
}
@roo7690 use can try my @preact-signals/safe-react
with manual subscribing components to signals via HOC. It's not so cool as automatic tracking, but for now I don't know better options for next.js. For now I researching opportunity to migrate babel plugin to swc to make it working with next.js https://github.com/XantreGodlike/preact-signals/issues/43
first of all, I appreciate about your work
I also facing same problem. I did integrate @preact-signals/safe-react
into my React native project
it seems can subscribe signals but the component not re-render
in case I declare temporary state and update state from useSignalEffect to force re-render, it's working but I don't think this is working well as intended
@Dylan-yoon-mp Did you run yarn start --reset-cache
?
@XantreGodlike yes many times but i didn't work I want share my env just in case
react-native: 0.71.12 react-navigation: 0.6.x @preact-signals/safe-react: 0.3.1
Did you change babel config?
yes I did
same issue with "vite": "^4.5.0" and "@preact/signals-react": "^2.0.0"
same issue
Same issue in Next.js and Vite.
@rschristian Should we add Troubleshooting section to readme? I can provide PR
What would that entail (especially in relation to this issue)?
What would that entail (especially in relation to this issue)?
Components don't track signals or Components do not update if signal value changes or Lack of component reactivity
For me, the simple vite react typescript template doesnt work with @preact/signal-react 2.0.0 using the .value
, but when I switch to 1.3.8 it works as id expect. I have also tried the same thing in a create react app webpack environment. The switch to version 1.38 does resolve the issue.
https://stackblitz.com/edit/vitejs-vite-pj3xda?file=package.json,src%2FApp.tsx&terminal=dev
For me, the simple vite react typescript template doesnt work with @preact/signal-react 2.0.0 using the .value
You haven't followed the v2 usage instructions
For me, the simple vite react typescript template doesnt work with @preact/signal-react 2.0.0 using the .value
You haven't followed the v2 usage instructions
Your right, I missed the babel stuff. Thanks.
Quick solution:
This is probably because you didn't set the babel config.
Solution 1: Setting the babel config should fix the issue
Solution 2: Adding the hook useSignals() in the top of the file
Closing as answered.
Hello, I'm having a problem with @preact/signal-react. Using this code provided by the documentation,
there is a subscription of the console.log() that re-executes with each change but no rerendering of the component