Skip to content

fix: include all chunkFiles in fallbackFiles in order to avoid wrong lazy Angular chunks #4925

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

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions lib/services/webpack/webpack-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,33 +221,25 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
return args;
}

private getUpdatedEmittedFiles(emittedFiles: string[], chunkFiles: string[]) {
let fallbackFiles: string[] = [];
private getUpdatedEmittedFiles(allEmittedFiles: string[], chunkFiles: string[]) {
const hotHash = this.getCurrentHotUpdateHash(allEmittedFiles);
const emittedHotUpdateFiles = _.difference(allEmittedFiles, chunkFiles);

return { emittedFiles: emittedHotUpdateFiles, fallbackFiles: chunkFiles, hash: hotHash };
}

private getCurrentHotUpdateHash(emittedFiles: string[]) {
let hotHash;
let result = emittedFiles.slice();
const hotUpdateScripts = emittedFiles.filter(x => x.endsWith('.hot-update.js'));
if (chunkFiles && chunkFiles.length) {
result = result.filter(file => chunkFiles.indexOf(file) === -1);
if (hotUpdateScripts && hotUpdateScripts.length) {
// the hash is the same for each hot update in the current compilation
const hotUpdateName = hotUpdateScripts[0];
const matcher = /^(.+)\.(.+)\.hot-update/gm;
const matches = matcher.exec(hotUpdateName);
hotHash = matches[2];
}
hotUpdateScripts.forEach(hotUpdateScript => {
const { name, hash } = this.parseHotUpdateChunkName(hotUpdateScript);
hotHash = hash;
// remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
result = result.filter(file => file !== `${name}.js`);
});
// if applying of hot update fails, we must fallback to the full files
fallbackFiles = emittedFiles.filter(file => hotUpdateScripts.indexOf(file) === -1);

return { emittedFiles: result, fallbackFiles, hash: hotHash };
}

private parseHotUpdateChunkName(name: string) {
const matcher = /^(.+)\.(.+)\.hot-update/gm;
const matches = matcher.exec(name);
return {
name: matches[1] || "",
hash: matches[2] || "",
};
return hotHash || "";
}

private async stopWebpackForPlatform(platform: string) {
Expand Down