Skip to content

fix(artifacts): preserve host-shell embed contract across in-viewer artifact links - #5238

Merged
stamp-build[bot] merged 2 commits into
mainfrom
agent/reef/artifact-viewer-embed-contract-preservation
Nov 21, 2026
Merged

stamp-build[bot] merged 2 commits into
mainfrom
agent/reef/artifact-viewer-embed-contract-preservation

Conversation

@stamp-build

@stamp-build stamp-build Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Reef from raft opened this pull request through Stamp
View in Stamp →


Summary

Fixes #wg-mobile-feedback:#256 (Artifact viewer losing the host-shell embed contract after opening another Artifact from an in-page link such as Linked from › Documents, then breaking Desktop Mode / one-bar / hostOpen=message across subsequent Artifact opens).

Root cause

  1. Tapping a document backlink (ArtifactBacklinksList.tsx:137 <a href="/artifacts/<otherId>">) inside ArtifactStandalonePage triggers a full-document navigation to /artifacts/<otherId> with no ?embed=raft-settings-v1&shell=host&back=host&hostMenu=...&hostOpen=message&hostConversation=... query params.
  2. raftArtifactViewerRoutesDocumentAsLink previously returned false for OpenArtifact (and iOS RaftIosSandboxWebView.decideNavigationPolicy did not invoke events.routesMainFrameNavigation), allowing the WebView to replace its embedded document with an un-embedded full page load.
  3. With conversationId != null, onAddress matched raftArtifactViewerSwitchesInPlace and falsely recorded that un-embedded WebView in RaftArtifactViewerMemory keep-alive. Because slock embed.ts latches NOT_EMBEDDED synchronously on document boot, subsequent opens reusing that keep-alive WebView via history.pushState rendered with isHostShell() === false — causing stacked native + web headers, desktop-width ArtifactDetailsTitle on phones in Desktop Mode, and Original message closing the viewer instead of opening over via #host=open&to=.
  4. Separately, LaunchedEffect(pendingHostAction) wrote the pre-toggle hostDesktop value to the address right before toggleDesktopMode("page") triggered Android's updateUseWideViewPort reload.

Changes

  • Intercept full-document Artifact links before load (RaftArtifactViewer.kt):
    • Added raftArtifactViewerHasEmbedContract(url), raftArtifactViewerKeptDocumentHasEmbedContract(kept), and raftArtifactViewerHostDesktopAfterAction(action, current).
    • Updated raftArtifactViewerRoutesDocumentAsLink to return true for full-document navigations to another Artifact (OpenArtifact) and un-embedded full reloads of the same Artifact (Stay && !raftArtifactViewerHasEmbedContract(url)), while leaving embedded same-Artifact loads, warm route, sign-out (/, /login), and post-delete (/s/<slug>) untouched. Client-side SPA switches (history.pushState) never enter routesMainFrameNavigation.
  • iOS symmetry (RaftSandboxWebView.ios.kt):
    • Wired events.routesMainFrameNavigation inside RaftIosSandboxWebView.decideNavigationPolicy matching Android's shouldRouteMainFrameNavigation.
  • Defense in depth + Desktop Mode toggle sync (RaftArtifactViewerPage.kt):
    • Drop keep-alive WebViews lacking the embed contract on reuse or dispose, and align RaftArtifactViewerMemory metadata on dispose when stacked Artifact viewers unwind.
    • Route intercepted OpenArtifact in inColumn via openRaftArtifactViewerPage (matching Left), and handle un-embedded same-Artifact version links via in-place SPA navigation.
    • Pass toggled nextHostDesktop to raftArtifactViewerHostDesktopScript before currentOnHostAction triggers Android's Desktop Mode reload.
  • Tests & changeset:
    • Added/updated regression tests in RaftArtifactViewerEmbedTest.kt, RaftArtifactViewerCacheTest.kt, RaftAndroidArtifactViewerWebViewRulesTest.kt, and RaftSandboxWebViewNavigationFenceIosTest.kt.
    • Added change-logs/1.28.0/changesets/artifact-viewer-preserve-embed-contract.md.

Upstream note (web)

botiverse/slock packages/web/src/apps/artifacts/embed.ts and ArtifactBacklinksList.tsx were checked against local slock HEAD; mobile now guards the embed contract independently of whether web backlinks trigger a hard <a href> navigation.

Reef added 2 commits November 21, 2026 09:50
…rtifact links

- Intercept full-document top-level navigations to other Artifacts (e.g. bare
  <a href="/artifacts/..."> in Linked from -> Documents) and un-embedded
  same-Artifact reloads in raftArtifactViewerRoutesDocumentAsLink so the
  WebView never loads an un-embedded document that latches NOT_EMBEDDED for
  the lifetime of the page and poisons keep-alive across subsequent opens.
- Wire events.routesMainFrameNavigation symmetrically in iOS
  RaftIosSandboxWebView.decideNavigationPolicy (matching Android).
- Add defense-in-depth embed-contract validation when reusing or parking a
  keep-alive WebView, and align cache metadata on dispose when stacked
  Artifact viewers unwind.
- Compute toggled hostDesktop before running raftArtifactViewerHostDesktopScript
  on #host=desktop-mode so Android reloads with the updated hostDesktop value.
- Add common, Android, and iOS regression tests plus 1.28.0 changeset.
@stamp-build stamp-build Bot added the full-ci label Nov 21, 2026
@stamp-build
stamp-build Bot merged commit fedb7a8 into main Nov 21, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants