-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Vite] Component does not keep track of Signal value when updated #357
Comments
Are you referring to HMR? Might be an issue for Prefresh. Edit: Hmm, looks like it should be supported, per preactjs/preset-vite#58 |
@rschristian Hello! Yes, I am referring to HMR. Do you think I should recreate this issue on the Prefresh repo? Edit: I've just tested this with React instead of Preact and the same issue shows up. Changing other parts of the JSX (such as the text inside the |
Can just CC @JoviDeCroock here, he would know best I believe. I don't know where we broke support, assuming it was working once.
React is a different beast entirely. Given the relationship of an external org trying to patch React to support signals and its ergonomics, I'm not sure HMR support in React is something that can be hoped for. |
@9Morello I've ran into this issue too but I was thinking that was the norm if the computed values weren't wrapped in a useComputed hook. If I use a useSignal, I wrap the return value using that signal's value in a useComputed or I create a signal outside of the component function and use a return statement in the useEffect of the component to clean up (reset) the signal's value on un-mounting. I've done this for a couple of components already and I don't think I've ran into any optimization bugs. |
I have tested this using Vite's
preact-ts
template.Using the
useState
hook keeps the state after the component gets reloaded because of a change:With the above, I can change the text inside the
p
tag, or change the counter display tocount * 2
, andcount
's value stays the same as the component reloads.However, using the same component with the
useSignal
hook, it doesn't work:Any change to text or to the function inside the
onClick
parameter resetscount
to 0. Is there any way to avoid this? Am I misunderstanding something? Sorry for the trouble.The text was updated successfully, but these errors were encountered: