-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
[BUG] Background Service Worker loses states on hot reload #151
Comments
Hi @belarusrulez, thanks for your detailed report! Apologies for the delay, it's been quite a busy week for us. Are you using MV2 or MV3? With MV3 you shouldn't have any expectations that the background service worker will stay alive and therefore it should be stateless. Even without HMR, the background service worker has a fixed lifetime and will die when you don't expect it to, in production. However, this isn't the case with MV2, so we'll need to figure out a good way to deal with that. For the time being, if you don't want HMR, please continue to use the prod bundle. We'll likely build a feature to disable HMR in dev but don't have that in yet. If you'd like to send a PR to add that functionality into plasmo, we'd greatly appreciate it. Something like |
Hey. Its MV3. It actually dies in the middle of code. It’s not idle when it’s get reloaded. Is there any way to build prod code readable under debug? |
Oh, that's not great. Thanks for the context. We'll take a look soon |
Thank you. I would like to make PR but have no idea where to start. too new in js/typescript. if you have in mind some kind example prs that can give me clue please send me link ill try to figure it out. |
I found if I just remove selected "auto-reload.12a1e065.js" from manifest I don't have problems.
BTW I was trying to get the code and fix it contribution guidelines https://github.com/PlasmoHQ/plasmo/blob/main/.github/CONTRIBUTING.md and I was not able to pull. I got the code in zip and was not able to build it using guidelines. |
Can you paste the command you used to clone? To build the whole project, you will need to get the sub-module as well (since we hoist all our lockfiles to the top) |
I tried
|
also I tried the same with https:
|
BTW sorry for late reply - basically you will need to setup a SSH keypair and associate it with ur github account, as our git submodules uses ssh: https://docs.github.com/en/authentication/connecting-to-github-with-ssh |
Regarding the losing state and invalidated context of this issue - do people really want their background sw to be static thorough development, or do they want the logic to change? - the idea of invalidating the context on development is so that folk can test their new background script logic, otherwise you would have to uninstall/re-install. On production, it will be a single-spawned background sw which won't be reloaded at runtime. But note that it will get killed on idle. While evaluating this issue, I'm not sure how to fix it completely. Basically during development there're times when the bgsw need to be invalidated for new instance and require hard reset of extension. What's the expected DX for background service worker? |
Note that in MV3, it's now background service worker. As a worker, it's prone to die (after 5mins or so) - thus, extension developer must account for the nature of worker and make it short-lived and ensure there's an "entry" logic to the bgsw - e.g who's invoking these background services? - otherwise, do not treat them as permanent, long-living worker as in prod they're not afaik - chrome kills them after certain amount of time see #3 |
I have hotfix that works for me perfectly. I just delete auto-reload.js file from manifest and refresh the extension. (It doesn't affect auto-reload if code is changed and works as expected) |
@belarusrulez I see, this would likely go hand-in-hand with #215 |
resolved in #255 |
What happened?
Hello.
Background script keeps loose state due to reloads.
I save some data in static vars or in classes parameters but because of reload it get's lost.
If I use production build everything works. With dev I have problems.
Is there a way to disable hot reload?
Thank you.
Version
Latest
What OS are you seeing the problem on?
MacOSX
What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
(OPTIONAL) Contact Details
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: