Skip to content
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

Prevent page refresh after hot reload #9

Open
rb1193 opened this issue Nov 15, 2020 · 9 comments
Open

Prevent page refresh after hot reload #9

rb1193 opened this issue Nov 15, 2020 · 9 comments

Comments

@rb1193
Copy link

rb1193 commented Nov 15, 2020

Frequently, webpack triggers an entire page refresh after hot reloading. This shouldn't be necessary - can we find a way to avoid this problem?

@mikedaviesweb
Copy link

I don't have much to add to this @rb1193, apart from I've experienced the same thing and is very annoying and slows down dev time.

Generally what I've seen happen is:

  1. Vue component hot reloads
  2. A few milliseconds after twig fully reloads resulting in a browser refresh.

A couple of things worth mentioning:

  • This doesn't happen all the time, but 9/10 times it does.
  • This wasn't happening at all on our previous webpack setup.

@moacode
Copy link

moacode commented Nov 15, 2020

@mikedaviesweb does this happen when saving Vue components or Twig files? I noticed this happened when saving Twig files using the old Webpack setup but it shouldn't happen when saving Vue SFCs.

@rb1193
Copy link
Author

rb1193 commented Nov 15, 2020

@thejoshsmith I've seen it with Vue SFCs too

@mikedaviesweb
Copy link

Hey @thejoshsmith, yes this happens with Vue SFCs. Say you add some new data to the vue component, and output it in the template, on save the vue component hot-reloads and you see the new data in browser, then the page completely refreshes, happends 9/10 times.

@rb1193
Copy link
Author

rb1193 commented Nov 16, 2020

I think I've gotten to the bottom of this, but I need to confirm the appropriate solution with @judereid and @thejoshsmith. I believe this is caused by both the legacy and modern webpack configs running their own hot reload process - on the second request for hot-update.json a 404 is returned, presumably because that file got replaced by the other process. It appears in some cases the file is accessed before the other process replaces it, hence we only see the issue intermittently.

When I comment out the legacy config, hot reload appears to work as expected (I've triggered over a dozen with no problem, with various page refreshes in between). Do we even need a legacy config for development? If we do, would it not be better to pass an isLegacy environment param via the start script and build a single config off of that, rather than building both configs on every occasion? I'm actually surprised exporting two configs from webpack.dev.js works at all, but I'm guessing there's a gap in my understanding.

@judereid
Copy link
Contributor

@rb1193 The legacy build shouldn't be included by default (with npm run dev), and only run when then environment variable BUILD_TYPE is explicitly set to legacy or combined (using the npm run dev-legacy or npm run dev-combined commands).

If the combined build is running by default, that's definitely a bug.

cc @thejoshsmith

@rb1193
Copy link
Author

rb1193 commented Nov 16, 2020

Ok, looks like this one is already fixed in the latest version 🎉 I was running into this a lot on Lyttelton but I've updated Craft webpack to the latest version locally and am now unable to reproduce, unless I specifically run the "dev-combined" command which runs both the legacy and modern configs. I may open a PR to remove the combined option as Jude and I aren't really convinced it has a valid use case.

@mikedaviesweb do you want to try upgrading any projects you're having issues with to the latest version of craft-webpack and seeing if that resolves the issue?

@mikedaviesweb
Copy link

Hey @rb1193, sounds good! Next time I'm on the NPC project I'll upgrade and see if the issues is resolved.

@moacode
Copy link

moacode commented Nov 16, 2020

Ah yes, I added support for legacy/modern builds in v1.4.0. The use case for running a legacy bundle in development is so you can check IE11 (or other legacy browser) compatibility in tools such as BrowserStack without having to perform a build each time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants