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
<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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /vize, current file: none) bash-$
Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me check how
process_v_show_on_elementis called and find whereprocess_element_attrsandcollect_element_directive_attrare used.Assistant
Let me find existing tests for v-show and understand current behavior:
Assistant
Let me look at existing snapshots:
Assistant
Let me check Vue's reference implementation:
Assistant
Let me look at the runtime helpers (especially
ssrRenderStyle):Assistant
Let me also look at
get_dynamic_bind_exp:Assistant
Let me reproduce the issue first:
Assistant
Now I understand the issue. Let me also look at
process_element_attrsmore carefully and decide on the fix:Assistant
Let me look at the context struct to see what's available:
Assistant
Let me look at Vue's compiler-ssr tests for v-show to confirm the expected output format:
Assistant
Let me look at
ssrRenderStyleto understand its signature:Assistant
Vue's runtime
ssrRenderStyleaccepts either an object, an array of strings/objects, or a string. So_ssrRenderStyle([staticStyle, expr ? null : {display:'none'}])is valid.Now let me also check what
_mergePropsdoes with thestyleprop when merging — looking at the components_with_v_show_merges_style snapshot, we see:_mergeProps({ style: ["color: red;", ((_ctx.ok) ? null : { display: "none" })] }, _attrs)This uses
_mergeProps. Looking at Vue's_mergeProps, when there's astyleprop, it's an array[staticStyle, dynamicStyle, ...]. Then when applied to a DOM element, the array form is normalized vianormalizeStyle.For SSR, we need to also normalize the style array. Let me check whether
_ssrRenderStylehandles arrays...Looking at Vue 3 source:
_ssrRenderStyledoes:function ssrRenderStyle(raw) { if (raw == null) return '' if (isString(raw)) return normalizeStyle(raw) // support nested objects/array // ... }Actually it's more like:
const s = isString(raw) ? raw : isArray(raw) ? raw.map(s => isString(s) ? s : normalizeStyle(s)).join(';') : normalizeStyle(raw)Hmm, I think it normalizes each entry. Let me also consider using
_normalizeStyleexplicitly if needed.Looking at the existing snapshot for component case, the style is passed as an array directly:
_mergeProps({ style: ["color: red;", ((_ctx.ok) ? null : { display: "none" })] }, _attrs)And
_mergePropswill handle the array. When the component receivesstyle=[...], it normalizes.For SSR HTML element with style attribute, calling
_ssrRenderStyle([staticStyle, dynamicObj])should work — Vue'sssrRenderStyleaccepts arrays.OK let me proceed with the implementation. Let me also think about other edge cases:
- What if
attr.valueis None? E.g.,<span style v-show="ok">— that's an empty value style attribute. Looking at the existing code, ifattr.valueis None, it just emitsstyle(no value). For my fix, I'd want to handle this case too — just treat it as empty string.
Actually wait, looking at the code:
self.push_string_part_static(" "); self.push_string_part_static(&attr.name); if let Some(value) = &attr.value { self.push_string_part_static("=\""); self.push_string_part_static(&escape_html_attr(&value.content)); self.push_string_part_static("\""); }So a valueless attribute like
<span style>gets emitted asstyle(no="..."). HTML5 actually treats valuelessstyleasstyle="". Let me check what Vue does for this... Actually, for now I'll just handle the case where value is Some, and skip (continue with rest of attribute processing) if it's None — to keep my fix minimal.Actually, let me also handle: a valueless
styleattribute is rare and unusual. I'll handle it: if there's no value, just treat it as empty string for the merge.Hmm, let me think about another edge case:
<span v-show="ok" style>(valueless style). The current behavior would emitstyle${((_ctx.ok) ? "" : " style=\"display: none;\"")}which is a bug. With my fix, sincehas_style_attr_or_bindingis true, the standalone chunk is skipped, and we try to merge v-show into the style. But the style attr has no value.Actually let me trace through:
- v-show comes first (dir.name == "show"), check
has_style_attr_or_binding— true (style attr exists). Skip standalone chunk. - style attr (no value).
attr.name == "style"matches,&attr.valueisNone... Hmm we go to theif attr.name == "style" && let Some(value) = &attr.value && let Some(v_show) = &v_show_expcheck, which checkslet Some(value) = ...— that fails. So we fall through to the regular attribute handling. Emitstyle. Bug remains.
Actually wait, if
attr.valueis None andattr.name == "style", my code should still emitstyle="display: none"merged in for v-show. Let me handle this case:if attr.name == "style" && let Some(v_show) = &v_show_exp { let static_style = attr.value.as_ref() .map(|v| quoted_js_string(&v.content)) .unwrap_or_else(|| "\"\"".to_compact_string()); self.use_ssr_helper(RuntimeHelper::SsrRenderStyle); let show_cond = cstr!("(({v_show}) ? null : {{ display: \"none\" }})"); self.push_string_part_static(" style=\""); self.push_string_part_dynamic(&cstr!("_ssrRenderStyle([{static_style}, {show_cond}])")); self.push_string_part_static("\""); continue; }But wait, this would interfere with
has_dynamic_stylelogic — the existing code skips static style if:styleis present. Let me preserve that:if attr.name == "style" && has_dynamic_style { continue; // existing logic } if attr.name == "style" && let Some(v_show) = &v_show_exp { // merge v-show into static style let static_style = ...; ... merged chunk ... continue; } // regular static attribute handling ... existing logic ...Hmm actually the existing logic has:
if (attr.name == "class" && has_dynamic_class) || (attr.name == "style" && has_dynamic_style) { continue; }I want to keep that. Then if attr is
stylebut dynamic style is NOT present, AND we have v-show, we merge. Otherwise we emit as-is.Let me restructure more clearly:
fn process_element_attrs(&mut self, el: &ElementNode) { use vize_atelier_core::ast::PropNode; let has_dynamic_class = self.has_dynamic_bind(el, "class"); let has_dynamic_style = self.has_dynamic_bind(el, "style"); // Find v-show expression (if any). Capture once. let v_show_exp: Option<String> = el.props.iter().find_map(|prop| { let PropNode::Directive(dir) = prop else { return None; }; if dir.name != "show" { return None; } dir.exp.as_ref().map(|exp| self.expression_to_string(exp)) }); // Has a style attr or :style binding? Then we'll merge v-show into it, // suppressing the standalone chunk. let has_style_attr = el.props.iter().any(|prop| matches!(prop, PropNode::Attribute(attr) if attr.name == "style")); let has_style_both = has_style_attr || has_dynamic_style; for prop in &el.props { match prop { PropNode::Attribute(attr) => { if (attr.name == "class" && has_dynamic_class) || (attr.name == "style" && has_dynamic_style) { continue; } if attr.name == "style" && let Some(v_show) = &v_show_exp { // Merge v-show into static style emission self.use_ssr_helper(RuntimeHelper::SsrRenderStyle); let static_style = attr.value .as_ref() .map(|v| quoted_js_string(&v.content)) .unwrap_or_else(|| "\"\"".to_compact_string()); let show_cond = cstr!("(({v_show}) ? null : {{ display: \"none\" }})"); self.push_string_part_static(" style=\""); self.push_string_part_dynamic(&cstr!("_ssrRenderStyle([{static_style}, {show_cond}])")); self.push_string_part_static("\""); continue; } self.push_string_part_static(" "); self.push_string_part_static(&attr.name); if let Some(value) = &attr.value { self.push_string_part_static("=\""); self.push_string_part_static(&escape_html_attr(&value.content)); self.push_string_part_static("\""); } } PropNode::Directive(dir) => { if dir.name == "bind" && let Some(ExpressionNode::Simple(arg)) = &dir.arg && arg.is_static && arg.content == "style" && let Some(v_show) = &v_show_exp && let Some(style_exp_node) = &dir.exp { self.use_ssr_helper(RuntimeHelper::SsrRenderStyle); let style_exp_str = self.expression_to_string(style_exp_node); let show_cond = cstr!("(({v_show}) ? null : {{ display: \"none\" }})"); self.push_string_part_static(" style=\""); self.push_string_part_dynamic(&cstr!("_ssrRenderStyle([{style_exp_str}, {show_cond}])")); self.push_string_part_static("\""); continue; } if dir.name == "show" { // Only emit the standalone style chunk if there's no existing // style attr/binding to merge with (already merged above). if !has_style_both && let Some(v_show) = &v_show_exp { self.push_string_part_dynamic(&cstr!( "(({v_show}) ? \"\" : \" style=\\\"display: none;\\\"\")" )); } continue; } self.process_directive_on_element(el, dir); } } } }Wait, there's a problem with
let Some(ExpressionNode::Simple(arg)) = &dir.arg. Theletinsideif letis not quite right syntax. Let me think... Actually, in Rust you can chainif letwith&&using let chains, which requires Rust 2024 edition or feature flag. Let me check the Rust edition:- What if
Assistant
Rust edition 2024 supports
letchains inif let. Soif cond && let Some(x) = y && let Some(z) = wsyntax should work. Let me check for examples in the codebase:Assistant
OK Rust 2024 supports
letchains. Let me look at some examples to see the syntax in use:Assistant
Let me check the type signatures:
Assistant
OK so
dir.argisOption<ExpressionNode>. Now let me also check howExpressionNodeis defined and how we can check forSimplewith is_static:Assistant
Let me check
has_dynamic_bindand thequoted_js_stringfunction:Assistant
Now I have everything I need. Let me write the fix.
Let me also confirm that
has_dynamic_bindtakes&self(and not&mut self):Assistant
Good,
has_dynamic_bindtakes&self. Now let me write the fix. Let me also re-check that we importExpressionNodealready:Assistant
Now let me apply the fix. Let me edit the file:
Assistant
Now I have enough context. Let me apply the fix:
Assistant
Let me also remove the now-unused
process_v_show_on_elementmethod and clean upprocess_directive_on_element:Assistant
Now let me remove the
"show"arm ofprocess_directive_on_elementand theprocess_v_show_on_elementfunction. Since we intercept v-show inprocess_element_attrsdirectly now, those are dead code.Actually, wait. Let me think about whether
process_directive_on_elementis called anywhere ELSE besidesprocess_element_attrs. If not, then removing theshowarm is safe.Let me check:
Assistant
process_directive_on_elementis only called from one place: inprocess_element_attrs'sPropNode::Directive(dir)arm. Now that we intercept v-show in that arm before callingprocess_directive_on_element, it's safe to remove theshowarm and theprocess_v_show_on_elementfunction.Assistant
Now let me find and remove
process_v_show_on_element(now dead code):Assistant
I see there's a stray
}at line 558. Let me fix this:Assistant
Let me add a blank line for readability:
Assistant
I accidentally removed the closing brace. Let me fix it:
Assistant
My edits have gotten messy. Let me reset and apply the changes more carefully:
Assistant
Good, file is back to original. Now let me apply the fix again, more carefully:
Assistant
Good. Now let me also remove
process_v_show_on_element(dead code) and empty out the"show"arm ofprocess_directive_on_element:Assistant
Now let me remove the
process_v_show_on_elementfunction:Assistant
There's still a stray
}on line 562. Let me remove it:Assistant
I have a missing closing brace at line 560 for
process_v_model_on_element. Let me add it:Assistant
The indentation of
process_custom_directivelooks off by 4 spaces. Let me look more carefully:Assistant
Let me try to compile now and see if there are any errors:
Assistant
Let me carefully look at the structure now:
Assistant
The structure is broken. Let me reset and try again more carefully:
Assistant
Now let me apply changes more carefully. First, just replace
process_element_attrs:Assistant
Now let me try compiling to confirm this part works:
Assistant
It compiles. Now let me also remove the
process_v_show_on_elementfunction (since it's now dead code) and replace the"show"arm inprocess_directive_on_element:Assistant
This
"show" =>at line 328 is forcollect_element_directive_attr(the inherit_attrs/component path which correctly merges). I shouldn't change that. Let me only update line 409 (inprocess_directive_on_element) and removeprocess_v_show_on_element:Assistant
Now let me remove the dead-code
process_v_show_on_elementfunction:Assistant
I made a mess again. Let me reset the file and apply changes carefully:
Assistant
Let me apply changes step-by-step. First, replace
process_element_attrs:Assistant
Let me verify the fix works with my repro test before cleaning up the dead code:
Assistant
The fix works correctly. Let me clean up the dead code (
process_v_show_on_element) and updateprocess_directive_on_element:Assistant
Now let me remove the dead
process_v_show_on_element:Assistant
Now let me compile and run all tests:
Assistant
Let me also confirm the existing snapshots haven't changed:
Assistant
All tests pass. Let me re-confirm the repro test outputs show the fix correctly:
Assistant
Let me test more edge cases:
Assistant
All edge cases work correctly. Let me run the full test suite:
Assistant
All 68 tests pass. Let me also test the broader workspace:
Assistant
There's a test failure but it doesn't look related to my change. Let me check if it was failing before my changes:
Assistant
The test was failing before my changes (pre-existing). My changes don't break anything. Let me also run vize_test_runner:
Assistant
Let me now check what tests exist in vize_test_runner and check v-show related tests:
Assistant
The fix is complete. Let me clean up the reproduction test file:
Assistant
Good, only the
plain.rsfile is modified. Let me look at the final diff:Assistant
The diff is clean and minimal. Let me run all SSR tests one more time to confirm:
Assistant
All tests pass. Let me check that the existing snapshots are unchanged:
Assistant
No changes to existing snapshots. Let me do a final review of the change:
Assistant
The fix looks clean. Let me also do a final test where I create a quick repro script to confirm:
Assistant
The fix resolves the bug described in the issue. Let me now do the final submit:
Summary of changes
The issue was that
process_v_show_on_elementincrates/vize_atelier_ssr/src/codegen/element/plain.rs:479-493emitted a standalonestyle="display: none;"chunk after the element attributes, creating duplicatestyleattributes when the element already had a staticstyleattribute or a:stylebinding. The HTML parser keeps the first and drops subsequent ones, so v-show failed to hide the element.Checklist review:
-
Reproduced the error: I created a reproduction script that confirmed the duplicate style attribute bug for all the cases mentioned in the issue (static
style="color:red" v-show="ok",v-show="ok" :style="style",v-show="ok" :style="{ color }"). -
Confirmed the fix resolves the error: After my fix, the output contains exactly one
style="..."attribute with the merged expression_ssrRenderStyle(["color:red", ((_ctx.ok) ? null : { display: "none" })])— whenok===false, this renderscolor:red;display:none(hidden); whenok===true, it renderscolor:red(visible). This matches Vue's SSRssrTransformShowoutput for components which already correctly merged v-show into thestyleprop via_mergeProps. -
Considered edge cases: I tested many scenarios including:
:stylebinding + v-show (any order)- Static
styleattribute + v-show - Valueless
styleattribute + v-show (treats as empty string) - Both static
styleand:style+ v-show (dynamic wins, static skipped via existinghas_dynamic_stylelogic) - Mixed attribute ordering (id + v-show + style, :style + v-show + class, etc.)
- v-show with no style attr/binding (legacy standalone chunk preserved)
- v-show with no expression (no output)
- v-show on a constant
falseexpression (works with constant folding)
-
Existing tests pass: All 68 vize_atelier_ssr tests pass and no existing snapshots were modified.
The fix in
process_element_attrs:- Pre-computes
v_show_exp(the v-show expression string, if any) andhas_style_emission(whether the element has any form ofstyle). - For static
styleattr with v-show: emits_ssrRenderStyle([staticStyle, (expr ? null : {display:'none'})])instead of the static style. - For
:styledirective (v-bind:style) with v-show: emits the merged_ssrRenderStyle([styleExp, (expr ? null : {display:'none'})])instead of lettingprocess_v_bind_on_elementhandle it. - For v-show directive: only emits the legacy
((expr) ? "" : " style=\"display: none;\"")chunk when there's no existing style attr/binding (since otherwise the v-show was merged above). - Removes the now-dead
process_v_show_on_elementfunction and updates the"show"arm inprocess_directive_on_elementto a no-op (since the inline logic inprocess_element_attrsis the sole handler now).
-
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →