ISSUE DESCRIPTION fix(atelierssr): v-show on a non-root element with an existing style…
- User
ISSUE DESCRIPTION
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
vue<template> <div class="wrapper"> <span style="color:red" v-show="ok">x</span> </div> </template>Actual
js<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 static attr or binding and merge into a single style binding, reusing the merge logic already present in the single-root path (, plain.rs:245-254). - Assistant
I’ll first inspect the SSR element code and nearby tests to understand both code paths and identify the project’s test conventions. Then I’ll reproduce the duplicate output with the narrowest existing test/tool, implement a generalized merge for static and bound styles, and run focused plus relevant broader tests.
- Assistant
The buggy function is exactly as described. Before changing it, I need to determine attribute emission order and whether style directives are independently emitted, because the correct fix must avoid not only adding a duplicate but also prevent the existing static or
:styleprocessor from emitting its own attribute. I’ll inspect the full element generation flow, AST prop ordering, and SSR snapshot/integration tests usinggrep(ripgrep is unavailable). - Assistant
The direct path emits props sequentially, so fixing only
process_v_show_on_elementwould still be order-dependent unless existing style props are suppressed. A clean localized strategy is:- detect
v-showwhile processing direct element attrs; - suppress the static
styleand static-argumentv-bind:styleemissions; - let
process_v_show_on_elementemit one_ssrRenderStyle([...])attribute combining static style, bound style, and the conditional display object; - retain the current conditional standalone chunk when there is no existing style, minimizing unrelated output changes.
I’ll inspect prop normalization and helper APIs, then compile the exact reproduction before implementing.
- detect
- Assistant
The shared normalization confirms the intended representation: duplicate style prop entries become a style array. I’ll use a temporary Cargo example (removed immediately afterward) to compile both reported templates and capture the pre-fix output. This does not alter repository tests.
- Assistant
The reproduction confirms both failure modes: static style appears first and defeats hiding; bound style appears second and is discarded when hidden. I’ll implement the localized style-array merge rather than routing the whole element through merged-attrs generation, because that broader route has known differences for element
v-model. The merge will scan all staticstyle/:stylevalues regardless of source order, suppress their normal emissions only when a validv-showexpression exists, and emit exactly one rendered style attribute. - Assistant
The first edit applied, but the function replacement did not match the escaped source text, leaving an incomplete change that would drop existing styles. I caught this in the diff before testing. I’ll replace the function by line-anchored slicing, then inspect the resulting source carefully.
- Assistant
The merged function now correctly builds
[existing styles…, show condition]and emits one_ssrRenderStylecall. I’ll compile and rerun the exact two reproductions plus reversed directive order and combined static/dynamic style as edge cases, verifying each generated start tag contains only one style emission. - Assistant
All reproduced and edge-case outputs now contain a single
style="${_ssrRenderStyle([...])}", withdisplay: "none"last so it overrides any existing display while hidden. Directive order no longer matters, and static plus dynamic styles are both retained.I’ll now run the package’s complete test suite and Clippy. I’ll also inspect
get_v_show_expsemantics and repository status to ensure invalid-expression handling and temporary-file cleanup are sound. - Assistant
Validation is complete:
- Reproduced reported error: Yes. Before the fix, the temporary compiler example produced two style attributes for static style and conflicting style emissions for
:style, exactly matching the report. - Confirmed fix resolves error: Yes. The same templates now compile to one
_ssrRenderStyleattribute containing[existingStyle, condition ? null : { display: "none" }]. - Considered edge cases: Yes. I verified reversed prop order and simultaneous static plus bound styles. The scan is order-independent, preserves all existing style values, and puts the hiding style last. Elements without existing style retain their prior compact output. Missing
v-showexpressions do not suppress styles because suppression requiresget_v_show_expto return an expression. - Ran affected existing tests: Yes.
cargo test -p vize_atelier_ssrpassed all 108 unit/integration tests (40 + 68), doc tests passed,cargo checkpassed, and Clippy with warnings denied passed. - The temporary reproduction example was removed; only the intended source file is modified, and passes.
- Reproduced reported error: Yes. Before the fix, the temporary compiler example produced two style attributes for static style and conflicting style emissions for
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.