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).ADDITIONAL ADVICE
Assistant
Let me analyze the issue:
- The problem is in
crates/vize_atelier_ssr/src/codegen/element/plain.rs process_v_show_on_elementat line ~490 unconditionally appends a standalonestyle="display: none;"chunk- When an element already has a
styleattribute or:stylebinding, this creates duplicatestyleattributes - The fix should merge v-show into the existing style binding, similar to how
collect_element_directive_attrdoes it
Let me start by exploring the repository structure and understanding the code.
- The problem is in
Assistant
Good, I found the relevant file. Let me open it and understand the code structure.
Assistant
Sorry for the confusion! Let me open the file with the correct syntax.
Assistant
Let me continue reading the file to find the relevant sections mentioned in the issue.
Assistant
Let me continue reading to find the
process_v_show_on_elementfunction:Assistant
Now I understand the issue. Let me see the rest of the file and understand the helper functions:
Assistant
Now let me understand how Vue SSR handles this. Looking at the correct path in
collect_element_directive_attr(lines 245-254):"show" => { let Some(exp) = dir.exp.as_ref().map(|exp| self.expression_to_string(exp)) else { return; }; entries.push(component_prop_entry( "style", &cstr!("(({exp}) ? null : {{ display: \"none\" }})"), false, )); }This correctly merges the v-show style into the entries that get merged via
_mergeProps. Butprocess_v_show_on_element(lines 479-493) emits a standalonestyle="display: none;"chunk:self.push_string_part_dynamic(&cstr!( "(({exp}) ? \"\" : \" style=\\\"display: none;\\\"\")" ));The fix should make
process_v_show_on_elementuse_ssrRenderStylesimilar to howprocess_v_bind_on_elementhandles the:stylecase. Let me check how the style rendering helper works:Assistant
Now let me check what tests exist and look at the test structure:
Assistant
Let me look at the existing v-show snapshot tests:
Assistant
Now I can see the problem clearly. Let me check the test file for more context and understand how the tests are structured:
Assistant
Now let me look at the test file to understand the test structure:
Assistant
Let me now look at the v_show test section specifically:
Assistant
Assistant
The command is still running (downloading dependencies). Let me wait for it to complete.
<tool_call> <function=bash_terminal> <parameter=command> cd /vize && cargo test --package vize_atelier_ssr --test ssr_snapshot v_show 2>&1 </tool_call>
Assistant
The command is still running. Let me wait for it and try again with a proper timeout.
Assistant
Good, tests pass. Now let me create a reproduction script to confirm the issue:
Assistant
I need to run the test script to confirm the issue. Let me compile and run it.
Assistant
Good, the build completed. Now let me run the test binary to see the current behavior and confirm the bug.
Assistant
Interesting! The output looks correct now - it's using
_mergePropswith the style merged. Wait, this looks like it's going through theinherit_attrspath (component-level), not the plain element path. Let me check what happens when the element is NOT the root (no inherit_attrs):Assistant
Assistant
I made an error in my command. Let me try again.
Assistant
Now I have a clear plan. Let me implement the fix:
Assistant
Now I'll implement the fix. Let me start by examining the current code structure more carefully and then make the changes:
Assistant
Now I understand the full picture. Let me implement the fix step by step:
- First, add a helper method to check if element has v-show and get its expression
- Modify
process_element_attrsto skip staticstylewhen v-show is present - Modify
process_v_bind_on_elementfor style to merge v-show - Modify
process_v_show_on_elementto properly merge with existing styles
Assistant
Now let me implement the fix step by step:
Assistant
Let me apply the fix step by step. First, I'll modify
process_element_attrsto skip static style when v-show is present:Assistant
I need to modify the file step by step. Let me start by:
- Adding the
has_v_showhelper method - Modifying
process_element_attrsto skip static style when v-show is present - Modifying
process_v_bind_on_elementto merge v-show into style - Modifying
process_v_show_on_elementto handle the merge properly
Let me do this one edit at a time.
- Adding the
Assistant
The user hasn't sent a new message. The sed command was executed successfully. I need to continue with the fix. Let me check the current state of the file and continue modifying it.
Assistant
The
has_v_showvariable was added. Now I need to modify the condition at lines 114-117 to also skip static style when v-show is present (but no dynamic style binding). Let me update the condition.Assistant
Let me check if the change was applied correctly:
Assistant
The sed didn't work as expected with multiline. Let me try a different approach - I'll use the edit command:
Assistant
The sed command didn't work properly for multiline replacement. Let me use a different approach - I'll use Python or a heredoc with sed to do the replacement properly. Let me first see the exact line numbers and then make the edit.
Assistant
The user hasn't sent a new message. The last command I ran was adding a line after line 115. Let me check if the modification was applied correctly and continue with the fix.
Assistant
The condition is now correct. Now I need to:
- Add the
has_v_showhelper method - Add the
get_v_show_exphelper method - Modify
process_v_bind_on_elementto merge v-show into style - Modify
process_v_show_on_elementto handle merging properly
Let me add the helper methods first. I'll add them after the
has_dynamic_bindmethod:- Add the
Assistant
The user hasn't provided any new information. The previous command showed the end of the file. I need to add the helper methods
has_v_showandget_v_show_exp. Let me continue with the implementation.I need to:
- Add
has_v_showhelper method - Add
get_v_show_exphelper method - Modify
process_v_bind_on_elementto merge v-show into style - Modify
process_v_show_on_elementto handle merging properly
Let me add the helper methods before the closing brace of the impl block.
- Add
Assistant
Let me verify the helper methods were added correctly:
Assistant
The helper methods were added correctly. Now I need to modify
process_v_bind_on_elementto merge v-show into style when present. Let me find the exact location:Assistant
Now I need to modify the
process_v_bind_on_elementfunction to:- Change
_eltoel(remove the underscore prefix) - Update the style handling to also merge v-show when present
Let me make these changes:
- Change
Assistant
Now I need to replace the style handling in
process_v_bind_on_element. Let me find the exact lines and replace them:Assistant
I need to replace lines 380-392 with the new code that handles v-show merging. Let me create the replacement:
Assistant
Now let me replace lines 380-392 with this new code. I'll use Python for this multiline replacement:
Assistant
Let me verify the replacement worked:
Assistant
The style handling in
process_v_bind_on_elementis now updated. Now I need to modifyprocess_v_show_on_elementto:- Use
elinstead of_el - Skip emitting if there's a
:stylebinding (since it's handled by that path) - Merge with static style using
_ssrRenderStyleif there's static style - Keep current behavior if no existing style
Let me find and update this function:
- Use
Assistant
Good, I see that the function already has
el: &ElementNode(from my earlier sed change). Now I need to replace the body of this function. Let me do that:Assistant
Let me verify the replacement worked:
Assistant
The
process_v_show_on_elementfunction is now updated. Let me now rebuild and test to see if the changes work:Assistant
The build succeeded. There's a warning about an unused variable in a different function, but that's unrelated to my changes. Let me now rebuild the test binary and test the fix:
Assistant
The fix is working. Let me analyze the results:
-
Case 1 (v-show with static style): Now correctly uses
_ssrRenderStyle(["color:red", v_show_style])- single style attribute! -
Case 2 (v-show with :style binding): Now correctly uses
_ssrRenderStyle([dynamic_style, v_show_style])- single style attribute! -
Case 3 (v-show alone): Still uses the conditional inline approach - unchanged behavior (correct)
-
Case 4 (issue reproduction): Now correctly uses
_ssrRenderStyle(["color:red", v_show_style])- single style attribute!
Now let me run the existing tests to make sure I haven't broken anything:
-
Assistant
All v-show tests pass! Let me also check if the snapshots changed and run the full test suite to make sure nothing else is broken:
Assistant
The tests failed because my change now always wraps the style expression in an array
[_ssrRenderStyle([exp])]even when there's only a single dynamic style binding. The original behavior was_ssrRenderStyle(exp)for a single style, which is also valid. I need to fix this to only use the array form when there are multiple parts to merge.Assistant
The issue is that I always wrap in an array
[{parts_str}]even when there's only one part. The_ssrRenderStylefunction can accept either a single value or an array. When there's only one part, I should use_ssrRenderStyle(exp)instead of_ssrRenderStyle([exp]).Let me fix this:
Assistant
Let me verify the change:
Assistant
The user hasn't sent a new message. Let me continue with my work - I need to rebuild and test to verify my fix works correctly now.
Assistant
All tests pass. Let me rebuild and run my test script to confirm the fix works:
Assistant
All test cases are now working correctly:
- Case 1 (v-show with static style): Now emits
_ssrRenderStyle(["color:red", v_show])- single style attribute ✓ - Case 2 (v-show with :style binding): Now emits
_ssrRenderStyle([dynamic, v_show])- single style attribute ✓ - Case 3 (v-show alone): Still uses the conditional inline approach - unchanged ✓
- Case 4 (issue reproduction): Now emits
_ssrRenderStyle(["color:red", v_show])- single style attribute ✓
Let me also test some edge cases:
- Case 1 (v-show with static style): Now emits
Assistant
Most edge cases work well. Case 4 (multiple v-show directives) shows a problem - when there are multiple v-show directives on the same element, my fix creates duplicate style attributes. However, this is an unusual edge case that's likely invalid Vue template syntax anyway. Let me think about this:
- Case 1 (static + :style + v-show): Works perfectly - all three merged ✓
- Case 2 (class + v-show): Works correctly - no style, so uses conditional inline ✓
- Case 3 (root element): Works correctly - uses inherit_attrs path ✓
- Case 4 (multiple v-show): Creates duplicate styles - but this is invalid Vue syntax
- Case 5 (complex static style + v-show): Works perfectly ✓
For case 4, the fix should handle this gracefully. But first, let me check if this was already a problem before my fix:
Assistant
Let me check the current state of my changes and verify everything is working:
Assistant
All tests pass. Let me clean up the temporary test files and review the final changes:
Assistant
Let me review my changes one final time before submitting:
Assistant
I notice there's an unused variable warning for
elinprocess_custom_directivethat I accidentally introduced. Let me fix that before submitting.Assistant
Let me check what happened and fix it properly:
Assistant
The sed command didn't work as expected. Let me fix this properly:
Assistant
The user hasn't sent a new message. I was in the middle of fixing a warning about an unused variable in the
process_custom_directivefunction. Let me continue by verifying my fix worked and then proceed with the final verification.Assistant
The unused variable is now fixed. Let me run the full test suite one more time to confirm everything passes:
Assistant
All tests pass. Let me review the final diff and verify the fix is complete:
Assistant
The changes look correct. Let me summarize the fix:
Summary of Changes
Problem
process_v_show_on_elementwas unconditionally appending a standalonestyle="display: none;"chunk whenv-showwas false. When an element already had a staticstyleattribute or a:stylebinding, this resulted in twostyleattributes in the generated HTML. The HTML parser keeps only the first one, sodisplay:nonewas dropped andv-showfailed to hide the element.Solution
The fix merges
v-show's style into a single style binding using_ssrRenderStyle:-
Added helper methods (
has_v_show,get_v_show_exp) to detect and retrieve v-show directives on an element. -
Modified
process_element_attrs: Skip emitting staticstyleattribute whenv-showis present (and no binding), so can merge it properly.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.