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
Now add tests for the new merge cases:
- Assistant
Good —
get_compiled_stringwraps in a div, so the inner element goes through the non-fallthrough path. Build and run: - Assistant
The new output is exactly the expected merged form. The 3 failures are just new snapshots pending acceptance. Let me accept and inspect them:
- Assistant
All merged correctly. Now run the full crate test suite to check for regressions:
- Assistant
Fixed. All 111 crate tests pass, clippy and fmt are clean.
Changes
crates/vize_atelier_ssr/src/codegen/element/plain.rs-
process_v_show_on_element(the buggy element-level path) — now inspects the element for an existing staticstyleattribute (get_element_attr_value) and/or a:stylebinding (get_dynamic_bind_exp). When either exists, it emits a single merged style attribute —style="${_ssrRenderStyle([<static>, <bound>, (expr ? null : { display: "none" })])}"— matching Vue'sssrTransformShowsemantics. When neither exists, the original conditional standalone-attr output is preserved (so the two existing v-show snapshots are byte-identical). -
process_element_attrs— skips standalone emission of the staticstyleattribute when v-show is present (same pattern already used for the dynamic-style skip), since v-show now owns the merged emission. -
process_v_bind_on_element(Some("style")branch) — returns early when the element has v-show, deferring style emission to the v-show handler so only onestyleattribute is ever produced.
New snapshot tests (
tests/ssr_snapshot.rs)- static style + v-show →
style="${_ssrRenderStyle(["color:red", ((_ctx.ok) ? null : { display: "none" })])}" :stylebinding + v-show →style="${_ssrRenderStyle([{ color: _ctx.color }, ...])}"- static + bound + v-show → all three sources merged into one attribute
Each case now renders exactly one
styleattribute, sodisplay: noneis no longer dropped by the browser's first-attribute-wins parsing. -
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 →