Carry the plugin installation through the modal bridge

On phones and native apps Modal.Content renders its body under Gorhom's root
portal host. The bridge rebuilt the installation's server ID but not the
installation, so AgentTimeline in a modal threw "Plugin host UI must render
inside a plugin surface". The bridge now rebuilds every installation context
from the same function the provider uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Gringauz
2026-12-02 11:36:55 +00:00
co-authored by Claude Opus 5.5
parent cd29c7ac6d
commit fd29216a04
3 changed files with 40 additions and 22 deletions
@@ -31,16 +31,28 @@ export function usePluginInstallationServerId(): string | undefined {
return useContext(PluginInstallationServerIdContext);
}
/** Rebuilds the plugin installation's host server ID across React Native portals. */
export function usePluginInstallationServerIdBridge() {
const serverId = usePluginInstallationServerId();
return useCallback(
(children: ReactNode) => (
/** Every installation context host UI reads. The portal bridge rebuilds all of them from here. */
function provideInstallation(
plugin: InstalledPlugin | null,
serverId: string | undefined,
children: ReactNode,
) {
return (
<PluginInstallationContext.Provider value={plugin}>
<PluginInstallationServerIdContext.Provider value={serverId}>
{children}
</PluginInstallationServerIdContext.Provider>
),
[serverId],
</PluginInstallationContext.Provider>
);
}
/** Rebuilds the plugin installation and its host server ID across React Native portals. */
export function usePluginInstallationBridge() {
const plugin = useContext(PluginInstallationContext);
const serverId = usePluginInstallationServerId();
return useCallback(
(children: ReactNode) => provideInstallation(plugin, serverId, children),
[plugin, serverId],
);
}
@@ -52,13 +64,7 @@ function InstallationContexts({
plugin: InstalledPlugin;
children: ReactNode;
}) {
return (
<PluginInstallationContext.Provider value={plugin}>
<PluginInstallationServerIdContext.Provider value={plugin.serverId}>
{children}
</PluginInstallationServerIdContext.Provider>
</PluginInstallationContext.Provider>
);
return provideInstallation(plugin, plugin.serverId, children);
}
/** Where the handle hooks, such as `useComposer` and `useWorkspaceLayout`, get their handles. */
@@ -21,7 +21,8 @@ import {
import { seedSessionHosts } from "@/test/seed-session";
import {
PluginInstallationProvider,
usePluginInstallationServerIdBridge,
usePluginInstallation,
usePluginInstallationBridge,
} from "../installation-provider";
import type { InstalledPlugin } from "../types";
import { Markdown } from "./markdown";
@@ -302,11 +303,11 @@ describe("plugin Markdown local images", () => {
let capturedBridge: ((children: ReactNode) => ReactNode) | null = null;
function CaptureBridge() {
const bridgeServerId = usePluginInstallationServerIdBridge();
const bridgeInstallation = usePluginInstallationBridge();
const bridgeFileLinks = useAssistantFileLinkEnvironmentBridge();
capturedBridge = (children) => (
<QueryClientProvider client={plugin.queryClient}>
{bridgeFileLinks(bridgeServerId(children))}
{bridgeFileLinks(bridgeInstallation(children))}
</QueryClientProvider>
);
return null;
@@ -322,11 +323,22 @@ describe("plugin Markdown local images", () => {
const portalHost = document.createElement("div");
document.body.append(portalHost);
function InstallationProbe() {
return <span data-testid="installation">{usePluginInstallation().id}</span>;
}
const portal = render(
<>{bridge(<Markdown>{"![ModalShot](/tmp/screenshots/modal.png)"}</Markdown>)}</>,
<>
{bridge(
<>
<InstallationProbe />
<Markdown>{"![ModalShot](/tmp/screenshots/modal.png)"}</Markdown>
</>,
)}
</>,
{ container: portalHost },
);
try {
expect(portalHost.querySelector('[data-testid="installation"]')?.textContent).toBe(plugin.id);
await expectLoadedImage(portalHost, "ModalShot", "blob:");
expect(host.reads).toEqual([{ cwd: "/", path: "/tmp/screenshots/modal.png" }]);
} finally {
@@ -4,7 +4,7 @@ import { usePluginRuntimeContextBridge } from "@getpaseo/plugin/client/host";
import { createContext, useCallback, useContext, useMemo, useRef, type ReactNode } from "react";
import { useAssistantFileLinkEnvironmentBridge } from "@/assistant-file-links";
import { ToastApiProvider, useToast as useAppToast } from "@/contexts/toast-api-context";
import { usePluginInstallationServerIdBridge } from "../installation-provider";
import { usePluginInstallationBridge } from "../installation-provider";
interface ModalContextValue {
open: boolean;
@@ -42,17 +42,17 @@ function ModalContent({
const queryClient = useQueryClient();
const toast = useAppToast();
const bridgePluginRuntime = usePluginRuntimeContextBridge();
const bridgePluginServerId = usePluginInstallationServerIdBridge();
const bridgePluginInstallation = usePluginInstallationBridge();
const bridgeFileLinkEnvironment = useAssistantFileLinkEnvironmentBridge();
const contextBridge = useCallback(
(content: ReactNode) => (
<QueryClientProvider client={queryClient}>
<ToastApiProvider api={toast}>
{bridgeFileLinkEnvironment(bridgePluginServerId(bridgePluginRuntime(content)))}
{bridgeFileLinkEnvironment(bridgePluginInstallation(bridgePluginRuntime(content)))}
</ToastApiProvider>
</QueryClientProvider>
),
[bridgeFileLinkEnvironment, bridgePluginRuntime, bridgePluginServerId, queryClient, toast],
[bridgeFileLinkEnvironment, bridgePluginInstallation, bridgePluginRuntime, queryClient, toast],
);
const { AdaptiveModalSheet } =
require("../../components/adaptive-modal-sheet") as typeof import("../../components/adaptive-modal-sheet");