Skip to content

Commit 6c0bbdb

Browse files
heswellCopilot
andcommitted
fix: support connectionless remote modules
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent edf865a commit 6c0bbdb

3 files changed

Lines changed: 60 additions & 8 deletions

File tree

docs/rfc/vuu_table_browser.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ The browser's registry descriptor is expected to be equivalent to:
233233
```
234234

235235
The descriptor intentionally has no `vuu` property.
236+
The host `RemoteModule` MUST therefore render the browser without installing a
237+
connection-scoped `AuthenticationProvider`; remotes that require Vuu data MUST
238+
provide explicit `vuu` metadata.
236239

237240
### 2. Navigation
238241

vuu-ui/packages/core/src/remote-module/RemoteModule.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export interface RemoteModuleProps<
2929
width?: number;
3030
}
3131

32-
const portalConnection = { connectionId: "portal" };
33-
3432
const getLazyComponent = (
3533
scope: string,
3634
component: string,
@@ -95,6 +93,9 @@ function RawRemoteModule<ComponentProps extends object | undefined>({
9593
...remoteProps
9694
}: RemoteModuleProps<ComponentProps>) {
9795
const RemoteComponent = getRemoteComponent(mfUrl, mfScope, mfComponent);
96+
const remoteComponent = (
97+
<RemoteComponent {...remoteProps} {...componentProps} />
98+
);
9899

99100
return (
100101
<RemoteModuleErrorBoundary
@@ -106,12 +107,13 @@ function RawRemoteModule<ComponentProps extends object | undefined>({
106107
onError?.(error);
107108
}}
108109
>
109-
<AuthenticationProvider
110-
mode="vuu-connection"
111-
connection={vuu ?? portalConnection}
112-
>
113-
<RemoteComponent {...remoteProps} {...componentProps} />
114-
</AuthenticationProvider>
110+
{vuu ? (
111+
<AuthenticationProvider mode="vuu-connection" connection={vuu}>
112+
{remoteComponent}
113+
</AuthenticationProvider>
114+
) : (
115+
remoteComponent
116+
)}
115117
</RemoteModuleErrorBoundary>
116118
);
117119
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { act, Suspense } from "react";
2+
import { createRoot, type Root } from "react-dom/client";
3+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4+
5+
vi.mock("@module-federation/enhanced/runtime", () => ({
6+
loadRemote: vi.fn().mockResolvedValue({
7+
default: () => <div>Connectionless remote loaded</div>,
8+
}),
9+
registerRemotes: vi.fn(),
10+
}));
11+
12+
import { RemoteModule } from "../../src/remote-module/RemoteModule";
13+
14+
describe("RemoteModule", () => {
15+
let container: HTMLDivElement;
16+
let root: Root;
17+
18+
beforeEach(() => {
19+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
20+
container = document.createElement("div");
21+
document.body.append(container);
22+
root = createRoot(container);
23+
vi.spyOn(console, "error").mockImplementation(() => {});
24+
});
25+
26+
afterEach(async () => {
27+
await act(async () => root.unmount());
28+
container.remove();
29+
vi.restoreAllMocks();
30+
});
31+
32+
it("loads a remote without a Vuu connection when metadata is absent", async () => {
33+
await act(async () => {
34+
root.render(
35+
<Suspense fallback="Loading">
36+
<RemoteModule
37+
mfComponent="ConnectionlessRemote"
38+
mfScope="connectionless"
39+
mfUrl="http://localhost:5000"
40+
/>
41+
</Suspense>,
42+
);
43+
});
44+
45+
expect(container.textContent).toBe("Connectionless remote loaded");
46+
});
47+
});

0 commit comments

Comments
 (0)