diff --git a/.github/scripts/ci/fixtures/remote-ui-browser.sh b/.github/scripts/ci/fixtures/remote-ui-browser.sh new file mode 100644 index 000000000..b43fa0b31 --- /dev/null +++ b/.github/scripts/ci/fixtures/remote-ui-browser.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Install the locked platform and fixture dependencies and Chromium, then check remote rendering +# over the real frame transport. The fixture keeps its own package.json and lockfile. +set -euo pipefail + +report=${1:?Expected an absolute report path} +fixture=web/src/tests/fixtures/remote-ui-browser + +bun install --no-env-file --frozen-lockfile --ignore-scripts +( + cd "$fixture" + bun install --no-env-file --frozen-lockfile + node node_modules/@playwright/test/cli.js install --only-shell chromium + shell=$(find "$HOME/.cache/ms-playwright" -type f \( -name chrome-headless-shell -o -name headless_shell \) -print -quit) + if [ -z "$shell" ] || ldd "$shell" | grep -q 'not found'; then + node node_modules/@playwright/test/cli.js install-deps chromium + fi +) +bun --no-env-file "$fixture/browser.mts" "$report" diff --git a/.github/workflows/app-runtime-reference.yml b/.github/workflows/app-runtime-reference.yml index ab89b9483..c1541d20f 100644 --- a/.github/workflows/app-runtime-reference.yml +++ b/.github/workflows/app-runtime-reference.yml @@ -220,3 +220,48 @@ jobs: ${{ runner.temp }}/app-runtime-reference/greeting-grants.json ${{ runner.temp }}/app-runtime-reference/greeting-recovery.json ${{ runner.temp }}/app-runtime-reference/greeting-offline-restore.json + + remote-ui: + name: Remote UI browser fixture + needs: changes + if: ${{ !cancelled() }} + runs-on: ubuntu-24.04 + timeout-minutes: 20 + env: + # The platform's renderer, its shared components and the fixture are web inputs. + RUN_CHECK: ${{ needs.changes.outputs.web != 'false' }} + steps: + - name: Require successful change detection + env: + CHANGE_RESULT: ${{ needs.changes.result }} + run: test "$CHANGE_RESULT" = success + + - name: Report unaffected check + if: env.RUN_CHECK != 'true' + run: echo 'No web input changed; this check does not need to run.' + + - name: Check out exact tested commit + if: env.RUN_CHECK == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ github.sha }} + + - name: Set up Bun + if: env.RUN_CHECK == 'true' + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + with: + bun-version: 1.4.5 + + - name: Verify remote rendering over the real frame transport + if: env.RUN_CHECK == 'true' + run: bash .github/scripts/ci/fixtures/remote-ui-browser.sh "$RUNNER_TEMP/remote-ui-browser.json" + + - name: Upload browser evidence + if: env.RUN_CHECK == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: remote-ui-browser-${{ github.run_attempt }} + if-no-files-found: error + retention-days: 14 + path: ${{ runner.temp }}/remote-ui-browser.json diff --git a/web/src/features/AppUi/AppUiFrame.tsx b/web/src/features/AppUi/AppUiFrame.tsx index 787845169..412232bf8 100644 --- a/web/src/features/AppUi/AppUiFrame.tsx +++ b/web/src/features/AppUi/AppUiFrame.tsx @@ -1,27 +1,16 @@ -import { toast } from '@rentnerkev/toasts' -import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from 'react' +import { useEffect, useEffectEvent, useState } from 'react' -import { - appUiDefaultRoute, - type AppUiDialogRequest, - type AppUiRendering, - type AppUiToast, -} from '@/lib/AppUi/bridge.ts' +import { appUiDefaultRoute } from '@/lib/AppUi/bridge.ts' import type { AppUiSlot, AppUiSummary } from '@/lib/AppUi/contract.ts' import { APP_UI_PREFIX } from '@/lib/AppUi/paths.ts' -import { createRemoteUiStore, type RemoteUiEvent } from '@/lib/AppUi/remote-tree.ts' -import { - bindAppUiFrame, - supportsRemoteRendering, - type AppUiRemoteEventDetail, - type AppUiRevocation, -} from '@/lib/AppUi/session.ts' +import type { AppUiRevocation } from '@/lib/AppUi/session.ts' import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { ModalActionButton } from '@/shared/Modal/Components/ModalActions.tsx' import { useAppUi } from './AppUiProvider.tsx' import { callAppUi } from '@/lib/AppUi/client.ts' import { openAppUiHandler } from './middleware.ts' -import RemoteAppView from './Components/RemoteAppView/index.tsx' +import AppFrameView from './Components/AppFrameView.tsx' +import type { AppFrameSource as OpenedSource } from './Types/app-frame-view.types.ts' type FrameProps = { app: AppUiSummary @@ -33,12 +22,7 @@ type FrameProps = { fill?: boolean | undefined } -type AppFrameSource = { nonce: string; url: string; frameToken: string } - -/** A toast an app asked for, always titled with the app's name so it never looks like the platform's. */ -function showAppToast(appName: string, { tone, heading, text }: AppUiToast) { - toast[tone](text, { title: heading ? `${appName} · ${heading}` : appName }) -} +type AppFrameSource = OpenedSource & { frameToken: string } export default function AppUiFrame({ app, slot, hostId, route, onNavigate, fill }: FrameProps) { const sessionId = useAppUi()?.sessionId @@ -182,57 +166,18 @@ function OpenedAppFrame({ onDisconnect: (reason: Exclude) => void }) { const ui = useAppUi() - const { t, locale } = useTranslationStore() - const theme = ui?.theme ?? 'light' - const iframe = useRef(null) - const bridge = useRef | null>(null) - // An app that may draw remotely shows nothing until its handshake says how it renders. - const [rendering, setRendering] = useState(() => - supportsRemoteRendering(app) ? 'pending' : 'frame', - ) - const [remoteTree] = useState(createRemoteUiStore) - const currentContext = useEffectEvent(() => ({ - theme, - locale, - route, - permissionKeys: app.permissionKeys, - })) - // Keys match the manifest pattern, so the joined list changes exactly when the keys do. - const permissionScope = app.permissionKeys.join(' ') - const navigate = useEffectEvent(onNavigate) - const dialog = useEffectEvent( - (request: AppUiDialogRequest, settle: (outcome: 'confirmed' | 'cancelled') => void) => { - ui?.openDialog({ - appName: app.name, - dialogId: request.dialogId, - mount: source.nonce, - settle, - }) - }, - ) - const revoke = useEffectEvent((reason: AppUiRevocation) => { - ui?.cancelDialog(source.nonce) - if (reason !== 'unmounted') onDisconnect(reason) - }) - - const onRemoteEvent = useCallback( - (node: string, event: RemoteUiEvent, detail: AppUiRemoteEventDetail) => - bridge.current?.sendRemoteEvent(node, event, detail), - [], - ) - - const bind = useEffectEvent((element: HTMLIFrameElement) => - bindAppUiFrame(element, source.nonce, app, { - onConnected: (mode) => { - setRendering(mode) - return currentContext() - }, - onRemoteMutate: (records) => remoteTree.apply(records), - onToast: (message) => showAppToast(app.name, message), - onNavigate: (target) => navigate(target), - onDialog: (request, settle) => dialog(request, settle), - onRevoked: (reason) => revoke(reason), - onApiRequest: ({ requestId, operationId, idempotencyKey, payload }, signal) => + // Operations go through the gateway with this frame's token; dialogs open in the platform. + return ( + callAppUi({ data: { installationId: app.installationId, @@ -244,50 +189,17 @@ function OpenedAppFrame({ payload, }, signal, - }), - }), - ) - - useLayoutEffect(() => { - const element = iframe.current - if (!element) return - const session = bind(element) - bridge.current = session - return () => { - bridge.current = null - session.close() - } - }, []) - - // The inventory poll updates the user's keys while the frame stays open. - useEffect(() => { - const permissionKeys = permissionScope === '' ? [] : permissionScope.split(' ') - bridge.current?.sendContext({ theme, locale, route, permissionKeys }) - }, [locale, permissionScope, route, theme]) - - // A remotely drawn app keeps running in its hidden frame, which never takes focus. - return ( - <> -