Skip to content

Commit 4a92133

Browse files
committed
refactor(rsc-mf): dedupe repeated expose import entries
1 parent ae03f8f commit 4a92133

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

tests/integration/rsc-mf/remote/src/runtime/createRscExposeDefinitions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ interface NormalizedExposeDefinition {
1515
importPaths: string[];
1616
exposeOverrides: Record<string, unknown>;
1717
}
18+
const getUniqueImportPaths = (importPaths: string[]) => [
19+
...new Set(importPaths),
20+
];
1821

1922
if (!CALLBACK_BOOTSTRAP_IMPORT.startsWith(CALLBACK_BOOTSTRAP_PREFIX)) {
2023
throw new Error(
@@ -65,7 +68,7 @@ const normalizeExposeImportPaths = (
6568
exposeImport.every(item => typeof item === 'string')
6669
) {
6770
return {
68-
importPaths: exposeImport,
71+
importPaths: getUniqueImportPaths(exposeImport),
6972
exposeOverrides,
7073
} satisfies NormalizedExposeDefinition;
7174
}

tests/integration/rsc-mf/tests/createRscExposeDefinitions.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,31 @@ describe('createRscExposeDefinitions', () => {
169169
});
170170
});
171171

172+
it('deduplicates repeated entries in object expose import arrays', () => {
173+
const { createRscExposeDefinitions, CALLBACK_BOOTSTRAP_MODULE } =
174+
loadCreateRscExposeDefinitions();
175+
const exposeDefinitions = createRscExposeDefinitions({
176+
'./infoBundle': {
177+
import: [
178+
'./src/components/infoBundle.ts',
179+
'./src/components/infoBundle.ts',
180+
'./src/components/remoteMeta.ts',
181+
],
182+
},
183+
});
184+
185+
expect(exposeDefinitions).toEqual({
186+
'./infoBundle': {
187+
import: [
188+
CALLBACK_BOOTSTRAP_MODULE,
189+
'./src/components/infoBundle.ts',
190+
'./src/components/remoteMeta.ts',
191+
],
192+
layer: 'react-server-components',
193+
},
194+
});
195+
});
196+
172197
it('rejects object expose definitions with invalid import payloads', () => {
173198
const { createRscExposeDefinitions } = loadCreateRscExposeDefinitions();
174199
expect(() =>

0 commit comments

Comments
 (0)