Skip to content

fix: raise VueCodeError for a Vue-code c-bind key on c-slot and c-fill - #625

Merged
JuroOravec merged 3 commits into
mainfrom
fix/vuecodeerror-slot-bind
Nov 14, 2026
Merged

JuroOravec merged 3 commits into
mainfrom
fix/vuecodeerror-slot-bind

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Part of 0.9.0. 0.8.0 is released. This changes exception types and refuses names that used to pass, so it ships in a minor release. Its changelog entries are under Unreleased.

What this does

Closes #559.

1. VueCodeError for a Vue-code c-bind key on <c-slot> and <c-fill>

A c-bind key that Vue would read as code, such as ":row" or "v-slot", on <c-slot> or <c-fill> was refused at render with a plain RuntimeError. HTML elements and component tags raise VueCodeError (a TypeError) for the same mistake, and its docstring promises it for every such key. Code that catches VueCodeError missed the slot and fill cases.

Now <c-slot> and <c-fill> raise VueCodeError too, with the same messages. The render failed before as well, so only the exception type changes.

  • <c-slot c-bind>: a key that is_vue_code_attr_name accepts (:row, v-slot, v-if, @click, #x, .x, ^x, any letter case) raises VueCodeError. The rule decides, not the message lookup: a Vue-code key that has no slot-specific message still raises VueCodeError, with the general message.
  • <c-fill c-bind>: the same keys raise VueCodeError in the "unsupported key" check. An unknown plain key such as "bogus" stays RuntimeError.
  • A $c-tr key in c-bind on <c-slot> or <c-fill> raises VueCodeError, as it already does on elements and component tags.

2. Two more names that <c-slot> used to pass as slot data are refused (breaking)

Both raise VueCodeError now. Neither reached the browser, because slot data stays on the server, but the tag did not refuse them as it refuses the other Vue-code names.

  • <c-slot c-$c-tr:x="y" />: a c- attribute whose name is a $c-tr binding. The parser does not reject it, so the slot took $c-tr:x as a slot data key. SlotNode now checks its c-* attribute names once at construction, as ComponentNode does, and raises with the component-tag message style plus advice that fits a slot.
  • On <c-slot>, a c-bind key that is just ".", or a str subclass that overrides startswith and so hides its text. unsupported_slot_tag_directive_message skipped a bare ., and it read the key through the subclass's own methods. It now treats every .-prefixed key as a DOM-property binding and reads the key as an exact str.

Sweep for siblings:

  • New exact_str() in attrs.py returns the exact str text of a key. validate_html_attr_name already did this inline for HTML elements and <c-element>; it now calls the helper.
  • <c-fill> checked is_vue_code_attr_name, which already reads real text, but compared the key with in ("name", "data", "fallback"), which uses the subclass's __eq__. It now uses the exact key too, as <c-slot> does for name and required.
  • Component tags (other than <c-element>) tested the :c-* State binding and x-on:* refusals with the subclass's startswith. A str subclass spelling :c-value slipped past it as a kwarg. They now use the exact key, so it raises the same RuntimeError as a plain str.
  • Every built-in and structural tag was probed with c-bind carrying :row, $c-tr:x, ., and disguised keys, and with a c-$c-tr:x attribute. <c-slot> was the only tag that accepted any of them. The tags with a fixed attribute list reject c-$c-tr:x at parse time like any unknown attribute.
  • Ordinary str mixin enum keys keep working as a component kwarg, a slot data key, and a fill name (covered by tests).

Left as RuntimeError on purpose

Not a name that Python data chose and that Vue reads as code, which is what VueCodeError covers:

  • Citry's own @c-* and :c-* names in c-bind on <c-slot> and <c-fill>. They are not Vue code (is_vue_code_attr_name leaves them out, and elements still accept them).
  • {{ ... }} inside a : prop on <c-slot>, in a fill's v-slot, and in a Vue binding on a component tag, and the "must be written in the template with a plain text value" checks. These are template-author mistakes about a binding's value. docs/design/vue.md says "interpolation in a written binding fails as a template error", and the parser rejects the slot and fill forms with SyntaxError.
  • ref set from Python data on a component tag.

Found while reviewing, not changed

None of these reaches the browser, and none is a RuntimeError path:

  • A c-bind key that starts with #c- (and data-cev-* or x-on:* keys) is accepted as slot data on <c-slot>, while component tags, <c-fill> and the built-in tags refuse it. Slot data stays on the server.
  • A bare ., @, or : written as an attribute in the template (<c-slot .="v" />, <c-child @="v" />) passes the parser, because the grammar and the len(key) > 1 guard in _vue_directive_name accept it. Only the template author can write it.
  • Not tested: _reject_vue_code_from_attrs_hook compares keys with key in before, which uses a key's own __eq__ and __hash__. Hooks are extension code, which is already trusted.

Docs, comments and changelog

The VueCodeError docstring, the docs (vue/slots.md, vue/csp.md) and docs/design/vue.md say where <c-slot> and <c-fill> raise it. CHANGELOG.md has two **Breaking:** entries under Unreleased (the exception type change, and the newly refused names) and one line under Fixes for str subclass keys.

Checklist

  • Tests added or updated for the change
  • CHANGELOG.md updated
  • Docs updated
  • No grammar, AST, compiler, or binding change, so no cross-language update

Checks run: the full packages/py/citry/tests suite without browser tests (12389 passed), ruff check, ruff format --check, and mypy packages/py/citry/citry (also with --platform linux). The new tests fail with the source change reverted, and the two __eq__ tests fail when exact_str is removed from the slot and fill loops. The full scripts/check.py gate was not run. packages/py/citry_ui tests: 3339 passed and 1 failed, test_the_editor_accepts_digit_inputs_as_text_or_numbers, which runs the ty language analyzer against the installed package and does not load this branch's code.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits November 14, 2026 14:42
#559)

A c-bind key that Vue would read as code, such as ":row" or "v-slot",
on <c-slot> or <c-fill> raised a plain RuntimeError at render, while
HTML elements and component tags raise VueCodeError for the same
mistake. Both tags now raise VueCodeError, with the same messages. A
$c-tr key in c-bind does too. Citry's own @c-* and :c-* names and
unknown keys on <c-fill> keep raising RuntimeError, because they are
not Vue code.

The change is breaking for code that catches RuntimeError around these
renders, so it has a changelog entry. The VueCodeError docstring and the
slots, CSP and Vue design docs name the two tags.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ct text (#559)

<c-slot> passed two names to the fill as slot data that every other tag
refuses: a $c-tr binding written as a c- attribute (c-$c-tr:x) and a
c-bind key that is just ".". It also decided on a c-bind key with the
key's own startswith, so a str subclass could hide a Vue-code name. All
three now raise VueCodeError. The refusal follows is_vue_code_attr_name,
so a Vue-code key with no slot-specific message is still refused.

A new exact_str() helper gives the checks the real text of a key. <c-slot>,
<c-fill> and component tags use it, so a str subclass that overrides
startswith or __eq__ gets the same result as a plain str.

These are breaking changes for code that passes such names to <c-slot>, so
the changelog says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec

Copy link
Copy Markdown
Member Author

Follow-ups from "Found while reviewing, not changed": #647 (slot data accepts reserved c-bind keys, plus the untested hook key comparison) and #648 (bare ., @, : attribute names).

@JuroOravec
JuroOravec merged commit d29f2d1 into main Nov 14, 2026
0 of 11 checks passed
@JuroOravec
JuroOravec deleted the fix/vuecodeerror-slot-bind branch November 14, 2026 14:04
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.

A refused c-bind key on <c-slot> or <c-fill> raises RuntimeError instead of VueCodeError

1 participant