Skip to content

[webpack-localization-plugin] Fix circular reference in assetInfo.related #4937

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
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/webpack5-localization-plugin",
"comment": "Fix circular references between localized assets' \"related\" properties. This caused emitting of the webpack stats object to fail.",
"type": "patch"
}
],
"packageName": "@rushstack/webpack5-localization-plugin"
}
11 changes: 8 additions & 3 deletions webpack/webpack5-localization-plugin/src/AssetProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ export function processLocalizedAsset(options: IProcessLocalizedAssetOptions): R

const fileName: string = compilation.getAssetPath(filenameTemplate, data);

originInfo.related[locale] = fileName;

const info: AssetInfo = {
...originInfo,
locale
Expand All @@ -130,8 +128,15 @@ export function processLocalizedAsset(options: IProcessLocalizedAssetOptions): R
// If file already exists
if (originName === fileName) {
// This helper throws if the asset doesn't already exist
compilation.updateAsset(fileName, wrapped, info);
// Use the function form so that the object identity of `related` is preserved.
// Since we already read the original info, we don't need fancy merge logic.
compilation.updateAsset(fileName, wrapped, () => info);
} else {
// If A.related points to B, B.related can't point to A or the stats emitter explodes
// So just strip the related object for the localized assets
info.related = undefined;
// We omit the `related` property that does a self-reference.
originInfo.related[locale] = fileName;
// This helper throws if the asset already exists
compilation.emitAsset(fileName, wrapped, info);
}
Expand Down
Loading