You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support v-once and v-memo in component templates #166
Templates can't use Vue's v-once or v-memo; Citry rejects them when the template loads. Both are useful for skipping work on parts of a component that rarely change.
Why they're rejected today
Citry renders compiled Vue templates without Vue's render cache, and the parts needed for these directives don't line up yet:
Citry clears a component's cached render output only when its compiled template changes. A server response that only changes values would keep showing the old v-once / v-memo output, so a server re-render would not reset them.
Citry passes Vue its own cache array, so when Vue removes a cached node it clears the wrong entry (a v-once inside a toggled v-if would likely reuse a removed node — inferred from the code, not reproduced).
The browser runtime doesn't include the helpers these directives compile to (setBlockTracking, withMemo), and the compiler output check forbids them.
Proposal
Support both with this behavior: they follow Vue's rules between server re-renders, and any server re-render of the component resets them.
Clear the component's render cache on every server update to that component.
Use Vue's own per-instance cache array.
Add the helpers to the browser runtime and allow them in the compiler output check.
Tests: v-once/v-memo keep their output between client updates, reset after a server re-render, and behave inside toggled v-if and keyed lists; hydration still matches.
Parked for now (low priority). This is the design note worked out so far, kept here so the work can resume from it. The two decisions at the end are still open.
Syntax
These are Vue's own directives, written as in any Vue template. Citry adds no syntax:
<header v-once>{{ title }}</header>
<li v-for="row in rows" :key="row.id" v-memo="[row.id, row.selected]">...</li>
v-once takes no value, and v-memo takes an array expression read in the browser.
Behavior
On the server: the first render writes the HTML as without the directive. Both only skip work on later client renders, and hydration compares the same nodes. The server renderer (server_render.rs) treats them as transparent, writing the element normally.
In the browser, between server updates: Vue's rules apply. A v-once part renders once per component instance. A v-memo part re-renders only when one of the values in its array changes (Vue's isMemoSame).
When the server re-renders the component: that resets both. Citry clears that component instance's render cache whenever a server update changes its prepared data or template, so v-once shows the new server values. This is the issue's rule, and it matches what a reader expects from "server is the source of truth".
The changes needed:
give each instance Vue's own cache array, so that a node removed inside a toggled v-if clears its own entry;
add setBlockTracking and withMemo to the browser runtime's helper contract (client.jsHELPER_CONTRACT, runtime.js);
remove them, and _cache[, from the compiler output check (_FORBIDDEN_CODE in _vue/compiler.py).
Error modes
v-memo with a value that is not an array: Vue's dev build warns; Citry raises at template load with the line, like other Vue syntax errors.
v-memo inside v-for without :key: Vue's compiler refuses it. Citry passes its message through citry check and raises at load.
v-once or v-memo on a <c-*> tag or a c- binding element: refused at load, because Citry renders those parts on the server and the browser cache would hide server updates. It names the tag and suggests moving the directive to a plain element.
v-memo around c- bindings or Events listeners: the memoized vnode keeps stale handler identities, so it is refused with the same message. Vue listeners in the browser are fine.
Hydration mismatch risk: none from the directives themselves. The server writes what Vue's first client render writes.
Tests
Output is kept between client updates.
A server re-render resets it, including inside a toggled v-if and in keyed lists.
Hydration still matches.
The parity check covers pages using both directives.
The refusals above.
Decisions for you
What resets the cache: any server update to the component, or only one that changes its prepared data? I propose any update, which is simpler and matches the issue.
Refusing v-memo around c- bindings and Events listeners: I propose refusing for now, since the memoized handlers would go stale; widen it later if needed.
Activity
JuroOravec commentedon Oct 25, 2026
Parked for now (low priority). This is the design note worked out so far, kept here so the work can resume from it. The two decisions at the end are still open.
Syntax
These are Vue's own directives, written as in any Vue template. Citry adds no syntax:
v-oncetakes no value, andv-memotakes an array expression read in the browser.Behavior
server_render.rs) treats them as transparent, writing the element normally.v-oncepart renders once per component instance. Av-memopart re-renders only when one of the values in its array changes (Vue'sisMemoSame).v-onceshows the new server values. This is the issue's rule, and it matches what a reader expects from "server is the source of truth".v-ifclears its own entry;setBlockTrackingandwithMemoto the browser runtime's helper contract (client.jsHELPER_CONTRACT,runtime.js);_cache[, from the compiler output check (_FORBIDDEN_CODEin_vue/compiler.py).Error modes
v-memowith a value that is not an array: Vue's dev build warns; Citry raises at template load with the line, like other Vue syntax errors.v-memoinsidev-forwithout:key: Vue's compiler refuses it. Citry passes its message throughcitry checkand raises at load.v-onceorv-memoon a<c-*>tag or ac-binding element: refused at load, because Citry renders those parts on the server and the browser cache would hide server updates. It names the tag and suggests moving the directive to a plain element.v-memoaroundc-bindings or Events listeners: the memoized vnode keeps stale handler identities, so it is refused with the same message. Vue listeners in the browser are fine.Tests
v-ifand in keyed lists.Decisions for you
v-memoaroundc-bindings and Events listeners: I propose refusing for now, since the memoized handlers would go stale; widen it later if needed.