Skip to content

Commit faad3ae

Browse files
committed
fix(rsc-mf): register host callServer in remote action runtime
1 parent e72ed00 commit faad3ae

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
'use client';
22

3+
import { callServer } from '@modern-js/runtime/rsc/client';
34
import { useState } from 'react';
45
import RemoteClientBadge from 'rscRemote/RemoteClientBadge';
6+
import { RemoteClientCounter as RemoteClientCounterBridge } from 'rscRemote/RemoteClientCounter';
57
import { remoteActionEcho } from 'rscRemote/actions';
68
import defaultRemoteAction from 'rscRemote/defaultAction';
9+
import { registerRemoteServerCallback } from 'rscRemote/registerServerCallback';
710

811
export default function HostRemoteActionRunner() {
12+
// Keep this import in the client graph so federated RSC bridge IDs
13+
// can map back to a concrete remote module factory at runtime.
14+
void RemoteClientCounterBridge;
15+
registerRemoteServerCallback(callServer as any);
916
const [defaultResult, setDefaultResult] = useState('');
1017
const [echoResult, setEchoResult] = useState('');
1118
const [isPending, setIsPending] = useState(false);

tests/integration/rsc-mf/remote/module-federation.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export default createModuleFederationConfig({
155155
import: './src/components/defaultAction.ts',
156156
layer: LAYERS.rsc,
157157
} as any,
158+
'./registerServerCallback': {
159+
import: './src/components/registerServerCallback.ts',
160+
layer: LAYERS.rsc,
161+
} as any,
158162
},
159163
shared: sharedByScope as any,
160164
dts: false,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { setServerCallback } from 'react-server-dom-rspack/client.browser';
2+
3+
type CallServer = (id: string, args: unknown[]) => Promise<unknown>;
4+
5+
let hasRegisteredRemoteServerCallback = false;
6+
7+
export function registerRemoteServerCallback(callServer: CallServer) {
8+
if (hasRegisteredRemoteServerCallback) {
9+
return;
10+
}
11+
setServerCallback(callServer as any);
12+
hasRegisteredRemoteServerCallback = true;
13+
}

0 commit comments

Comments
 (0)