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
I'll start by exploring the repository structure and understanding the codebase, then reproduce the issue and implement a fix.
Assistant
The user seems to have encountered an error. Let me try a different approach to open the file.
Assistant
Let me continue reading the file to find the relevant sections mentioned in the issue.
Assistant
I found the
collect_element_directive_attrfunction. Now let me look at theprocess_v_show_on_elementfunction around line 479-493.Assistant
Now I can see the issue clearly. The
process_v_show_on_elementfunction at line 479-493 unconditionally emits a standalonestyle="display: none;"chunk, which causes duplicate style attributes when the element already has astyleattribute or:stylebinding.Let me look at how the element attributes are processed to understand the context better.
Assistant
Now let me see where
process_v_show_on_elementis called from:Assistant
Now let me check how the code determines if there's an existing style attribute or binding:
Assistant
Now let me check how the
process_v_bind_on_elementhandles style bindings to understand the correct pattern:Assistant
Now I understand the issue. Let me look at the test files to understand how tests are structured:
Assistant
Let me look at the existing v_show test files to understand the expected behavior:
Assistant
Let me check the other v_show snapshots to understand the expected behavior.
Assistant
Now let me check if there are tests that check for the bug - v-show with existing style attribute.
Assistant
This is interesting - for components, the style is properly merged! This is the "single-root path" mentioned in the issue. Let me also check the test file to understand the test structure:
Assistant
Now I need to look at the v_show tests to see what tests exist and understand the structure better.
Let me look at the v_show tests:
Assistant
Now let me create a reproduction script to confirm the bug:
Assistant
Let me create a reproduction script:
Assistant
Let me create a proper test using the existing test infrastructure:
Assistant
Good, the tests pass. Now let me write a simple test script to reproduce the issue:
Assistant
Now let me add a temporary test case to the existing test file and run it to confirm the bug:
Assistant
Let me create a standalone test to confirm the bug:
Assistant
Interesting! When using
compile_full(which compiles the full template without wrapping in a div), the style IS being merged correctly. Let me check what happens when the element is wrapped (like inget_compiled_string):Assistant
I've confirmed the bug. The issue is clear:
- Root element (Test 1): Style is correctly merged via
_mergeProps - Nested element (Test 2): Two style attributes are emitted:
style="color:red"+ conditionalstyle="display: none;" - Nested with :style (Test 3): The v-show style comes before the bound style, breaking it
Now let me understand the code flow better and implement the fix:
- Root element (Test 1): Style is correctly merged via
Assistant
Now I understand the fix. Looking at how
process_v_bind_on_elementhandles style at line 378-390:- It emits
style="as a static prefix - It uses
_ssrRenderStyle()to merge the static style (if any) with the dynamic expression - It closes with
"
For
process_v_show_on_element, I need to:- Check if there's an existing static
styleattribute - Check if there's a dynamic
:stylebinding - If either exists, merge v-show into the style using
_ssrRenderStyle() - If neither exists, emit the current conditional approach (but as a proper style attribute)
Let me look at how Vue handles this. Let me check what the component path does:
- It emits
Assistant
Good. Now I understand the fix. For the element path, when there's an existing style, I should use
_ssrRenderStyle()to merge the v-show into the style binding.Let me implement the fix:
Assistant
I see that when there's a dynamic style binding, the static style attribute is skipped. Now let me implement the fix for
process_v_show_on_element:Assistant
Now I need to understand the proper fix. The issue is:
- When there's a static
styleattribute AND v-show, the current code emits two style attributes - When there's a
:stylebinding AND v-show, the current code emits the v-show style first, then the bound style
The fix should:
- Check if there's an existing static
styleattribute or dynamic:stylebinding - If so, merge v-show into the style binding using
_ssrRenderStyle() - If not, emit a proper style attribute with v-show logic
Let me look at how the
_ssrRenderStylehelper works in Vue's SSR:- When there's a static
Assistant
Now let me implement the fix. The key insight is:
- When there's an existing style (static or dynamic), we should emit a single
style="..."attribute that uses_ssrRenderStyle()to merge everything - The v-show should be added as
((expr) ? null : { display: 'none' })to the style array
Let me write the fix:
- When there's an existing style (static or dynamic), we should emit a single
Assistant
error None
Assistant
Now I need to implement the fix. The strategy is:
- Check if element has static
styleattribute or dynamic:stylebinding - If yes, emit a single
style="..."using_ssrRenderStyle()to merge existing style with v-show - If no, emit the conditional v-show style (but in a cleaner way)
- Check if element has static
Assistant
I need to fix the edit command syntax. Let me use the correct format with the file path and line range properly specified.
Assistant
I need to use the correct edit command format. Looking at the usage, it seems the edit command needs the LINE_RANGE first, then the REPLACEMENT_TEXT. Let me try a different approach.
Assistant
The issue is that the edit command doesn't seem to be parsing my arguments correctly. Let me try using the syntax from the examples in the system prompt:
Assistant
The edit command removed the function entirely instead of replacing it with new content. I need to re-add the
process_v_show_on_elementfunction. Let me check what happened and fix it properly.Assistant
I see - the function was deleted. Let me revert and try again with proper syntax:
Assistant
Now let me use the proper heredoc syntax to make the edit:
Assistant
Now let me test if the fix works:
Assistant
The fix is not working correctly yet. I see two issues:
-
Test 2: The static style
style="color:red"is still being emitted separately, and then the merged style is also emitted. This is because the static style attribute is processed before the v-show directive inprocess_element_attrs. -
Test 3: When there's a
:stylebinding, both v-show and the dynamic style binding emit separatestyle="..."attributes.
The root cause is that
process_element_attrsprocesses props in order:- First, it emits static
style="color:red" - Then, it calls
process_directive_on_elementwhich callsprocess_v_show_on_element
When
has_dynamic_styleis true, the static style is skipped (see line 114), but when there's only a static style (no dynamic binding), the static style is emitted first.The fix needs to be smarter. When there's a static style AND v-show (but no dynamic style binding), the static style should be skipped in
process_element_attrs, and v-show should handle merging everything.Let me look at how the code handles this for class:
-
Assistant
I see! The logic at line 113-116 skips the static
styleattribute when there's a dynamic:stylebinding. But this doesn't account for v-show.I need to also skip the static
styleattribute when there's a v-show directive, because v-show will handle merging the style. Let me update the logic:Assistant
Good, there's a
has_v_showfunction I can use. Let me check if it's available in the crate:Assistant
Now I need to update
process_element_attrsto also skip staticstylewhen there's v-show:Assistant
main.rs:
Assistant
I notice there's a duplicate line at 119-120 - let me fix that:
Assistant
The edit command replaces lines 119:120, which means it will merge those two identical lines into one. But I notice it's still processing the v-show through
process_directive_on_element. Since we're now skipping the static style attribute when v-show is present, we also need to handle the case where a dynamic:stylebinding is processed - we need to make sure v-show doesn't emit its own style attribute when:styleis already present, because:stylewill be processed separately.Actually, wait. Let me think about this more carefully. The issue is:
-
When there's a static
style="color:red"andv-show="ok":- Before fix:
style="color:red"is emitted, then v-show emitsstyle="display:none"(duplicate!) - After my fix:
style="color:red"is skipped, v-show emitsstyle="${_ssrRenderStyle(["color:red", ...])}"✓
- Before fix:
-
Assistant
I see! The
process_v_bind_on_elementfor style checks if there's a static style and merges it. So when we have:- Static
style="color:red"+:style="{ color }": the static style is skipped inprocess_element_attrs, andprocess_v_bind_on_elementmerges both.
But when we have:
v-show="ok"+:style="{ color }":- v-show is processed first, emitting its style
:styleis processed second, emitting its own style
The problem is the order. Let me think about this differently...
Actually, the issue is that when there's a dynamic
:stylebinding, v-show should NOT emit its own style attribute. Instead, the v-show style should be merged into the:stylebinding.But that would require modifying how
:stylebinding is processed to include v-show, which is more complex.- Static
Assistant
In the component path, v-show adds a style entry to the props, and they get merged through
_mergeProps. This works because all style entries end up in the same props object.For the element path, we're emitting string chunks, not props. So the challenge is how to merge v-show with a dynamic
:stylebinding.Looking at Vue's actual SSR output, when you have
:style="obj"andv-show="cond", Vue emits something like:style="${_ssrRenderStyle([obj, cond ? null : {display:'none'}])}"So the
:stylebinding needs to know about v-show and include it. Let me modifyprocess_v_bind_on_elementto include v-show when processing style:Assistant
Now I understand the approach better. When there's a
:stylebinding AND v-show:- v-show should NOT emit its style (because
:stylewill handle it) :styleshould include v-show in its style array
So my fix for
process_v_show_on_elementshould:- If there's a dynamic
:stylebinding, skip emitting (let:stylehandle it) - If there's only a static style, merge it with v-show
- If there's no style at all, emit the conditional style
And I also need to modify
process_v_bind_on_elementto include v-show when processing style.Let me update the approach. First, let me revert my current changes and implement a cleaner solution:
- v-show should NOT emit its style (because
Assistant
Let me think about this more carefully. The simplest approach that matches Vue's SSR behavior:
- When there's only static
style="..."+v-show: Skip static style, emit_ssrRenderStyle(["static", v-show]) - When there's
:style="..."+v-show: Skip v-show processing, and modify:styleto include v-show - When there's static
style="..."+:style="..."+v-show: Skip static style, emit:stylewith both static and v-show
The cleanest solution is to:
- Skip v-show processing if there's a
:stylebinding (let:stylehandle it) - Modify
:styleprocessing to check for v-show and include it - Skip static style if there's v-show or
:style, and let the first one that processes handle the merging
Actually, the simplest approach:
- Skip static style when there's v-show
- In v-show, if there's a static style, include it in the render
- In
:style, if there's v-show, include v-show in the render - In v-show, if there's
:style, skip (let handle it)
- When there's only static
Assistant
Let me implement the fix step by step:
Step 1: Skip static style when there's v-show (so v-show can handle merging):
Assistant
Step 2: Update
process_v_show_on_elementto:- If there's a
:stylebinding, skip (let:stylehandle v-show) - If there's a static style, merge it
- Otherwise, emit conditional style
- If there's a
Assistant
Step 3: Update
process_v_bind_on_elementfor style to include v-show when present:Assistant
I need to update the style binding to also include v-show:
Assistant
Wait, I see an issue with my code. The
cstr!macro takes format args, but I'm trying to use it with a string slice. Let me check how to properly use it:Assistant
continue
Assistant
I see -
cstr!usesformat_args!so it can take format arguments. But my issue is thatpartsis a String, and I'm trying to use.as_str()which should work. Let me check if my code compiles:Assistant
It compiles. Now let me run the test to see if the fix works:
Assistant
The fix is working! Let me analyze the output:
- Test 1 (root element): Still uses
_mergePropsfor style - correct ✓ - Test 2 (nested with static style): Now uses
_ssrRenderStyle(["color:red", ...])- FIXED! ✓ - Test 3 (nested with dynamic :style): Now uses
_ssrRenderStyle([{ color: _ctx.color }, ...])- FIXED! ✓ - Test 4 (component): Still uses
_mergeProps- correct ✓
All cases now emit a single
styleattribute! Let me run the existing tests to make sure I didn't break anything:- Test 1 (root element): Still uses
Assistant
All v_show tests pass. But wait - the snapshots may need to be updated since the output has changed. Let me check the snapshot content:
Assistant
The test for
basic_v_showpasses, which means that the snapshot for the case without static style still uses the conditional approach (which is correct - we only changed the behavior when there's an existing style).Let me check the
v_show_with_other_attrssnapshot:Assistant
This case has
id="foo"(not a style attribute), so it correctly still uses the conditional approach. Now let me run ALL tests to make sure nothing is broken:Assistant
All 108 tests pass. Now let me also add a test case to verify the fix handles edge cases. Let me also test a few more scenarios to make sure the fix is robust:
Assistant
The test passed and I need to continue with the next step. Let me run the existing tests to make sure nothing is broken.
Assistant
All 108 tests pass. Let me clean up the test file I created and review the final changes.
Assistant
The diff looks clean. Let me now summarize the changes and verify everything is working correctly before submitting.
Summary of Changes:
-
Line 114: Skip static
styleattribute when element has v-show (similar to how it's skipped for dynamic:style) -
Lines 378-410 (
process_v_bind_on_elementfor style): When processing:stylebinding, also include v-show's style contribution if present -
Lines 478-528 (
process_v_show_on_element):- Skip v-show processing if there's a
:stylebinding (let:stylehandle it) - If there's a static style, merge it with v-show using
_ssrRenderStyle() - Otherwise, emit conditional style attribute (existing behavior)
- Skip v-show processing if there's a
Let me verify that my fix properly handles all edge cases by creating one more comprehensive test:
-
Assistant
The previous command failed because the shell script had a syntax error - the line continuation for the
containscheck got split incorrectly. Let me fix this by creating a proper test file directly.Assistant
The test passed, showing the fix works. Let me clean up the test file and verify the final state of the changes.
Assistant
All tests pass and the fix is working correctly. Let me submit the changes now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.