Skip to content

Commit

Permalink
Merge pull request #15222 from webpack/bugfix/serialization-warning
Browse files Browse the repository at this point in the history
store url as Buffer to avoid serialization warnings
  • Loading branch information
sokra committed Jan 21, 2022
2 parents e2d214a + 17f317b commit 3014a3b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/RuntimeTemplate.js
Expand Up @@ -1031,7 +1031,7 @@ class RuntimeTemplate {
const codeGen = codeGenerationResults.get(module, runtime);
const { data } = codeGen;
const url = data.get("url");
if (url) return url;
if (url) return url.toString();
const filename = data.get("filename");
return publicPath + filename;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/asset/AssetGenerator.js
Expand Up @@ -215,7 +215,7 @@ class AssetGenerator extends Generator {
},${encodedContent}`;
}
const data = getData();
data.set("url", encodedSource);
data.set("url", Buffer.from(encodedSource));
return new RawSource(
`${RuntimeGlobals.module}.exports = ${JSON.stringify(
encodedSource
Expand Down
11 changes: 7 additions & 4 deletions lib/asset/RawDataUrlModule.js
Expand Up @@ -33,6 +33,7 @@ class RawDataUrlModule extends Module {
constructor(url, identifier, readableIdentifier) {
super("asset/raw-data-url", null);
this.url = url;
this.urlBuffer = url ? Buffer.from(url) : undefined;
this.identifierStr = identifier || this.url;
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
}
Expand All @@ -56,6 +57,7 @@ class RawDataUrlModule extends Module {
* @returns {number} the estimated size of the module (must be non-zero)
*/
size(type) {
if (this.url === undefined) this.url = this.urlBuffer.toString();
return Math.max(1, this.url.length);
}

Expand Down Expand Up @@ -97,13 +99,14 @@ class RawDataUrlModule extends Module {
* @returns {CodeGenerationResult} result
*/
codeGeneration(context) {
if (this.url === undefined) this.url = this.urlBuffer.toString();
const sources = new Map();
sources.set(
"javascript",
new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
);
const data = new Map();
data.set("url", this.url);
data.set("url", this.urlBuffer);
const runtimeRequirements = new Set();
runtimeRequirements.add(RuntimeGlobals.module);
return { sources, runtimeRequirements, data };
Expand All @@ -115,14 +118,14 @@ class RawDataUrlModule extends Module {
* @returns {void}
*/
updateHash(hash, context) {
hash.update(this.url);
hash.update(this.urlBuffer);
super.updateHash(hash, context);
}

serialize(context) {
const { write } = context;

write(this.url);
write(this.urlBuffer);
write(this.identifierStr);
write(this.readableIdentifierStr);

Expand All @@ -132,7 +135,7 @@ class RawDataUrlModule extends Module {
deserialize(context) {
const { read } = context;

this.url = read();
this.urlBuffer = read();
this.identifierStr = read();
this.readableIdentifierStr = read();

Expand Down

0 comments on commit 3014a3b

Please sign in to comment.