Skip to content

Loosen the one-id-per-component-instance constraint (v-for over components, copy-paste, reuse) #148

Open

Description

@JuroOravec

(Opus 5.5)

Every rendered Citry component instance has a unique identity, and the browser runtime assumes that one occurrence id means exactly one live Vue instance. This makes some things hard: a browser v-for over Citry components, reusing rendered output in more than one place, and duplicating Citry-rendered HTML while debugging. This issue tracks whether and how to loosen that.

What exists today (researched 2026-09-27)

Two kinds of id:

  • Render id (c…): minted by Python for each rendered instance, new on every re-render. Events requests carry it; State refreshes and Render targets address it.
  • Occurrence id (citryOccurrence<hash>): a hash of the parent's occurrence id and the component's position. It names one Vue instance in the data sent to the browser.

The server keeps no record of the ids it issued. It checks only their shape, and the State token is bound to the component class, not the instance. The browser keeps about 15 "one id = one live instance" records (mounted instances, Events contexts, remount accounting, i18n cells, Vue keys, reply id translation). A second live instance with the same id, or an id the server never sent, stops the app ("invalid mounted occurrence").

Current behavior for the motivating cases:

  • Copy-pasting rendered HTML by hand: identity lives in JavaScript maps, not DOM attributes, so pasted markup is untracked DOM and raises no error. Pasting a fragment <script data-citry-vue-fragment> block fails with "duplicate Citry Vue app". What Vue does to pasted DOM on its next re-render of that element is unverified.
  • Reusing cached output: the render cache mints fresh render ids on replay, so reuse works. The Python duplicate-id error comes from placing the same render object twice in one page.
  • Browser v-for over a Citry component: rejected by the template parser and the Vue compiler (CITRY_COMPONENT_IN_V_FOR); use c-for, which gives every row a real server occurrence.

Options considered

  • (a) Clones share the original's id. Every one-to-one rule in the browser becomes one-to-many, and clones still share js_data, State and the send queue, so they aren't independent components. Not recommended.
  • (b) The browser mints clone ids mapped to the original, from the original's id plus every enclosing loop key. The server already accepts such ids for replies to a component's own event. Work: mark browser-created occurrences so about eight browser checks skip them, a compiler id expression that includes loop keys, a rule for what clones do when the original is re-rendered, and a way to apply a server reply to a browser-created occurrence.
  • (c) Treat the same id in different tree branches as different. Occurrence ids already encode position; the missing part is the loop key, which only the browser knows, so this reduces to (b).
  • (d) Keep the current rule.

Constraints

  • Must not break the performance work: simple = "vue" rows, per-row caches, the row HTML writer, the Rust server render programs used for hydration, and the validate-once client. None of the options slows the server's hot paths; the browser checks would gain skip paths, which weakens what they prove, at an unmeasured cost.
  • An earlier Alpine-era decision (A9) rejected cloning server components for the same missing pieces: a server contract for browser-minted ids and State tokens, and a way to create a whole client instance in one step.

Suggested next step

Keep (d) until a concrete use case needs more. If one does, start with a narrow (b): only loops with unique string :keys, only for components with no Events, no child Citry components, no markers and no i18n provider role (a simple = "vue" leaf fits). Also decide what "copy-paste while debugging" should mean in practice: untracked static DOM is already fine; making pasted components live is the hard part.

Activity

  1. added
    next-sprint
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions