Skip to content

feat(vue): guarantee script order and failure behaviour (#145) - #651

Merged
JuroOravec merged 7 commits into
mainfrom
feat/145-script-order
Nov 14, 2026
Merged

JuroOravec merged 7 commits into
mainfrom
feat/145-script-order

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Closes #145. Implements the design in docs/design/script_order.md (#630) for 0.9.0.

What changes

  • Component scripts report whether they ran to their end. The server wraps each component's own js in a try that calls __citryRuntime.finishScript(key). A component script that throws or fails to parse now keeps the Vue app from starting (or fails the server render that loaded it). The error names the component and carries the original error as cause, and reportError passes the original error to the page's error event. The manifest gains an optional finishKey on those script entries. Python and the browser both validate it.
  • A third-party script that fails to load is skipped. On a mounted page, a script that is listed by URL, is not declared to register options, and comes from another origin is skipped with a console warning when it fails to load (blocked, failed integrity check, or network error). Owned and same-origin scripts still stop startup. A skipped file keeps no record, so a later server render or fragment tries it again. Within one startup or server render it is requested only once.
  • onServerRender has one order. On the first mount and after a server render, callbacks run children before their parent, and siblings in the order they first mounted. Citry numbers instances in its mounted wrapper and follows $parent links; it does not read Vue's internals. A callback that throws stops the rest of that pass and stops the app. First-mount callbacks now run from one ordered queue. A component that an earlier callback removed gets no callback. A component that a callback shows gets its callback after the rest.
  • Browser plugin scripts run before component scripts on standalone pages too.
  • runtime.js was rebuilt from client.js with buildCitryVueRuntime. The render snapshots were regenerated; the only differences are finishKey fields and bundle digests.
  • Docs: a new "When scripts run" and "When a script fails" on the Component JS and CSS page, plus notes in component options, browser APIs, dependency files and extensions. The changelog lists upgrade notes under Unreleased. The design doc is marked built, and a new section lists how the code differs from the text.

Where the code differs from the design

  • Component script results are kept per page, not per app, because a component script runs once per page and a fragment reuses it.
  • A component script with wrap=False, or with a type that has parameters (which Script does not wrap), gets no try and no finishKey, so a throw there does not stop the app.
  • A component shown by a callback during a server render's callbacks now gets its callback; before this change it got none.
  • A callback that fails after startup (a browser-only v-if) now logs and stops the app.

Tests

  • JS: test/script-order.test.mjs (26 tests) covers finishScript, finishKey validation, isThirdPartyScript (including <base>, protocol-relative and null-origin pages), callback order and the failure rule.
  • Python: tests for the finishKey emission and validation, the wrap condition, and plugin script placement on both page kinds.
  • E2E: test_script_order_e2e.py and test_callback_order_e2e.py. They cover plugin order, throw and parse failures before and after $component, a throwing Dependencies file, third-party versus same-origin load failures, retry by a later fragment, a request sent once at startup and in a server render, callback order (siblings, slot fill, loop, hydrated and client-rendered), order after a server render with the response reversed, a new sibling and reordered keyed rows, components removed or shown by callbacks, and throws on first mount, after a server render and after startup. They pass on Chromium, Firefox and WebKit.
  • Three existing e2e tests that copy a component script entry and give it an external source now drop finishKey.

Locally the canary "runtime matches its source build" fails only because the installed Vue is 3.5.42 while the repo pins 3.5.44. buildCitryVueRuntime output equals the committed runtime.js. A few local failures (old citry_core binary, WebKit charset tests) also fail on main.

Review

An independent technical review (Mechanism 6) and a re-review of the fixes. Docs had a cold read and a prose pass. Every finding was folded in.

Security (Mechanism 7)

These are the places from the Mechanism 7 list in CLAUDE.md that this PR touches. Each was checked by an independent reviewer, and none has a hole:

  • JavaScript and JSON. The component script text now has Citry's try wrapper, and the manifest JSON gains finishKey. The wrapper text is Citry's own and holds no </script, <!-- or -->. finishKey must be 64 hex characters, on a component entry with an owned source, and both Python and the browser check this. It is written through the existing JSON escaping. Safe.
  • Addresses and keys the browser code takes from the server. These are the URLs of the scripts the runtime loads, and the new origin check that decides whether a failed script is skipped. The URLs come from the app author (author-only by design). The origin check resolves against the page's own address, so a <base> element cannot change the decision. It skips only a script that the browser already refused to load, never an owned script, one that registers options, or one with a finishKey. Finish results are kept in a Map, so __proto__ reaches only its own entry. Safe. The trade-off is accepted: a page runs without a skipped cross-origin file. The docs say to serve safeguards such as consent managers from the page's own origin.
  • Element id and name. The origin check reads document.URL through the runtime's clobber-safe document wrapper. <img name="URL"> cannot replace it, and a value that does not parse counts as the page's own origin, so it fails closed. Safe.
  • Markers for Citry's browser code. Only finishScript writes a finish record, and it checks the key. Page code that forges a record only hides its own component's failure. Safe.
  • The CSP nonce. The reordered plugin scripts and the wrapped inline component scripts on a standalone page, scripts the runtime adds on a mounted page, and fragments all get the nonce exactly as before. Integrity and CSP hashes cover the final wrapped bytes. The reviewer checked this in Chromium under real CSP headers: nonce only, hash only, and strict-dynamic, with and without a throwing component. Safe.
  • The opt-in output checks (security_javascript, security_csp, a JavaScript policy). They decide from script attributes, which the wrapper does not change, and on a standalone page they also see the wrapped bytes. Warn, forbid and omit give the same results as on main. An omitted script leaves no finishKey. Safe.
  • Responses Citry serves. The new error and warning text goes only to the console and the window's error event, never into page HTML. Safe.

Mechanism 8: the reviewer read the advisory survey and checked the change against script-load, dom-clobber, proto, ssr-serialize, template-inj, error-page, log-inj, sanitizer-bypass, cache-key, redos and source-exposure. The change introduces none of them.

Open: the measurement in design item 7 is not part of this PR. Two citry_ui runtime scripts (CSplitButton, CContextMenu) throw at top level when a dependency is missing. They now stop the app, but their dependencies are app-owned files that would already stop it.

🤖 Generated with Claude Code

JuroOravec and others added 6 commits November 14, 2026 15:11
Component scripts report whether they ran to their end, a third-party
script that fails to load is skipped, onServerRender callbacks run in one
order after the first mount and after a server render, and browser plugin
scripts run before component scripts on standalone pages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Skip callbacks of components that an earlier callback unmounted, request a
skipped third-party file once per startup or server render, report a
callback failure after startup, wrap only scripts Citry put in a function,
check finishKey after the source, and rewrite the docs for clarity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…callbacks (#145)

Also mark the app started where startup last checks it, skip a repeated
file only when it is third-party, name a failed load in the unfinished
script error, and check finishKey after the source on the server too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The script order tests and the fragment nonce e2e helpers found script
elements with a regular expression that missed upper-case tags and a
closing tag such as `</script >`. They now use html.parser, which reads
script text the way a browser does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 559d59e into main Nov 14, 2026
1 of 15 checks passed
@JuroOravec
JuroOravec deleted the feat/145-script-order branch November 14, 2026 14:23
JuroOravec added a commit that referenced this pull request Nov 14, 2026
…erverRender

Since #651, Citry runs onServerRender callbacks after a server render with
children before their parent, after every cleanup has run. Several Citry UI
components relied on the parent's callback running first:

- CDatePicker, CDateRange and CTimePicker un-enhanced their control in the
  cleanup, which hid the trigger of their CPopover, so the popover's earlier
  callback force-closed it. Their cleanup now keeps the control enhanced on a
  server-render handoff, and the popup stays closed while the server has just
  disabled the picker and the picker has not run yet.
- An open CPopover hid its surface in the cleanup, so a layer nested inside it
  closed. It now stays showing and registered until its next run takes it over.
- CAccordion applied item state before detecting removed items, so it skipped
  the removal report and the focus fallback. It reconciles the items first.
- A CDialog, CDrawer or CCommandPalette opened inside a dialog that the same
  render opens now waits until that dialog is modal, so it opens on top. CDrawer
  watches every ancestor's attributes, and the palette joins the shared dialog
  list, so closing the outer one closes them.

The JavaScript asset budgets rise to fit the added code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec added a commit that referenced this pull request Nov 14, 2026
…erverRender (#675)

Since #651, Citry runs onServerRender callbacks after a server render with
children before their parent, after every cleanup has run. Several Citry UI
components relied on the parent's callback running first:

- CDatePicker, CDateRange and CTimePicker un-enhanced their control in the
  cleanup, which hid the trigger of their CPopover, so the popover's earlier
  callback force-closed it. Their cleanup now keeps the control enhanced on a
  server-render handoff, and the popup stays closed while the server has just
  disabled the picker and the picker has not run yet.
- An open CPopover hid its surface in the cleanup, so a layer nested inside it
  closed. It now stays showing and registered until its next run takes it over.
- CAccordion applied item state before detecting removed items, so it skipped
  the removal report and the focus fallback. It reconciles the items first.
- A CDialog, CDrawer or CCommandPalette opened inside a dialog that the same
  render opens now waits until that dialog is modal, so it opens on top. CDrawer
  watches every ancestor's attributes, and the palette joins the shared dialog
  list, so closing the outer one closes them.

The JavaScript asset budgets rise to fit the added code.

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

Decide component-script execution-order guarantees and dependency APIs

2 participants