Skip to content

Commit ba39928

Browse files
committed
refactor(rsc-mf): normalize callback URLs with trailing slashes
1 parent 8f9e303 commit ba39928

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const getNormalizedRemoteActionUrl = (remoteOrigin: string) => {
4747
'Remote action callback URL must not include embedded credentials.',
4848
);
4949
}
50+
const normalizedPathname = url.pathname.replace(/\/+$/, '') || '/';
51+
url.pathname = normalizedPathname;
5052
url.search = '';
5153
url.hash = '';
5254
return url.toString();

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,31 @@ describe('registerRemoteServerCallback runtime behavior', () => {
384384
);
385385
});
386386

387+
it('dedupes callback registrations when only trailing slash differs', async () => {
388+
const { registerRemoteServerCallback } = await importRegisterHelper();
389+
registerRemoteServerCallback(
390+
'http://127.0.0.1:3008/server-component-root/',
391+
'rscRemote',
392+
);
393+
registerRemoteServerCallback(
394+
'http://127.0.0.1:3008/server-component-root',
395+
'rscRemote',
396+
);
397+
expect(mockSetServerCallback).toHaveBeenCalledTimes(1);
398+
399+
const callback = getRegisteredCallback();
400+
await callback('slash-normalized-action', []);
401+
402+
expect(global.fetch).toHaveBeenCalledWith(
403+
'http://127.0.0.1:3008/server-component-root',
404+
expect.objectContaining({
405+
headers: expect.objectContaining({
406+
'x-rsc-action': 'remote:rscRemote:slash-normalized-action',
407+
}),
408+
}),
409+
);
410+
});
411+
387412
it('re-registers callback when alias changes and uses new alias prefix', async () => {
388413
const { registerRemoteServerCallback } = await importRegisterHelper();
389414
registerRemoteServerCallback(

0 commit comments

Comments
 (0)