-
Notifications
You must be signed in to change notification settings - Fork 8
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
hot-reloading doesn't remove old versions of content scripts #46
hot-reloading doesn't remove old versions of content scripts #46
Conversation
@@ -0,0 +1,37 @@ | |||
// Enable HMR if available | |||
if (module.hot) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to have it working I had to add a wrapper script that imports the module, but I'm not sure about the implications of using it with webpack-target-webextension
or the react reloader for example so I appreciate any guidance
// minimum-content-script-file.js - Wrapper for user-defined content_scripts
function loadContentScript() {
// Import content.js dynamically so HMR updates are tracked
return import('./content.js')
}
// Content script initial load
let cleanup = loadContentScript()
// Enable HMR for the content script
if (module.hot) {
module.hot.accept('./content.js', () => {
// Remove previous content
cleanup && cleanup()
// Re-import the updated content script and run it again
cleanup = loadContentScript()
})
// Ensure cleanup on dispose
module.hot.dispose(() => {
cleanup && cleanup()
})
}
Hi! There is nothing wrong happened. The wrapper is required because the outmost module does not support HMR. Things like React HMR won't happen because React HMR is based on many restrictions of the nature of React development. A React Component is stateless (all states are managed by the React runtime), and has no side effect (or having a cleanup function to cancel the side effect). By using |
@Jack-Works thanks for taking a look. by the way, do you think my implementation is correct for the use-case of providing HMR for raw JS/TS files? I want to provide Extension.js users a way to HMR raw JS/TS files, and also the reload of the core |
I can do some experiments with this, but I will work on other projects for now so I cannot answer this recently. |
@Jack-Works ok, sounds good! |
hi! Have you tried |
hey @Jack-Works yes, I'd love your feedback on extension-js/extension.js#239. I expected the following two test cases to be ok:
but after running
happy to assist with testing/debugging. please let me know if these test cases should expect something else |
hi! @cezaraugusto I have created an example PR of how to HMR the root of the content script. #56 Please let me know if you need more help and sorry for the months of delay! |
hey there! it seems
webpack-target-webextension
doesn't emove old versions of content scripts when usingmodule.hot.accept()
. This PR adds a sample that can reproduce. it seems an issue with both.js
and.ts
extensions.Steps to Reproduce:
content.js
react-hmr
example works