question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Full page reload on syntax errors during hot reloads

See original GitHub issue
  • Operating System: Mac 10.13.6
  • Node Version: 11.8.0
  • NPM Version: 6.5.0
  • webpack Version: 4.29.0
  • webpack-dev-server Version: 3.1.14
  • This is a bug
  • This is a modification request

Code

  // webpack.config.js
{
	mode: 'development',
	devServer: {
		contentBase: 'build/',
		hot: true,
	},
	plugins: [
		new webpack.HotModuleReplacementPlugin(),
	],
}
// get a foo
var foo = require('./foo')

if (module.hot) {
    module.hot.accept('./foo', function () {
        // clean up the old foo
        foo.dispose()
        // replace it with a new one
        foo = require('./foo')
    })
}

Actual Behavior

Above is a super-minimal version of my HMR setup - it works fine, whenever foo.js changes it gets hot reloaded, so far so good.

The problem occurs when there’s some kind of error in the HMR handler - for example, a syntax error inside foo.dispose(). When that’s the case, then whenever you edit foo.js, the HMR handler executes and dev-server catch the syntax error, and then fully reloads the page. This prevents the developer from knowing there’s a syntax error - it just looks like HMR has stopped working.

Expected Behavior

WDS should allow the error to be caught by the browser so the developer can see it - or if there’s a really good reason not to, I guess have an option to prevent the automatic reloading?

For Bugs; How can we reproduce the behavior?

As far as I can tell any kind of syntax error inside the HMR event handler function causes this.

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
fenomascommented, Feb 22, 2019

@evilebottnawi Uhhhh I’d better start over 😁

Currently, when there’s a syntax error inside an HMR callback, WDS reloads the page, right? That’s what should be happening in the minimal reproduction repo, step 3.

The issue I’m reporting is that WDS should not reload the page in this case. If WDS doesn’t reload the page, then the HMR callback will execute and the browser will catch the error and so forth.

Hope that’s clearer!

1reaction
fenomascommented, Feb 1, 2019

@evilebottnawi The code samples above are already the minimal repro, there’s nothing else in the project.

Here’s the same code in a repo: https://github.com/andyhall/wds_hmr_issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "Aborted because 0 is not accepted" and full page ...
I am using webpack in an existing rails app. But it isn't hot-reloading. It is simply triggering a reload every time my react...
Read more >
My Wishlist for Hot Reloading - Overreacted
Syntax error shouldn't make you lose the state. A syntax error after reload should still be visible.
Read more >
Basic Features: Fast Refresh - Next.js
Next.js' Fast Refresh is a new hot reloading experience that gives you instantaneous feedback on edits made to your React components.
Read more >
Troubleshooting - Vite
A full reload happens instead of HMR #. If HMR is not handled by Vite or a plugin, a full reload will happen....
Read more >
Fast Reliable/Hot Reloading in Next.js - Coding Ninjas
The file can be regenerated if a syntax error is made during development. Because the error will automatically disappear, there is no need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found