Skip to content

Commit 3f5fe0d

Browse files
authored
fix: include missing generator options in updateHash for persistent cache correctness (#20821)
CssGenerator was missing `exportsOnly`, JsonGenerator was missing `JSONParse`, and WebAssemblyGenerator was missing `mangleImports` in their updateHash methods. This could cause stale cached code generation results when these options change between builds with filesystem cache.
1 parent 5bb1d4f commit 3f5fe0d

6 files changed

Lines changed: 92 additions & 60 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Include missing generator options in hash to ensure persistent cache invalidation when configuration changes (CssGenerator `exportsOnly`, JsonGenerator `JSONParse`, WebAssemblyGenerator `mangleImports`).

lib/css/CssGenerator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ class CssGenerator extends Generator {
705705
*/
706706
updateHash(hash, { module }) {
707707
hash.update(/** @type {boolean} */ (this._esModule).toString());
708+
hash.update(/** @type {boolean} */ (this._exportsOnly).toString());
708709
}
709710
}
710711

lib/json/JsonGenerator.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
1616
/** @typedef {import("../../declarations/WebpackOptions").JsonGeneratorOptions} JsonGeneratorOptions */
1717
/** @typedef {import("../ExportsInfo")} ExportsInfo */
1818
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
19+
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
20+
/** @typedef {import("../util/Hash")} Hash */
1921
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
2022
/** @typedef {import("../Module").SourceType} SourceType */
2123
/** @typedef {import("../Module").SourceTypes} SourceTypes */
@@ -237,6 +239,17 @@ class JsonGenerator extends Generator {
237239
generateError(error, module, generateContext) {
238240
return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
239241
}
242+
243+
/**
244+
* Updates the hash with the data contributed by this instance.
245+
* @param {Hash} hash hash that will be modified
246+
* @param {UpdateHashContext} updateHashContext context for updating hash
247+
*/
248+
updateHash(hash, updateHashContext) {
249+
if (this.options.JSONParse) {
250+
hash.update("json-parse");
251+
}
252+
}
240253
}
241254

242255
module.exports = JsonGenerator;

lib/wasm-sync/WebAssemblyGenerator.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ const WebAssemblyUtils = require("./WebAssemblyUtils");
1717

1818
/** @typedef {import("webpack-sources").Source} Source */
1919
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
20+
/** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
2021
/** @typedef {import("../Module")} Module */
2122
/** @typedef {import("../Module").SourceType} SourceType */
2223
/** @typedef {import("../Module").SourceTypes} SourceTypes */
2324
/** @typedef {import("../ModuleGraph")} ModuleGraph */
2425
/** @typedef {import("../NormalModule")} NormalModule */
26+
/** @typedef {import("../util/Hash")} Hash */
2527
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
2628
/** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */
2729
/** @typedef {import("@webassemblyjs/ast").Instruction} Instruction */
@@ -542,6 +544,17 @@ class WebAssemblyGenerator extends Generator {
542544
generateError(error, module, generateContext) {
543545
return new RawSource(error.message);
544546
}
547+
548+
/**
549+
* Updates the hash with the data contributed by this instance.
550+
* @param {Hash} hash hash that will be modified
551+
* @param {UpdateHashContext} updateHashContext context for updating hash
552+
*/
553+
updateHash(hash, updateHashContext) {
554+
if (this.options.mangleImports) {
555+
hash.update("mangle-imports");
556+
}
557+
}
545558
}
546559

547560
module.exports = WebAssemblyGenerator;

test/configCases/css/local-ident-name/__snapshots__/ConfigCacheTest.snap

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ Object {
1414

1515
exports[`ConfigCacheTestCases css local-ident-name exported tests should have correct local ident for css export locals 2`] = `
1616
Object {
17-
"btn--info_is-disabled_1": "_8ee4d8b938ce15d40534",
18-
"btn-info_is-disabled": "_8ee4d8b938ce15d40534",
19-
"color-red": "--_8ee4d8b938ce15d40534",
17+
"btn--info_is-disabled_1": "_15e922b2c97f47f17c54",
18+
"btn-info_is-disabled": "_15e922b2c97f47f17c54",
19+
"color-red": "--_15e922b2c97f47f17c54",
2020
"foo": "bar",
21-
"foo_bar": "_8ee4d8b938ce15d40534",
21+
"foo_bar": "_15e922b2c97f47f17c54",
2222
"my-btn-info_is-disabled": "value",
23-
"simple": "_8ee4d8b938ce15d40534",
23+
"simple": "_15e922b2c97f47f17c54",
2424
}
2525
`;
2626

2727
exports[`ConfigCacheTestCases css local-ident-name exported tests should have correct local ident for css export locals 3`] = `
2828
Object {
29-
"btn--info_is-disabled_1": "f0e5e7b8779254ec04d4-btn--info_is-disabled_1",
30-
"btn-info_is-disabled": "f0e5e7b8779254ec04d4-btn-info_is-disabled",
31-
"color-red": "--f0e5e7b8779254ec04d4-color-red",
29+
"btn--info_is-disabled_1": "_04a0a4472ff4d45a1166-btn--info_is-disabled_1",
30+
"btn-info_is-disabled": "_04a0a4472ff4d45a1166-btn-info_is-disabled",
31+
"color-red": "--_04a0a4472ff4d45a1166-color-red",
3232
"foo": "bar",
33-
"foo_bar": "f0e5e7b8779254ec04d4-foo_bar",
33+
"foo_bar": "_04a0a4472ff4d45a1166-foo_bar",
3434
"my-btn-info_is-disabled": "value",
35-
"simple": "f0e5e7b8779254ec04d4-simple",
35+
"simple": "_04a0a4472ff4d45a1166-simple",
3636
}
3737
`;
3838

@@ -86,13 +86,13 @@ Object {
8686

8787
exports[`ConfigCacheTestCases css local-ident-name exported tests should have correct local ident for css export locals 8`] = `
8888
Object {
89-
"btn--info_is-disabled_1": "d5c602f0c8fdc09fea74-btn--info_is-disabled_1",
90-
"btn-info_is-disabled": "d5c602f0c8fdc09fea74-btn-info_is-disabled",
91-
"color-red": "--d5c602f0c8fdc09fea74-color-red",
89+
"btn--info_is-disabled_1": "ba1a7d6d0bb21c7b0653-btn--info_is-disabled_1",
90+
"btn-info_is-disabled": "ba1a7d6d0bb21c7b0653-btn-info_is-disabled",
91+
"color-red": "--ba1a7d6d0bb21c7b0653-color-red",
9292
"foo": "bar",
93-
"foo_bar": "d5c602f0c8fdc09fea74-foo_bar",
93+
"foo_bar": "ba1a7d6d0bb21c7b0653-foo_bar",
9494
"my-btn-info_is-disabled": "value",
95-
"simple": "d5c602f0c8fdc09fea74-simple",
95+
"simple": "ba1a7d6d0bb21c7b0653-simple",
9696
}
9797
`;
9898

@@ -110,25 +110,25 @@ Object {
110110

111111
exports[`ConfigCacheTestCases css local-ident-name exported tests should have correct local ident for css export locals 10`] = `
112112
Object {
113-
"btn--info_is-disabled_1": "_8ee4d8b938ce15d40534",
114-
"btn-info_is-disabled": "_8ee4d8b938ce15d40534",
115-
"color-red": "--_8ee4d8b938ce15d40534",
113+
"btn--info_is-disabled_1": "a02ad227dd548bb84a61",
114+
"btn-info_is-disabled": "a02ad227dd548bb84a61",
115+
"color-red": "--a02ad227dd548bb84a61",
116116
"foo": "bar",
117-
"foo_bar": "_8ee4d8b938ce15d40534",
117+
"foo_bar": "a02ad227dd548bb84a61",
118118
"my-btn-info_is-disabled": "value",
119-
"simple": "_8ee4d8b938ce15d40534",
119+
"simple": "a02ad227dd548bb84a61",
120120
}
121121
`;
122122

123123
exports[`ConfigCacheTestCases css local-ident-name exported tests should have correct local ident for css export locals 11`] = `
124124
Object {
125-
"btn--info_is-disabled_1": "f0e5e7b8779254ec04d4-btn--info_is-disabled_1",
126-
"btn-info_is-disabled": "f0e5e7b8779254ec04d4-btn-info_is-disabled",
127-
"color-red": "--f0e5e7b8779254ec04d4-color-red",
125+
"btn--info_is-disabled_1": "_81378ae70e35838d73e5-btn--info_is-disabled_1",
126+
"btn-info_is-disabled": "_81378ae70e35838d73e5-btn-info_is-disabled",
127+
"color-red": "--_81378ae70e35838d73e5-color-red",
128128
"foo": "bar",
129-
"foo_bar": "f0e5e7b8779254ec04d4-foo_bar",
129+
"foo_bar": "_81378ae70e35838d73e5-foo_bar",
130130
"my-btn-info_is-disabled": "value",
131-
"simple": "f0e5e7b8779254ec04d4-simple",
131+
"simple": "_81378ae70e35838d73e5-simple",
132132
}
133133
`;
134134

@@ -182,12 +182,12 @@ Object {
182182

183183
exports[`ConfigCacheTestCases css local-ident-name exported tests should have correct local ident for css export locals 16`] = `
184184
Object {
185-
"btn--info_is-disabled_1": "d5c602f0c8fdc09fea74-btn--info_is-disabled_1",
186-
"btn-info_is-disabled": "d5c602f0c8fdc09fea74-btn-info_is-disabled",
187-
"color-red": "--d5c602f0c8fdc09fea74-color-red",
185+
"btn--info_is-disabled_1": "_68c15c0000bcbbd61f4d-btn--info_is-disabled_1",
186+
"btn-info_is-disabled": "_68c15c0000bcbbd61f4d-btn-info_is-disabled",
187+
"color-red": "--_68c15c0000bcbbd61f4d-color-red",
188188
"foo": "bar",
189-
"foo_bar": "d5c602f0c8fdc09fea74-foo_bar",
189+
"foo_bar": "_68c15c0000bcbbd61f4d-foo_bar",
190190
"my-btn-info_is-disabled": "value",
191-
"simple": "d5c602f0c8fdc09fea74-simple",
191+
"simple": "_68c15c0000bcbbd61f4d-simple",
192192
}
193193
`;

test/configCases/css/local-ident-name/__snapshots__/ConfigTest.snap

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ Object {
1414

1515
exports[`ConfigTestCases css local-ident-name exported tests should have correct local ident for css export locals 2`] = `
1616
Object {
17-
"btn--info_is-disabled_1": "_8ee4d8b938ce15d40534",
18-
"btn-info_is-disabled": "_8ee4d8b938ce15d40534",
19-
"color-red": "--_8ee4d8b938ce15d40534",
17+
"btn--info_is-disabled_1": "_15e922b2c97f47f17c54",
18+
"btn-info_is-disabled": "_15e922b2c97f47f17c54",
19+
"color-red": "--_15e922b2c97f47f17c54",
2020
"foo": "bar",
21-
"foo_bar": "_8ee4d8b938ce15d40534",
21+
"foo_bar": "_15e922b2c97f47f17c54",
2222
"my-btn-info_is-disabled": "value",
23-
"simple": "_8ee4d8b938ce15d40534",
23+
"simple": "_15e922b2c97f47f17c54",
2424
}
2525
`;
2626

2727
exports[`ConfigTestCases css local-ident-name exported tests should have correct local ident for css export locals 3`] = `
2828
Object {
29-
"btn--info_is-disabled_1": "f0e5e7b8779254ec04d4-btn--info_is-disabled_1",
30-
"btn-info_is-disabled": "f0e5e7b8779254ec04d4-btn-info_is-disabled",
31-
"color-red": "--f0e5e7b8779254ec04d4-color-red",
29+
"btn--info_is-disabled_1": "_04a0a4472ff4d45a1166-btn--info_is-disabled_1",
30+
"btn-info_is-disabled": "_04a0a4472ff4d45a1166-btn-info_is-disabled",
31+
"color-red": "--_04a0a4472ff4d45a1166-color-red",
3232
"foo": "bar",
33-
"foo_bar": "f0e5e7b8779254ec04d4-foo_bar",
33+
"foo_bar": "_04a0a4472ff4d45a1166-foo_bar",
3434
"my-btn-info_is-disabled": "value",
35-
"simple": "f0e5e7b8779254ec04d4-simple",
35+
"simple": "_04a0a4472ff4d45a1166-simple",
3636
}
3737
`;
3838

@@ -86,13 +86,13 @@ Object {
8686

8787
exports[`ConfigTestCases css local-ident-name exported tests should have correct local ident for css export locals 8`] = `
8888
Object {
89-
"btn--info_is-disabled_1": "d5c602f0c8fdc09fea74-btn--info_is-disabled_1",
90-
"btn-info_is-disabled": "d5c602f0c8fdc09fea74-btn-info_is-disabled",
91-
"color-red": "--d5c602f0c8fdc09fea74-color-red",
89+
"btn--info_is-disabled_1": "ba1a7d6d0bb21c7b0653-btn--info_is-disabled_1",
90+
"btn-info_is-disabled": "ba1a7d6d0bb21c7b0653-btn-info_is-disabled",
91+
"color-red": "--ba1a7d6d0bb21c7b0653-color-red",
9292
"foo": "bar",
93-
"foo_bar": "d5c602f0c8fdc09fea74-foo_bar",
93+
"foo_bar": "ba1a7d6d0bb21c7b0653-foo_bar",
9494
"my-btn-info_is-disabled": "value",
95-
"simple": "d5c602f0c8fdc09fea74-simple",
95+
"simple": "ba1a7d6d0bb21c7b0653-simple",
9696
}
9797
`;
9898

@@ -110,25 +110,25 @@ Object {
110110

111111
exports[`ConfigTestCases css local-ident-name exported tests should have correct local ident for css export locals 10`] = `
112112
Object {
113-
"btn--info_is-disabled_1": "_8ee4d8b938ce15d40534",
114-
"btn-info_is-disabled": "_8ee4d8b938ce15d40534",
115-
"color-red": "--_8ee4d8b938ce15d40534",
113+
"btn--info_is-disabled_1": "a02ad227dd548bb84a61",
114+
"btn-info_is-disabled": "a02ad227dd548bb84a61",
115+
"color-red": "--a02ad227dd548bb84a61",
116116
"foo": "bar",
117-
"foo_bar": "_8ee4d8b938ce15d40534",
117+
"foo_bar": "a02ad227dd548bb84a61",
118118
"my-btn-info_is-disabled": "value",
119-
"simple": "_8ee4d8b938ce15d40534",
119+
"simple": "a02ad227dd548bb84a61",
120120
}
121121
`;
122122

123123
exports[`ConfigTestCases css local-ident-name exported tests should have correct local ident for css export locals 11`] = `
124124
Object {
125-
"btn--info_is-disabled_1": "f0e5e7b8779254ec04d4-btn--info_is-disabled_1",
126-
"btn-info_is-disabled": "f0e5e7b8779254ec04d4-btn-info_is-disabled",
127-
"color-red": "--f0e5e7b8779254ec04d4-color-red",
125+
"btn--info_is-disabled_1": "_81378ae70e35838d73e5-btn--info_is-disabled_1",
126+
"btn-info_is-disabled": "_81378ae70e35838d73e5-btn-info_is-disabled",
127+
"color-red": "--_81378ae70e35838d73e5-color-red",
128128
"foo": "bar",
129-
"foo_bar": "f0e5e7b8779254ec04d4-foo_bar",
129+
"foo_bar": "_81378ae70e35838d73e5-foo_bar",
130130
"my-btn-info_is-disabled": "value",
131-
"simple": "f0e5e7b8779254ec04d4-simple",
131+
"simple": "_81378ae70e35838d73e5-simple",
132132
}
133133
`;
134134

@@ -182,12 +182,12 @@ Object {
182182

183183
exports[`ConfigTestCases css local-ident-name exported tests should have correct local ident for css export locals 16`] = `
184184
Object {
185-
"btn--info_is-disabled_1": "d5c602f0c8fdc09fea74-btn--info_is-disabled_1",
186-
"btn-info_is-disabled": "d5c602f0c8fdc09fea74-btn-info_is-disabled",
187-
"color-red": "--d5c602f0c8fdc09fea74-color-red",
185+
"btn--info_is-disabled_1": "_68c15c0000bcbbd61f4d-btn--info_is-disabled_1",
186+
"btn-info_is-disabled": "_68c15c0000bcbbd61f4d-btn-info_is-disabled",
187+
"color-red": "--_68c15c0000bcbbd61f4d-color-red",
188188
"foo": "bar",
189-
"foo_bar": "d5c602f0c8fdc09fea74-foo_bar",
189+
"foo_bar": "_68c15c0000bcbbd61f4d-foo_bar",
190190
"my-btn-info_is-disabled": "value",
191-
"simple": "d5c602f0c8fdc09fea74-simple",
191+
"simple": "_68c15c0000bcbbd61f4d-simple",
192192
}
193193
`;

0 commit comments

Comments
 (0)