Skip to content

Commit b86124c

Browse files
committed
fix(rsc-mf): append nested mixed alias in copied build chunks
1 parent 7c5e3ea commit b86124c

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

tests/integration/rsc-mf/host/modern.config.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const serverOnlyEmptyPath = path.join(
88
'empty.js',
99
);
1010
const remoteDistStaticDir = path.resolve(__dirname, '../remote/dist/static');
11+
const REMOTE_COUNTER_ALIAS_MODULE =
12+
'remote-module:rscRemote:./src/components/RemoteClientCounter.tsx';
13+
const REMOTE_COUNTER_SOURCE_MODULE = './src/components/RemoteClientCounter.tsx';
14+
const createRemoteNestedMixedAliasChunk = () =>
15+
`\n;(globalThis["chunk_rscHost"] = globalThis["chunk_rscHost"] || []).push([["__federation_expose_RemoteNestedMixed_alias"],{"${REMOTE_COUNTER_ALIAS_MODULE}":function(module,__unused,__webpack_require__){module.exports=__webpack_require__("${REMOTE_COUNTER_SOURCE_MODULE}");}}]);`;
1116

1217
const copyRemoteExposeAssets = async (subDir: 'js' | 'css') => {
1318
const remoteAsyncDir = path.join(remoteDistStaticDir, subDir, 'async');
@@ -21,12 +26,26 @@ const copyRemoteExposeAssets = async (subDir: 'js' | 'css') => {
2126
await Promise.all(
2227
remoteFiles
2328
.filter(file => file.startsWith('__federation_expose_'))
24-
.map(file =>
25-
fs.copyFile(
26-
path.join(remoteAsyncDir, file),
27-
path.join(hostAsyncDir, file),
28-
),
29-
),
29+
.map(async file => {
30+
const sourceFile = path.join(remoteAsyncDir, file);
31+
const targetFile = path.join(hostAsyncDir, file);
32+
const shouldPatchNestedMixedChunk =
33+
subDir === 'js' &&
34+
file.startsWith('__federation_expose_RemoteNestedMixed') &&
35+
file.endsWith('.js');
36+
37+
if (!shouldPatchNestedMixedChunk) {
38+
await fs.copyFile(sourceFile, targetFile);
39+
return;
40+
}
41+
42+
const chunkText = await fs.readFile(sourceFile, 'utf-8');
43+
await fs.writeFile(
44+
targetFile,
45+
`${chunkText}${createRemoteNestedMixedAliasChunk()}`,
46+
'utf-8',
47+
);
48+
}),
3049
);
3150
};
3251

0 commit comments

Comments
 (0)