Open izznatsir opened 1 year ago
If I change @vitejs/plugin-react
jsxRuntime
setting to classic
and consequentially adding import * as React from 'react'
, it works as expected. But, React Refresh needs the jsxRuntime
to be automatic
. Doing this also fix #269, so these two issues might be related.
It works fine with @vitejs/plugin-react-swc
, btw
Any update on it? sadly i can't use the swc plugin of vite due to a bug in other lib
This isn't an error with Signals exactly. The line of code signal.value++
does not trigger the setter. Try updating that to be signal.value += 1
and you'll see things work properly.
@sbesh91 Its not true. And i dont know any reason why ++ shouldn't trigger setter
https://stackblitz.com/edit/vitejs-vite-vtubyq?file=src/App.tsx
@XantreGodlike well that's quite strange. I went ahead and forked that repro as well. It looks like the only difference here is on the button render. <button onClick={() => (count.value += 1)}>count is {count}</button>
Tell you the truth, I'm not sure why binding it up like this forces a re-render and binding it up like your example <button onClick={() => (count.value += 1)}>count is {count.value}</button>
doesn't trigger it.
You're also right that the ++
operator does fire the setter. Sorry for jumping to conclusions here.
https://stackblitz.com/edit/vitejs-vite-kbch31?file=src%2Fmain.tsx,src%2FApp.tsx
I've just noticed the same thing.
This is my reproduction: https://stackblitz.com/edit/vitejs-vite-csqbr6?file=src%2FApp.jsx
EDIT: I confirm that switching to jsxRuntime: 'classic'
fixes the issue.
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
],
});
Starting from
@preact/signals-react@1.2.0
, accessing signal value viasignal.value
in JSX does not trigger rerender when signal value is changed.Reproduction: Stackblitz