Skip to content

fix(i18n): give cached $c-tr bindings fresh IDs and definitions on replay - #658

Merged
JuroOravec merged 1 commit into
mainfrom
fix/631-cache-i18n-binding
Nov 14, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/631-cache-i18n-binding

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

What was wrong

A $c-tr binding ID is built from the render ID of the component whose
template contains the element. When that component is outside the cached
output, the cache entry kept the first render's ID and had no definition
for it. This happens with a <c-cache> fragment inside a page template
and with slot content that a caller passes to a cached component. A
render that was served from the cache then sent the browser an ID the
page never defined. The browser threw binding ... is not active, and
the Vue app did not start.

What this changes

  • Export asks the render cache which binding IDs the stored parts name.
    It copies the bindings (and the data-citry-i18n-binding values that
    list them) of components outside the entry into the record of the cache
    boundary. Replay renames them to fresh IDs like any binding written
    inside the entry, so the page gets one definition for each ID its HTML
    names.
  • New field OnRenderCacheExportContext.browser_binding_operands: the
    string operand of every browser binding in the stored parts, grouped by
    helper name. It has a default, so existing extensions keep working.
  • Export refuses an entry (the part is not stored) when a stored part
    names an ID that no record holds, when one marker lists some IDs the
    stored parts use and some they do not, or when the boundary has no
    record to hold the outside bindings.
  • Replay skips an entry (the part renders again) when a binding ID does
    not look like <render ID>~i18n-<number> (the number is at most 9
    digits), when an ID repeats in one record, or when a binding belongs to
    a client provider outside the entry and the replaying render has none.
    Before, the last case failed the request.
  • docs/design/i18n.md and docs/design/caching.md describe the new
    payload content and the refusals.
  • CHANGELOG.md has an entry under Unreleased, Fixes.

Tests

  • tests/test_i18n_cache.py (44 tests): a fragment with text and
    attribute bindings, a component cache with a caller's fill, a fragment
    at the root of a child template, a provider inside the fragment, nested
    fragments (outer miss with inner hit stores the outer entry), the same
    key used twice, a fragment per loop item, a fragment inside a fill
    passed to another component, a boundary with its own binding plus a
    caller's fill binding, an entry made under an outside provider and
    replayed without one, forged, repeated and over-long IDs, and the three
    export refusals. Each guard was removed in turn to confirm a test
    fails. The scenario tests fail on current main with markers that have
    no definition.
  • tests/test_ext_cache_typed_artifact.py: the operand grouping.
  • tests/e2e/test_cache_replay_e2e.py: a Chromium test with a Page
    that holds a fragment and a component whose root is <c-cache>. It
    checks four fresh IDs on the second render, the texts, and that
    $i18n.switchLocale('cs-CZ') translates every element. On main it
    fails with binding ...~i18n-1 is not active.
  • One existing test changed: test_i18n_usage.py::test_render_cache_remaps_translation_binding_records_and_html_markers
    used the placeholder string for "ambient owner" as the provided client
    owner. Replay drops a provide value that is not a render ID, so the new
    check skipped the entry. The test now provides a valid ID.

Checks run

  • ruff check, ruff format --check, and mypy (host and
    --platform linux) pass on the changed files.
  • Focused subset (test_ext_cache*, test_i18n*, test_extension*,
    test_events*, test_vue*): 20 failures, 4524 passed. The same
    failures occur on current main without this change. They come from
    the local citry_core Rust extension being older than the source (for
    example "not enough values to unpack (expected 8, got 7)" and the
    reserved-prefix tests from fix(parser): reject v-for and v-slot names with Citry's reserved prefixes #628), so CI with a fresh build is the real
    check.
  • The Chromium e2e files (cache replay and the four i18n files, 34
    tests) passed before the rebase onto main. I did not rerun them after
    the rebase, because the rebase did not touch them.
  • The full suite, scripts/check.py, and the Rust gates were not run
    locally.

Review

An independent reviewer went through the change at maximum effort, with a
separate security pass (places touched: markers for Citry's browser
code, JavaScript and JSON, translated messages) and a check against the
maintainers' advisory survey. It found no security hole and no confirmed
bug. Its performance, robustness, and test-gap findings were fixed and
re-checked, including a crash on a stored ID with thousands of digits
and the cost of export growing with the number of cached rows. A
separate prose review ran twice. After merge, the Mechanism 7 review
record in docs/security/reviews/ is still to be written.

Open items

  • D4, replay does not check that every stored marker and operand is
    renamed.
    If a stored entry's parts and its i18n record disagree, it
    still replays as a hit and the page can name IDs with no definition.
    Writing such an entry needs write access to the cache, which
    docs/design/caching.md section 7.1 already treats as trusted, and
    main behaves the same way. A reviewer also reproduced it with an
    unfixed worker writing entries that a fixed worker then reads. I do
    not expect that across releases: _RENDER_CONTRACT includes the
    installed Citry version (ext/cache/artifact.py:38-40) and replay
    rejects an entry with a different contract (:761), so workers on
    different versions do not replay each other's entries. The reviewer's
    reproduction used two source trees with the same version string, and I
    did not test across a real version bump. A follow-up could reject, at
    replay, an entry whose stored markers or operands are not all renamed.
  • D11, a root provides value for citry_i18n_client that is not
    shaped like a render ID.
    Emission accepts any non-empty string, but
    replay keeps only render-ID-shaped values. With such a value every
    request skips the entry and stores a new one, so it never hits. The
    page stays correct. Nothing in the package supplies the key this way.
  • D8, unproven. export_render_cache reads ctx.instances[0]
    without a guard. Nobody could build an empty instances.
  • Unproven: an owner {"parent": depth} replayed at a different
    depth, and simple=True components.

Follow-ups: problems that exist without this change

  • Replaying a cached component that uses Events adds
    data-cid="<fresh id>" to its root element (ext/events/cache.py:178),
    while a live prepared render skips it (ext/events/emission.py:70-73).
  • docs/design/caching.md section 7.1 says artifacts contain no
    original render IDs, but the i18n payload keeps old binding IDs as the
    names that replay renames from, for a component's own bindings too.
  • An Events revision that re-renders a region containing
    <c-i18n c-client> fails in the browser with an i18n fragment uses a different project runtimeState.configuration: the page and the
    revision write formats and parsers in a different key order, and
    the runtime compares the JSON text.
  • Cache on a component returned from on_render raises
    UnsupportedPreparedView on a hit (also without i18n).
  • Storing a component cache entry with hundreds of its own $c-tr
    bindings is very slow, and the entry is then refused as too large.
  • On replay, a stored binding's values_expression is accepted as any
    non-empty string, while the part-level expression must match one a
    live template wrote. The browser stores it as metadata and does not
    run it, so this is an inconsistency, not a way to run code.

Fixes #631

🤖 Generated with Claude Code

…replay (#631)

A `$c-tr` binding ID is built from the render ID of the component whose
template holds the element. When that component is outside the cached
output (a `<c-cache>` fragment in a page template, or slot content a
caller passes to a cached component), the entry kept the first render's
ID and no definition for it, so a cache hit sent the browser an ID the
page never defined and the Vue app did not start.

Export now asks the render cache which binding IDs the stored parts
name, copies the bindings of components outside the entry into the
record of the cache boundary, and replay renames them to fresh IDs like
any binding written inside the entry. Export refuses an entry that names
an ID no record holds, and replay skips an entry whose binding IDs are
malformed or repeated, or whose binding needs a client provider the
replaying render does not have.

Fixes #631

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the fix/631-cache-i18n-binding branch from 127e6a1 to ae626b0 Compare November 14, 2026 14:12
@JuroOravec
JuroOravec merged commit 885e190 into main Nov 14, 2026
14 of 31 checks passed
@JuroOravec
JuroOravec deleted the fix/631-cache-i18n-binding branch November 14, 2026 14:33
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.

<c-cache> around an element with $c-tr makes the second render fail to start the Vue app

1 participant