-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
prefresh-vite is not preserving the state of a component #543
Comments
Hey, it's been a while since I looked at this repo. I tried running the tests which fail on full browser reload as well as made a new vite app with Preact and it worked. Do you have a repro or do you want to work on a fix? |
Hmm, so you couldn't reproduce it? The code above is pretty much it. Here's the behavior I'm seeing: prefresh-.2.mp4My import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [preact()],
}); |
I just tried creating a Preact app with |
npm init preact creates a vite one which seemed to work, your vite configuration should work unless you have to explicitly enable prefresh. Or it's a bug in a recent vite version |
What does |
Not at home atm but the tests use v5 https://github.com/preactjs/prefresh/blob/main/test/fixture/vite/package.json that being said, let's not make this issue a debugging session. I can either look at it in the next few weeks or as you have a working impl feel free to look into it |
Just got back to this seems to work just fine on #544 |
FWIW this still doesn't work for me with a freshly generated |
Mind creating a reproduction then? |
For me, when I modify anything in index.jsx, the whole state gets reset. |
But that's the function that contains i.e. if I move your |
Yep you're right, sorry for the confusion. I guess looking back it should have been obvious that HMR is re-executing all that stuff. Thanks. |
I'm making my own prefresh integration for fun, and I decided to compare the behavior of mine to a known working implementation so I could verify how it works. My custom integration (done by basically following the blog post and reading a bit of the
prefresh-vite
code) works, and when I update a component it preserves state unless I add or remove hooks.I tried
prefresh-vite
however and it's actually not working-- I created a sample application withnpm init preact
and put this code inindex.jsx
:When I modify something (like just changing some text inconsequentially) it instantly updates in the browser but also resets the counter to 0 every time. I'm not sure what's happening, I put a breakpoint in
flushUpdates
and it doesn't throw an exception (I don't think).The text was updated successfully, but these errors were encountered: