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 structure to understand the codebase and locate the mentioned files. Let's first check the current directory and list files.
- Assistant
Great, the file is at
./crates/vize_atelier_ssr/src/codegen/element/plain.rs. Let's examine it and look at the lines mentioned (around 490 and 245-254). First, let's open the file and see the structure. Let's also check if there are any tests related to v-show. Let's first look at the plain.rs file. - Assistant
Let's examine the plain.rs file to understand the issue. First, let's look at the structure and locate the relevant functions.
- Assistant
Let's open the file and examine the relevant sections. First, I'll use the open command to view the file.
- Assistant
Let me read the rest of the file, especially around line 490 where
process_v_show_on_elementis mentioned. - Assistant
Let me now look at the full file to understand the context of where
process_v_show_on_elementis called. - Assistant
Now let me look at the
process_directive_on_elementfunction more closely. - Assistant
Now I understand the structure. Let me look at the
process_element_attrsfunction more closely: - Assistant
Let me also check if there are tests to understand the expected behavior. Let me first search for existing tests.
- Assistant
Let me examine the SSR snapshot test file to see if there are any existing tests for v-show:
- Assistant
Let me check the existing snapshots to understand the expected output:
- Assistant
Let me look at the existing snapshots to understand the expected output. I'll check the basic_v_show snapshot first.
- Assistant
Let me check the snapshot for
v_show_with_other_attrs: - Assistant
Let me check the component_with_v_show_merges_style snapshot:
- Assistant
Let me run the existing tests to see the current state:
- Assistant
Let me wait for the test to complete. Let me run it in the background and check results later. First, let me create a reproduction script to understand the issue better. Let me also examine the transforms.rs file to understand how v-show is transformed. Let me look at the transforms.rs file first.
- Assistant
Now I need to understand the full picture. Let me look at the
process_element_attrsfunction more carefully and understand how the v-show directive is currently handled. Let me also check if there's a function to detect if an element has a static style attribute.Let me first understand the structure of the ElementNode and PropNode types:
- Assistant
- Assistant
- Assistant
Now let me understand the full picture. Let me check the helper functions available:
- Assistant
Let me check the imports in plain.rs:
- Assistant
Let me check the
super::*import to see what's available: - Assistant
Let me check the
collect_element_directive_attrfunction at line 245-254 (the one that correctly handles v-show): - Assistant
Now I have a clear picture of the problem. Let me look at how
process_v_bind_on_elementhandles the:stylecase and what helper functions are available: - Assistant
Now I have a clear understanding of the issue. Let me trace through the code:
process_element_attrs(line 103) iterates over element props - it's used for non-root elements (inherit_attrs=false)- When it encounters
v-show, it callsprocess_directive_on_element→process_v_show_on_elementwhich emits a standalonestyle="display: none;" - But if there's already a static
styleor:stylebinding, we get TWOstyleattributes
The fix needs to:
- Skip static
styleattr emission whenv-showis present (like it already skips when:styleis present) - Skip
:styleemission whenv-showis present (let v-show handle merging) - In
process_v_show_on_element, merge the v-show display:none with any existing style
Let me also check for the
quoted_js_stringhelper: - Assistant
Let me find where quoted_js_string is defined:
- Assistant
Let me check the existing helper for getting a static style attribute:
- Assistant
Now I have a complete understanding. Let me implement the fix. The key changes:
- In
process_element_attrs: Add check to skip staticstyleattribute whenv-showis present (like it already does for:style) - In
process_v_show_on_element: Rewrite to check for existing style (static or dynamic) and merge, using_ssrRenderStyle - In
process_v_bind_on_elementfor:stylecase: Skip whenv-showis present (letprocess_v_show_on_elementhandle it)
- In
- Assistant
Now let me implement the fix. I'll make three changes:
- Modify
process_element_attrsto skip staticstylewhen v-show is present - Modify
process_v_show_on_elementto handle merging with existing style - Modify
process_v_bind_on_elementto skip:stylewhen v-show is present
- Modify
- Assistant
Let me try a different approach to edit the file:
- Assistant
I need to open the file first, then use edit:
- Assistant
Now let me edit the file. First, let me go to the relevant section and edit
process_element_attrs: - Assistant
The edit seems to have created a duplicate. Let me revert and redo:
- Assistant
Let me use sed to make precise changes:
- Assistant
Let me use sed for precise line-by-line edits:
- Assistant
Now let me verify and add the
has_v_showcondition to the skip logic: - Assistant
Good. Now I need to add
|| (attr.name == "style" && has_v_show)to the condition. Let me find the exact line: - Assistant
I need to add
|| (attr.name == "style" && has_v_show)after thehas_dynamic_styleline. Let me use sed to insert this line. - Assistant
Good. Now let me verify the first change:
- Assistant
The insertion was placed incorrectly - the
||was put after the{. Let me revert and redo properly: - Assistant
Let me use a Python script to make all three changes at once:
- Assistant
Now let me verify the changes look correct:
- Assistant
Good, change 1 looks correct. Let me verify change 2:
- Assistant
Good, change 2 looks correct. Let me verify change 3:
- Assistant
All three changes look correct. Let me now verify that the changes compile:
- Assistant
The code compiles successfully. Now let me run the tests to see how the changes affect the existing snapshots:
- Assistant
All 68 tests pass! But let me check the existing v-show test snapshots to make sure they still look correct:
- Assistant
Good, the basic_v_show snapshot is unchanged (correct - no existing style, so standalone conditional attribute is used). Let me check the other one:
- Assistant
Good, both existing snapshots are unchanged. Now let me create a reproduction script to verify the fix works for the reported issue:
- Assistant
Let me look at how the existing test infrastructure works to create actual test cases:
- Assistant
Let me create a temporary test script to verify the fix works for the reported issue:
- Assistant
Let me run this test using cargo test:
- Assistant
Let me create a proper test file with #[test] functions:
- Assistant
All 4 new tests pass! Let me see the actual output for each test case:
- Assistant
Excellent! The output looks exactly right:
- Test 1 (v-show with static style): Single merged
styleattribute using_ssrRenderStyle(["color:red", ...display:none...])✓ - Test 2 (v-show with dynamic :style): Single merged
styleattribute ✓ - Test 3 (v-show only): Standalone conditional attribute (unchanged behavior) ✓
- Test 4 (v-show with static + dynamic style): Single merged
styleattribute ✓
Now let me clean up the temporary test file and run the full test suite:
- Test 1 (v-show with static style): Single merged
- Assistant
All 68 existing tests pass. Let me also run any other tests that might be affected:
- Assistant
Let me also check if there are any other tests in the repository that might be affected:
- Assistant
The failing test
build_respects_configured_template_syntax_quirksis in a different package (vize) and is about template syntax quirks, not about v-show. Let me check if this failure existed before my change: - Assistant
Good, the test failure is pre-existing and not related to my changes. Let me restore my changes:
- Assistant
Let me verify the component v-show tests pass as well:
- Assistant
All tests pass. Let me now look at the final diff to review all changes:
- Assistant
The diff looks clean and correct. Let me verify the final code one more time:
- Assistant
Let me run the full SSR test suite one more time to confirm everything is clean:
- Assistant
All 108 tests pass (40 + 68). Let me now do a final review of the complete diff to make sure everything is correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.