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
Add --reload option for hard reload on non-CSS assets #443
Conversation
Otherwise CSS which imports JS for example won’t get added to the JS bundle. Needed for HMR.
…ired by JS in the head
Don’t load them into memory
* patch(hmr): use hostname for WS instantiation * test(hmr): add hostname shim for testing * Move location shim somewhere common
* Add url dependency for serviceWorker.register calls * extract matchesPattern helper * sync SW regexp with matchesPattern arg
* handle app store url scheme * Update scheme regex
…#340) * Fix: Error when scss file is empty parcel-bundler#327 * Return empty string when code is empty * Handling empty files * No need to load in mightHaveDependencies() * mightHaveDependencies doesn't run if this.contents is empty.
* web worker support * fix lint error
if (containsHtmlAsset) { | ||
const isReload = this.options.reload; | ||
const isReloadAsset = assets.some(asset => { | ||
return isReload ? asset.type !== 'css' : asset.type === 'html'; |
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.
It seems that the isReload
condition check can move out of the some
loop
Is this option really needed? Could you just hook into the HMR system yourself to do a reload? in your main JS file: if (module.hot) {
module.hot.accept(function () {
window.location.reload();
});
} |
+1 on the "is this needed" front. The reload suggestion above works, and building your code to perform a DOM "upsert" (see issue suggestions) also works. This does however, seem to be desired by quite a few. |
if (containsHtmlAsset) { | ||
const isReload = this.options.reload; | ||
const isReloadAsset = assets.some(asset => { | ||
return isReload ? asset.type !== 'css' : asset.type === 'html'; |
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.
Actually I hope the modification for styles can also reload the page, because it is related to DOM.
So I am thinking would it be better to be like isReload ? asset.type === 'js' : (asset.type === 'html' || asset.type === 'css')
?
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.
It sounds like you want reload to happen in any situation, so:
const isReloadAsset = isReload ? true : assets.some(a => a.type === 'html');
During the PR I assumed it was desirable to have CSS apply without page reloads, since it doesn't depend on JavaScript state and the like. But because it's using import
, maybe it runs into the same problems, and it's better to just hard reload the page?
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.
Oh yes. Maybe hot reload every time is more like what I need 😆
Agree. |
Looks like this has been approved but has fallen in to conflict. Would love to see this merged though - @mattdesl do you have any time to fix the conflicts? |
hey @mattdesl if you feel you can't find time to see this one through, I'd be happy to take on solving the conflicts. |
See the latest comment in the original discussion thread - it sounds like a cleaner fix than the command line flag in this PR. |
Ah I see, thanks for the reply. Well, to be honest, I get browser freezes with HMR on with the two apps I'm working on. As much as I like the idea of HMR, I'd love to just have the option you introduced in this PR, but I understand that it doesn't match the project's vision. |
I feel you. I personally have not had good experiences with HMR outside of very specific domains (ie: create-react-app), and this issue is the reason I’m not currently using parcel on some projects.
… On May 14, 2018, at 9:39 PM, Filipe Sabella ***@***.***> wrote:
Ah I see, thanks for the reply.
Well, to be honest, I get browser freezes with HMR on with the two apps I'm working on.
On is a vanilla typescript+react+redux and the other one is a canvas thing.
As it stands now I have to disable HMR and refresh the browser every time, which's a a little unfortunate.
As much as I like the idea of HMR, I'd love to just have the option you introduced in this PR, but I understand that it doesn't match the project's vision.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Same here! HMR gives me limited confidence so I end up refreshing manually anyway haha |
I find myself needing this in projects using web components. Calling |
Due to move to monorepo which rewrote the git history, this PR was automatically closed. Please open a new PR against master with your changes. You can do a diff against the |
With this new
--reload
option, parcel will trigger hard page reloads on JS and HTML assets, but should continue to inject updates with CSS assets.See discussion here:
#289
Personally I feel this should be the default rather than opt-in (HMR is not even working currently) but to each their own. 🍻