Skip to content

feat: serve the browser runtimes from content-hashed URLs (#578) - #652

Merged
JuroOravec merged 4 commits into
mainfrom
feat/runtime-hashed-urls
Nov 14, 2026
Merged

JuroOravec merged 4 commits into
mainfrom
feat/runtime-hashed-urls

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Closes #578. Design: docs/design/runtime_hashed_urls.md (merged as #627, updated here to match the code). Targets Citry 0.9.0.

Scope. This PR serves the browser runtimes from content-hashed URLs. Automatic recovery for a page whose runtime is gone after a deploy (a reload once, done safely) is left for after 1.0.0 in #665.

What changes

  • Hashed runtime URLs. Pages link Citry's browser runtimes by a URL that holds a hash of the file (/citry/citry.<sha256>.js, /citry/ext/i18n/runtime.<sha256>.js), served with immutable caching. The browser keeps the files between page loads instead of downloading them on every page. The stable URLs (citry.js, ext/events/runtime.js, ext/i18n/runtime.js) keep working with no-store. Citry.runtime_url() is new, for pages written by hand.
  • Old runtimes after a deploy. With a cache backend set, workers store each runtime there for 30 days and serve an old hash from it. A hash nobody holds answers 404 with no-store and Access-Control-Allow-Origin: *, so the console shows the 404 rather than a CORS error.
  • A missing runtime is reported clearly. On a mounted page, the start script calls startDocument when the runtime loaded. Otherwise it writes one console.error("Citry could not load its runtime: <url>") and keeps the server HTML. It sends no request and has one form, so its CSP hash depends only on the app id and the runtime URL. A missing browser plugin keeps the runtime's existing error. The fragment loader reports a failed runtime the same way.
  • 404s for missing Events definitions or stylesheets, and for unmatched paths under the ASGI/WSGI apps, send no-store.
  • Docs, the Events spec, the design docs, the changelog (top ## Unreleased), the docs site builder (hashed runtime in snapshots, shared to the root), the playground and Citry UI quality routes, and the starters' tests all follow. client.js, runtime.js, serialize.py and citry_render.py are unchanged from main.

Checks

  • Focused Python suites: 547 passed. One failure, test_i18n_client.py::test_javascript_delivery_policy_sees_client_i18n_and_can_omit_it, fails the same way on a clean main checkout here, because the local citry_core binary is older than main.
  • Browser tests (test_runtime_hashed_urls_e2e.py, test_fragment_e2e.py, test_base_element_e2e.py) on Chromium, Firefox and WebKit: 58 passed, 2 skipped (the prerender case runs on Chromium only).
  • ruff clean. mypy clean on the touched modules, also with --platform linux. docs build-check: 0 errors. Its 4 anchor warnings (#when-a-script-fails, #when-scripts-run) come from feat(vue): guarantee script order and failure behaviour (#145) #651, not this PR.
  • Not run locally: the full repository gate and Biome.

Review

Two independent reviews found no security hole. The runtime URL in <script src>, the preload hint, the start script and the fragment loader, Citry.runtime_url(), the digest in the path, the shared-cache entry and the CORS 404 are all safe, or limited to values the app author sets (the mount prefix). Fixed from the reviews: a leftover sentence about a reload check in the design doc, a stale reason for the CORS header in the spec, troubleshooting matching on Uncaught Error, the dropped citry.js 404 row, the stale-citry.js cases, and the changelog and docs wording. A separate prose pass was folded in.

Left for the maintainer

🤖 Generated with Claude Code

JuroOravec and others added 3 commits November 14, 2026 16:20
Pages now link Citry's shared runtime as <prefix>/citry.<sha256>.js and the
i18n runtime as <prefix>/ext/i18n/runtime.<sha256>.js. Both answer with an
immutable one-year Cache-Control, so the browser keeps them between page
loads, and a page always loads the runtime it was rendered for. The stable
URLs (citry.js, ext/events/runtime.js, ext/i18n/runtime.js) keep serving the
current bytes with no-store.

- New private module citry/_hashed_runtime.py serves both runtimes; with
  CitrySettings.cache set, a process that links a hashed URL writes the bytes
  to the shared cache for 30 days, and a worker serves a stored copy only
  when its SHA-256 matches the URL.
- Citry.runtime_url() returns the hashed shared-runtime URL for hand-written
  pages.
- serialize()/serialize_result() take request_method. Only a page that
  answers GET or HEAD reloads once when its runtime is missing; the start
  script and the runtime (for a missing browser plugin) apply the rule.
- Every runtime and Events asset 404 sends no-store (and CORS), and the
  ASGI/WSGI adapters' unmatched-path 404 sends no-store.
- Static export, docs-site snapshot assembly, the playground, and the
  citry_ui quality harness know the hashed URLs.
- Design doc docs/design/runtime_hashed_urls.md, spec, design docs, user
  docs and changelog updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#578)

The maintainer narrowed #578 to the content-hashed runtime URLs. Automatic
recovery of a page whose runtime is gone after a deploy is tracked for
after 1.0.0 in #665.

- A mounted page's start script now calls startDocument when the runtime
  loaded, and otherwise writes one console.error naming the runtime URL
  and keeps the server HTML. It sends no request and has one form.
- No request_method keyword, canReload value, manifest scriptUrl, HEAD
  request, location.reload() or session-storage key. client.js,
  runtime.js, _vue/events.py, serialize.py and citry_render.py match main.
- Tests, design docs, the spec, user docs and the changelog follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the feat/runtime-hashed-urls branch from df34fea to 5899d4c Compare November 14, 2026 15:22
@JuroOravec
JuroOravec merged commit 469b548 into main Nov 14, 2026
22 of 32 checks passed
@JuroOravec
JuroOravec deleted the feat/runtime-hashed-urls branch November 14, 2026 16:22
JuroOravec added a commit that referenced this pull request Nov 14, 2026
…ight merged changes (#682)

Add one record under docs/security/reviews/ for each of the eight published
0.8.0 advisories (GHSA-4hj5, -8xvf, -7qpw, -g658, -x6rm, -h524, -xmx5,
-xg8c) and for each of the pull requests that Mechanism 7, step 7 owes one:
#610, #640, #651, #652, #653, #658, #674 and #675. Each record says only what
the public pull request, the published advisory, the merged code and its tests
show, and lists what was not checked.

The reviews README describes how a record for a published advisory differs
from a pull request record. The Mechanism 7 list in CLAUDE.md gains the two
places that GHSA-7qpw added: parser rules browsers differ on, and the page's
declared encoding.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Serve the Events and i18n runtimes from a content-hashed URL

1 participant