-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
feat: hmr error recovery #435
Open
rjgotten
wants to merge
5
commits into
webpack-contrib:master
Choose a base branch
from
NetMatch:hmr-error-recovery
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
17acb10
feat: hmr error recovery
rjgotten 607532d
feat: hmr error recovery test
rjgotten ad42401
fix: amends hmr error recovery tests
rjgotten ed9f295
fix: remove unused testcase file
rjgotten 380f822
fix: hmr error recovery review remarks
rjgotten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function loader() { | ||
const callback = this.async(); | ||
callback(new Error('I am error')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["check"],{ | ||
|
||
/***/ "./index.css": | ||
/***/ (function(module, exports, __webpack_require__) { | ||
|
||
// extracted by mini-css-extract-plugin | ||
if(true) { | ||
// 1479427200000 | ||
var cssReload = __webpack_require__("../../../src/hmr/hotModuleReplacement.js")(module.i, {"hmr":true,"locals":false}); | ||
module.hot.dispose(cssReload); | ||
module.hot.accept(function(){}); | ||
module.hot.accept(undefined, cssReload); | ||
} | ||
|
||
throw new Error("ModuleBuildError: Module build failed (from ./error-loader.js):\nError: I am error\n at Object.loader (error-loader.js:1:1)"); | ||
|
||
/***/ }) | ||
|
||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.a { | ||
background: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { HotModuleReplacementPlugin } from 'webpack'; | ||
|
||
import Self from '../../../src'; | ||
|
||
module.exports = { | ||
entry: './index.css', | ||
mode: 'development', | ||
devtool: false, | ||
// NOTE: | ||
// Using optimization settings to shunt everything | ||
// except the generated module code itself into | ||
// discarded chunks that won't be compared for | ||
// expected output. | ||
optimization: { | ||
runtimeChunk: 'single', | ||
namedModules: true, | ||
namedChunks: true, | ||
splitChunks: { | ||
chunks: 'all', | ||
cacheGroups: { | ||
vendors: { | ||
test: /[\\/]index\.css$/, | ||
name: 'check', | ||
enforce: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: Self.loader, | ||
options: { | ||
hmr: true, | ||
}, | ||
}, | ||
require.resolve('./error-loader'), | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new HotModuleReplacementPlugin(), | ||
new Self({ | ||
filename: '[name].css', | ||
}), | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.emit.tapAsync('no-emit', (compilation, callback) => { | ||
const { assets } = compilation; | ||
|
||
// Not interested in comparing output for these. | ||
delete assets['runtime.js']; | ||
delete assets['main.js']; | ||
|
||
callback(); | ||
}); | ||
}, | ||
}, | ||
], | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For catching errors, right?
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.
Yes. It was moved down passed the dependencies, to ensure those dependenices are always tracked.
Flipping the error state into a success state on the parent compilation, means that it will also update its registered dependencies. (If the parent compilation would fail, it would retain the previous set.)
If we'd drop out of the child compilation because of an error before the dependencies of the child compilation are moved into the parent, then we would 'lose' those dependencies, including any change watches on them. This way, we won't.
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.
Would there be a case where multiple errors need to be shown in the errors array?
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.
@ScriptedAlchemy
Not sure actually. The current version of the plugin only reports the first child compilation error as well.