Skip to content

Commit 051929d

Browse files
committed
refactor(rsc-mf): avoid client stringify in callback dependency
1 parent 6871db7 commit 051929d

2 files changed

Lines changed: 42 additions & 35 deletions

File tree

tests/integration/rsc-mf/host/src/server-component-root/App.tsx

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,45 @@ const App = () => {
4242
// Map remote action IDs to host-local proxy action IDs so client-side
4343
// callbacks can always post a host-resolvable action id. This keeps
4444
// remote action execution in-process on the host via proxy imports.
45-
const remoteActionIdToHostProxyActionId = Object.fromEntries(
45+
const remoteActionIdToHostProxyActionEntries = [
46+
[
47+
getServerActionId(incrementRemoteCount),
48+
getServerActionId(proxyIncrementRemoteCount),
49+
],
50+
[
51+
getServerActionId(remoteActionEcho),
52+
getServerActionId(proxyRemoteActionEcho),
53+
],
54+
[
55+
getServerActionId(nestedRemoteAction),
56+
getServerActionId(proxyNestedRemoteAction),
57+
],
58+
[
59+
getServerActionId(defaultRemoteAction),
60+
getServerActionId(proxyDefaultRemoteAction),
61+
],
4662
[
47-
[
48-
getServerActionId(incrementRemoteCount),
49-
getServerActionId(proxyIncrementRemoteCount),
50-
],
51-
[
52-
getServerActionId(remoteActionEcho),
53-
getServerActionId(proxyRemoteActionEcho),
54-
],
55-
[
56-
getServerActionId(nestedRemoteAction),
57-
getServerActionId(proxyNestedRemoteAction),
58-
],
59-
[
60-
getServerActionId(defaultRemoteAction),
61-
getServerActionId(proxyDefaultRemoteAction),
62-
],
63-
[
64-
getServerActionId(remoteActionBundle.bundledIncrementRemoteCount),
65-
getServerActionId(proxyBundledIncrementRemoteCount),
66-
],
67-
[
68-
getServerActionId(remoteActionBundle.bundledRemoteActionEcho),
69-
getServerActionId(proxyBundledRemoteActionEcho),
70-
],
71-
[
72-
getServerActionId(remoteActionBundle.bundledNestedRemoteAction),
73-
getServerActionId(proxyBundledNestedRemoteAction),
74-
],
75-
[
76-
getServerActionId(remoteActionBundle.bundledDefaultRemoteAction),
77-
getServerActionId(proxyBundledDefaultRemoteAction),
78-
],
79-
].filter((pair): pair is [string, string] => Boolean(pair[0] && pair[1])),
63+
getServerActionId(remoteActionBundle.bundledIncrementRemoteCount),
64+
getServerActionId(proxyBundledIncrementRemoteCount),
65+
],
66+
[
67+
getServerActionId(remoteActionBundle.bundledRemoteActionEcho),
68+
getServerActionId(proxyBundledRemoteActionEcho),
69+
],
70+
[
71+
getServerActionId(remoteActionBundle.bundledNestedRemoteAction),
72+
getServerActionId(proxyBundledNestedRemoteAction),
73+
],
74+
[
75+
getServerActionId(remoteActionBundle.bundledDefaultRemoteAction),
76+
getServerActionId(proxyBundledDefaultRemoteAction),
77+
],
78+
].filter((pair): pair is [string, string] => Boolean(pair[0] && pair[1]));
79+
const remoteActionIdToHostProxyActionId = Object.fromEntries(
80+
remoteActionIdToHostProxyActionEntries,
81+
);
82+
const remoteActionIdMapKey = JSON.stringify(
83+
remoteActionIdToHostProxyActionEntries,
8084
);
8185

8286
const remoteServerOnlyInfo = getServerOnlyInfo();
@@ -126,6 +130,7 @@ const App = () => {
126130
<form action={proxyBundledDefaultRemoteAction} />
127131
</div>
128132
<HostRemoteActionRunner
133+
remoteActionIdMapKey={remoteActionIdMapKey}
129134
remoteActionIdToHostProxyActionId={remoteActionIdToHostProxyActionId}
130135
/>
131136
</div>

tests/integration/rsc-mf/host/src/server-component-root/HostRemoteActionRunner.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import { defaultRemoteAction } from 'rscRemote/defaultAction';
99
import { registerRemoteServerCallback } from 'rscRemote/registerServerCallback';
1010

1111
export default function HostRemoteActionRunner({
12+
remoteActionIdMapKey,
1213
remoteActionIdToHostProxyActionId,
1314
}: {
15+
remoteActionIdMapKey: string;
1416
remoteActionIdToHostProxyActionId: Record<string, string>;
1517
}) {
1618
// Keep this import in the client graph so federated RSC bridge IDs
@@ -32,7 +34,7 @@ export default function HostRemoteActionRunner({
3234
'rscRemote',
3335
remoteActionIdToHostProxyActionId,
3436
);
35-
}, [JSON.stringify(remoteActionIdToHostProxyActionId)]);
37+
}, [remoteActionIdMapKey]);
3638

3739
const runActions = async () => {
3840
setIsPending(true);

0 commit comments

Comments
 (0)