Skip to content

Fragment links: linkable app state and link manifests - #44

Merged
simonw merged 5 commits into
mainfrom
fragment-links
Nov 15, 2026
Merged

simonw merged 5 commits into
mainfrom
fragment-links

Conversation

@simonw

@simonw simonw commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Lets an app keep its view state in the URL fragment, and advertise which fragments it supports so other apps and datasette-agent can link to them.

What this adds

  • Fragment sync. The bridge mirrors the sandboxed iframe's location.hash to the page URL and back, so app views can be bookmarked, shared and stepped through with the back button. Ordinary <a href="#/customer/42"> links work inside the sandbox.
  • history.pushState() / history.replaceState() now work with a fragment-only URL. replaceState() replaces the current history entry rather than adding one.
  • Link manifest. An app declares its linkable views in its own HTML:
    <script type="application/json" id="datasette-app-links">
    [{"template": "#/customer/{id}", "description": "Detail view for one customer",
      "params": {"id": {"column": "sales/customers/id"}}}]
    </script>
    The manifest is extracted into a new app_links table on every HTML save, with a backfill for existing apps. External apps supply the same list as metadata["links"].
  • Agent tooling. New app_links tool lists advertised links for apps the user can view, filterable by database/table. app_create and the edit tools report what the manifest advertises and any errors in it. app_debug takes a hash argument. Referenced apps list their linkable views in the agent context.
  • Cross-app links. A click on a same-origin link inside an app navigates directly instead of showing the external-link confirmation modal.

Notes for review

  • Manifest text is untrusted. Descriptions are length-capped and collapsed to a single line; templates containing whitespace or control characters are rejected.
  • replaceState() uses location.replace("about:srcdoc#..."). This is covered by Playwright tests in Chromium and was also run in WebKit. It has not been checked in Firefox - Playwright's Firefox would not launch on the development machine. The new path is only taken when the document URL is exactly about:srcdoc.
  • Known and left as is: after the user edits the page fragment by hand, the back button needs two presses to leave that state.

Tests

275 unit tests and 21 Playwright tests pass locally.

🤖 Generated with Claude Code

simonw and others added 5 commits November 14, 2026 17:02
Apps keep view state in the URL fragment, mirrored between the sandboxed
iframe and the page URL. An app advertises its linkable views with a
datasette-app-links JSON manifest, extracted into a new app_links table
on every save. Adds the app_links agent tool, a hash option for
app_debug, and direct navigation for same-origin links between apps.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Manifest descriptions are shown to models in line-based lists, so a
newline could forge what looks like a separate entry. Collapse
whitespace in descriptions and reject templates containing whitespace
or control characters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The shim routed replaceState through the location.hash setter, which
always adds a history entry, so an app keeping a search box in the
fragment added a back button step per keystroke. Use location.replace()
with the srcdoc document's own absolute URL, which is a fragment
navigation that replaces the current entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1.0a42 renders menu links with role="menuitem", so the exact-string
assertion failed and the anonymous-user check could no longer fail.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@simonw
simonw merged commit cd48e22 into main Nov 15, 2026
16 checks passed
simonw added a commit that referenced this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant