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 start by exploring the repository to understand the structure and locate the relevant files mentioned in the issue. Let's first get an overview.
- Assistant
Let me look at the repository structure first to understand what we're dealing with.
- Assistant
Let me explore the specific file mentioned in the issue description.
- Assistant
Let me look at the specific file mentioned in the issue description first.
- Assistant
Let me scroll down to see the
process_v_show_on_elementfunction and thecollect_element_directive_attrfunction. - Assistant
Let me look at the
process_v_show_on_elementfunction and the surrounding code. - Assistant
Now let me look at the
process_element_attrsfunction to understand how attributes are processed. - Assistant
Let me see the full
process_directive_on_elementfunction: - Assistant
Now let me understand the full flow. Let me look at how
process_element_attrscallsprocess_directive_on_elementand thenprocess_v_show_on_element: - Assistant
Let me look at the element structure to understand how to check for existing style attributes:
- Assistant
Let me look for the AST types.
- Assistant
Let me search for the AST types more broadly.
- Assistant
Let me find the AST module definition:
- Assistant
Let me look at that AST module:
- Assistant
Good. Now I can see that
PropNodeis either anAttributeor aDirective. Let me also check what aDirectiveNodelooks like to understand how to check for:stylebindings: - Assistant
Now let me look at the existing tests to understand how to test this:
- Assistant
Let me search for existing v-show tests:
- Assistant
Let me look at the v-show test section:
- Assistant
Let me see what the existing v-show tests look like and understand the expected output. Let me look at the snapshots:
- Assistant
Let me look at the v-show snapshot to see what the expected output looks like:
- Assistant
Let me look at the basic v-show snapshot too:
- Assistant
Let me also look at the component_with_v_show_merges_style test case which should show us the correct behavior:
- Assistant
Now let me examine the
collect_element_directive_attrfunction that correctly handles v-show for the component/inherit_attrs path: - Assistant
Let me look at the existing test snapshots and understand the current behavior:
- Assistant
Let me also look at the
get_dynamic_bind_expfunction: - Assistant
Now let me also check the
ssrRenderStylehelper and theSsrRenderStyleruntime helper to understand how it works: - Assistant
Let me now look at how the element attributes are processed in
process_element_attrs, which is the main function I need to modify: - Assistant
Let me look at the
process_v_bind_on_elementto see how it handles:style: - Assistant
Now I have a comprehensive understanding of the code. Let me create a reproduction script to confirm the bug. First, let me check if I can compile and run the tests:
- Assistant
Let me now create a reproduction script to confirm the bug. Let me first check what the current output looks like for the problematic case:
- Assistant
Let me write a quick test script:
- Assistant
Let me write a quick test to see the current output for the problematic cases:
- Assistant
Let me create a proper Rust binary to test:
- Assistant
Let me look at the existing test structure to write a reproduction test:
- Assistant
Let me write a small Rust test script:
- Assistant
Now I can clearly see the bug. For
<span style="color:red" v-show="ok">, it generates:code<span style="color:red"${((_ctx.ok) ? "" : " style=\"display: none;\"")}>Two
style=attributes!For
<span v-show="ok" :style="myStyle">, it generates:code<span${((_ctx.ok) ? "" : " style=\"display: none;\"")} style="${_ssrRenderStyle(_ctx.myStyle)}">Again, two
style=attributes!Let me look at the helper methods and types I'll need:
- Assistant
Let me check what type
expression_to_stringreturns: - Assistant
Let me look at the
push_string_part_*methods: - Assistant
Let me look at the helper files to understand the types better.
- Assistant
Let me look at the
push_string_part_*methods to understand their signatures: - Assistant
Let me also check how
quoted_js_stringworks: - Assistant
Now I have a good understanding of the code. Let me also check how
quoted_js_stringworks to understand how to properly quote static style values: - Assistant
Now let me look at the
Stringimport: - Assistant
Let me look at the
Stringimport: - Assistant
Let me look at the element.rs module file:
- Assistant
Now I have a full understanding. Let me plan the fix:
The problem:
process_v_show_on_elementalways emits a standalonestyle="display: none;"attribute. When the element already has a staticstyleattr or:stylebinding, this creates duplicatestyleattributes.The fix needs to:
- When there's a static
style+v-show(no:style): merge them into a single style using_ssrRenderStyle - When there's
:style+v-show: skip the standalone v-show style, and have:stylemerge the v-show expression - When there's
v-showalone: emit standalone (current behavior)
Let me implement this:
- When there's a static
- Assistant
Now let me understand the full approach. I need to check if
has_v_show_exphelper already exists or if I need to create one: - Assistant
Good,
has_v_showandget_v_show_expalready exist. Let me check their signatures: - Assistant
Now I have a complete understanding. Let me implement the fix. The approach:
-
In
process_element_attrs: when there's a staticstyleattr ANDv-show(but no:style), skip the static style attr in the loop (it'll be handled byprocess_v_show_on_element). -
In
process_v_show_on_element:- If there's a
:stylebinding → return early (:stylewill handle merging) - If there's a static
styleattr → merge into a single_ssrRenderStylecall - Otherwise → emit standalone (current behavior)
- If there's a
-
In
process_v_bind_on_elementfor:style: if element hasv-show, merge the v-show expression into the:stylebinding.
-
- Assistant
Now let me implement the fix. First, modify
process_element_attrsto skip staticstylewhen there'sv-showand no:style: - Assistant
Now let me modify
process_v_bind_on_elementfor the:stylecase to merge v-show: - Assistant
Now let me modify the
:stylecase inprocess_v_bind_on_elementto merge v-show when present: - Assistant
I see there's a syntax error - a duplicate closing brace. Let me fix it:
- Assistant
I see a duplicate
}at line 415. Let me fix it: - Assistant
I still see a duplicate
}at line 415. Let me look at the exact context: - Assistant
I see the duplicate
}at line 415. Let me remove it: - Assistant
I see there's a duplicate line. Let me remove it:
- Assistant
Good, the style binding fix is in place. Now let me modify
process_v_show_on_elementto handle the case where there's a static style but no:style: - Assistant
Now let me replace
process_v_show_on_elementwith the fixed version: - Assistant
Now let me try to compile and see if there are any errors:
- Assistant
The code compiles. Now let me run the reproduction tests to verify the fix works:
- Assistant
Both tests pass. Let me now run the existing tests to make sure I didn't break anything:
- Assistant
All 68 existing tests pass. Let me run the full test suite:
- Assistant
All tests pass. Let me also check the existing snapshot for v_show_with_other_attrs, since this test already existed:
- Assistant
Let me also verify the component path still works correctly since it has different handling:
- Assistant
Now let me clean up the temporary test file since the instructions say not to add new tests:
- Assistant
Now let me run the full test suite again to make sure everything is working:
- Assistant
All 68 tests pass. Let me now verify my changes by looking at the diff:
- Assistant
The diff looks clean and correct. Let me now verify all existing tests pass one final time:
- Assistant
Let me now do a final verification by running a comprehensive test covering all the cases mentioned in the issue:
- Assistant
The compile succeeded. Let me run it:
- Assistant
The test 4 failure is in my test script's counting logic (the escaped
style=\"display: none;\"isn't counted bystyle="). The actual behavior is correct. Let me fix the test: - Assistant
Let me fix the assertion - the escape checking in my test was wrong:
- Assistant
All tests pass. Let me also run the broader test suite to make sure nothing else is broken:
- Assistant
All tests pass. Let me clean up temporary files:
- Assistant
Let me verify the final state of the changed file:
- Assistant
Let me do a final review of the complete diff:
- Assistant
The diff looks clean and correct. Let me run the full test suite one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.