Skip to content

Commit 010fc9b

Browse files
committed
refactor(rsc-mf): normalize callback action URL and assert request Accept headers
1 parent 82936fe commit 010fc9b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ const getHostActionId = (rawActionId: string, remoteAlias: string) => {
1414
// Align with RSC bridge action-id format expected by host runtime plugin.
1515
return `remote:${remoteAlias}:${rawActionId}`;
1616
};
17+
const getNormalizedRemoteActionUrl = (remoteOrigin: string) => {
18+
const url = new URL(remoteOrigin);
19+
url.search = '';
20+
url.hash = '';
21+
return url.toString();
22+
};
1723

1824
export function registerRemoteServerCallback(
1925
remoteOrigin: string,
@@ -22,15 +28,15 @@ export function registerRemoteServerCallback(
2228
if (!remoteOrigin) {
2329
return;
2430
}
31+
const remoteActionUrl = getNormalizedRemoteActionUrl(remoteOrigin);
2532
const callbackKey = JSON.stringify({
2633
remoteAlias,
27-
remoteOrigin,
34+
remoteActionUrl,
2835
});
2936
if (registeredCallbackKey === callbackKey) {
3037
return;
3138
}
3239

33-
const remoteActionUrl = new URL(remoteOrigin).toString();
3440
setServerCallback(async (id, args) => {
3541
const hostActionId = getHostActionId(id, remoteAlias);
3642
const temporaryReferences = createTemporaryReferenceSet();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,10 @@ function runTests({ mode }: TestConfig) {
584584
expect(runtimeRegisterSource).toContain("'x-rsc-action': hostActionId");
585585
expect(runtimeRegisterSource).toContain("method: 'POST'");
586586
expect(runtimeRegisterSource).toContain("Accept: 'text/x-component'");
587+
expect(runtimeRegisterSource).toContain('getNormalizedRemoteActionUrl');
588+
expect(runtimeRegisterSource).toContain("url.search = ''");
589+
expect(runtimeRegisterSource).toContain("url.hash = ''");
590+
expect(runtimeRegisterSource).toContain('remoteActionUrl,');
587591
expect(runtimeRegisterSource).not.toContain(
588592
'remoteActionIdToHostProxyActionId',
589593
);

0 commit comments

Comments
 (0)