fix(atelierssr): v-show on a non-root element with an existing style attr/:style binding…
- User
fix(atelier_ssr): v-show on a non-root element with an existing style attr/:style binding emits a duplicate style attribute, breaking display:none hiding
Location
crates/vize_atelier_ssr/src/codegen/element/plain.rs:490(process_v_show_on_elementunconditionally appends a standalonestyle="display: none;"chunk; its element param is unused)crates/vize_atelier_ssr/src/codegen/element/plain.rs:245-254(collect_element_directive_attr— the single-root/inherit_attrs path that correctly merges into one style binding via_mergeProps; reference for the fix)
Problem
process_v_show_on_element(used on every non-fallthrough-root element) emits a standalonestyle="display: none;"chunk instead of merging v-show into the element's existing style. When the element already has a staticstyleattribute or a:stylebinding, the generated HTML contains TWOstyleattributes. The HTML parser keeps the FIRST, sodisplay:noneis dropped and v-show fails to hide the element (or, in the:stylecase, thedisplay:nonechunk renders first and the bound style is silently dropped). The sibling single-root path already merges correctly via_mergeProps, proving the element-level path is the buggy one.Reproduction
<template> <div class="wrapper"> <span style="color:red" v-show="ok">x</span> </div> </template>Actual
<span style="color:red"${((_ctx.ok) ? "" : " style=\"display: none;\"")}> // when ok===false -> <span style="color:red" style="display: none;">x</span> ; browser keeps the first, display:none ignored<span v-show="ok" :style="{ color }">likewise emits two style attributes.Expected
Vue's SSR
ssrTransformShowrewrites v-show into the single style binding (style=[existing, expr ? null : {display:'none'}]) so there is exactly onestyleattribute.Suggested direction
In
process_v_show_on_element(plain.rs:479-493), inspect the element for an existing staticstyleattr or:stylebinding and merge(expr ? null : { display: 'none' })into a single style binding, reusing the merge logic already present in the single-root path (collect_element_directive_attr, plain.rs:245-254).Interface
No new interfaces are introduced.
- Assistant
Let me look at the helper functions in the crate root and check existing tests for v-show.
- Assistant
Now I'll make the fix. Three coordinated edits in
plain.rs:1. Skip the static
styleattribute when v-show will merge it: - Assistant
2. Merge v-show into the
:stylebinding's_ssrRenderStylecall: - Assistant
The module aliases
vize_carton::String(a CompactString). Use that: - Assistant
All three outputs emit exactly one
styleattribute withdisplay: nonemerged last. This matches Vue's shape. Accepting and running the full suite: - Assistant
That failure looks unrelated (CLI template-syntax quirks). Let me confirm it's pre-existing by stashing my changes:
- Assistant
Clean. The fix is complete.
Summary
Problem:
process_v_show_on_element(the non-fallthrough-root path) always appended a standalonestyle="display: none;"chunk, so elements that already had a staticstyleattr or a:stylebinding got two style attributes — the HTML parser keeps the first, droppingdisplay:none(or the bound style).Changes in
crates/vize_atelier_ssr/src/codegen/element/plain.rs:-
process_element_attrs(plain.rs:108-114) — a staticstyleattribute is now also skipped when the element carries av-showwith an expression, since it gets merged into the single style emission instead. -
process_v_bind_on_element,Some("style")branch (plain.rs:388-411) — the_ssrRenderStylecall now folds in the v-show term as the last array entry:_ssrRenderStyle([static?, bound, (expr) ? null : { display: "none" }]), sodisplay:nonewins in the merge. -
process_v_show_on_element(plain.rs:513-549) — now actually uses its element param:- defers entirely when a
:stylebinding exists (edit 2 handles it); - merges with a static
styleattr into one attribute:style="${_ssrRenderStyle(["color:red", (expr) ? null : { display: "none" }])}", matching Vue'sssrTransformElementshape; - keeps the original standalone chunk when there's no other style source (existing snapshots unchanged).
- defers entirely when a
Tests: added three snapshot tests (
v_show_merges_static_style,v_show_merges_style_binding,v_show_merges_static_and_dynamic_style) — each now emits exactly onestyleattribute. All 111 SSR crate tests pass; the one workspace failure (build_respects_configured_template_syntax_quirks) is pre-existing on the clean tree and unrelated. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →