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 relevant files. Let me first see what's in the repository.
- Assistant
Let me look at the directory structure first.
- Assistant
Now let's examine the main file mentioned in the issue:
- Assistant
Let me scroll down to see the
process_v_show_on_elementfunction: - Assistant
Let me search for the process_v_show_on_element function:
- Assistant
Let me examine the process_v_show_on_element function:
- Assistant
Now let me look at the collect_element_directive_attr function mentioned in the issue:
- Assistant
Let me see more context around that area:
- Assistant
Let me check where process_v_show_on_element is called:
- Assistant
Let me look at where process_directive_on_element is called:
- Assistant
Now I'll look at the structure of
process_directive_on_elementto see the full list of directives. - Assistant
Let me look at the
process_element_attrsfunction to see how it handles attributes: - Assistant
Let me check if there are any tests related to v-show:
- Assistant
Now I need to create a reproduction script to confirm the error. Let me first check if there's a test suite I can run:
- Assistant
Let me check if there's a way to run tests:
- Assistant
Let me look at the SSR snapshot tests to understand how they work:
- Assistant
Let me check the test snapshots to see what the expected output should be:
- Assistant
Let me check the existing v-show snapshot tests:
- Assistant
Let me check the other v-show snapshot:
- Assistant
Let me understand the full flow. Let me look at how root elements vs non-root elements are processed:
- Assistant
Let me look at the full process_plain_element function:
- Assistant
Let me look at the context around line 278:
- Assistant
Let me look at the full
collect_element_directive_attrfunction: - Assistant
Let me check how
process_v_bind_on_elementworks to understand the pattern: - Assistant
Now I understand the problem fully. Let me create a reproduction script first to confirm the issue:
- Assistant
Let me look at the SSR test file to understand how to run the tests:
- Assistant
Let me look at the component v-show tests:
- Assistant
Let me look at the component_with_v_show_merges_style test:
- Assistant
Let me check the snapshot for component_with_v_show_merges_style:
- Assistant
Let me look at the current v-show tests for plain elements:
- Assistant
Let me look at the component_with_v_show snapshot:
- Assistant
Let me run the existing tests to see if they pass:
- Assistant
Let me wait for the test to finish:
- Assistant
All tests pass. Now let me write a test to reproduce the bug. First, let me understand the issue more clearly by looking at how the existing tests work:
- Assistant
Let me create a simple reproduction by compiling the specific template with static style and v-show:
- Assistant
Let me create a proper test program:
- Assistant
Let me check how compile_ssr is called in the test:
- Assistant
Let me find the compile_ssr function.
- Assistant
Let me check the function signature.
- Assistant
Let me create a proper reproduction script to confirm the issue:
- Assistant
Let me just use the test infrastructure directly. I'll create a temporary test:
- Assistant
Let me check the test files in the crate:
- Assistant
Let me check the tests in lib.rs:
- Assistant
Let me look at the snapshot for the basic v-show test:
- Assistant
Now I have a clear understanding of the problem. Let me check if there's a helper to detect v-show on an element:
- Assistant
Let me look at the helper functions:
- Assistant
Let me check what's imported in plain.rs:
- Assistant
Let me check what's in the super module:
- Assistant
Let me find the parent module file.
- Assistant
Let me look at the codegen module to see what
super::*imports: - Assistant
Let me check the element.rs file:
- Assistant
Let me check what's available from the parent module:
- Assistant
Let me check if
has_v_showis accessible from the codegen module: - Assistant
Let me check if
has_v_showis accessible from the codegen module. Let me look at how the crate is structured: - Assistant
Now I have a clear understanding of the problem. Let me look at the
quoted_js_stringfunction that's used inprocess_v_bind_on_element: - Assistant
Let me look at
quoted_js_string: - Assistant
Now I understand the full picture. Let me implement the fix. The plan is:
- Modify
process_element_attrsto skip staticstyleattribute when the element hasv-show(similar to how it's skipped when there's a dynamic:stylebinding) - Modify
process_v_show_on_elementto check for existing style attributes and merge them properly
Let me first look at the full
process_v_show_on_elementfunction and surrounding context: - Modify
- Assistant
Now let me understand how
process_v_bind_on_elementhandles:style: - Assistant
Now I have a complete understanding of the problem. Let me implement the fix. I'll modify
process_v_show_on_elementto check for existing style attributes and merge them: - Assistant
Now I have a complete understanding of the problem. The fix requires three coordinated changes:
- In
process_element_attrs: skip staticstyleattribute whenv-showis present (so it doesn't get emitted separately) - In
process_v_bind_on_elementfor:style: include v-show condition in the style array when both exist - In
process_v_show_on_element: handle merging with existing styles instead of emitting standalone style
Let me implement the fix:
- In
- Assistant
Let me check the imports and what helpers are available:
- Assistant
Let me check the props module:
- Assistant
Now I understand the codebase. Let me now implement the fix. The approach is:
- Modify
process_v_show_on_elementto check for existing style attributes and merge them - When there's a static
styleattribute, skip it inprocess_element_attrsand merge it inprocess_v_show_on_element - When there's a
:stylebinding, handle the merging inprocess_v_show_on_element
Let me start by modifying
process_element_attrsto skip staticstylewhenv-showis present: - Modify
- Assistant
Good. Now I need to modify
process_v_show_on_elementto handle merging with existing styles. Let me look at the current function: - Assistant
Now I need to modify
process_v_show_on_elementto handle merging with existing styles. The function needs to:- Check if the element has a static
styleattribute - Check if the element has a
:stylebinding - If there's a
:stylebinding, skip standalone emission (the:stylebinding handler will merge it) - If there's a static
styleattribute, merge them into a single style attribute - If neither, emit the standalone style as before
Let me implement this:
- Check if the element has a static
- Assistant
I see there's an issue with the edit. Let me check the file:
- Assistant
The "Process a custom directive" function signature got mangled. Let me fix it:
- Assistant
I see the function is missing
&mut self. Let me fix it: - Assistant
Good. Now I need to also handle the case where
:styleis present ANDv-showis present. I need to modifyprocess_v_bind_on_elementto include the v-show condition when processing:style. Let me look at that function: - Assistant
Now I need to modify
process_v_bind_on_elementfor the:stylecase to include the v-show condition when the element has v-show. Let me update the:stylecase: - Assistant
I see there's an extra
}at line 406. Let me fix that: - Assistant
I see there's still an extra
}. Let me check the context: - Assistant
I need to remove the extra
}on line 406: - Assistant
Let me verify the complete
process_v_bind_on_elementfunction: - Assistant
Good. Let me also verify the
process_v_show_on_elementfunction: - Assistant
Good. Now let me compile to see if there are any syntax errors:
- Assistant
Great, it compiles without errors! Now let me run the tests:
- Assistant
All tests pass! Now let me create a test to verify the fix works correctly. Let me write a test program to see the generated output:
- Assistant
Let me just add a temporary test to the existing test file:
- Assistant
Let me add a temporary test to verify the fix:
- Assistant
Let me add a temporary test to the existing test file to see the output:
- Assistant
Let me fix the test format:
- Assistant
Excellent! The fix is working correctly. Let me also test the case where both static and dynamic styles exist:
- Assistant
Perfect! All test cases pass. Let me clean up the temp test file and run all existing tests to make sure nothing is broken:
- Assistant
I need to remove the appended test code from ssr_snapshot.rs:
- Assistant
Now let me run the tests again:
- Assistant
All 68 tests pass! Let me also check if there are any other tests in the repository that might be affected:
- Assistant
Let me also run the snapshot tests to make sure they still pass:
- Assistant
Let me also check if there are any other crates that might be affected:
- Assistant
There's a test failure in
build_respects_configured_template_syntax_quirksbut it seems unrelated to my changes. Let me check if it was already failing before my changes: - Assistant
Good, the test was already failing before my changes. Let me restore my changes:
- Assistant
Good, the pre-existing test failure is unrelated to my changes. Now let me also check if there are any other edge cases I should consider. Let me also look at how the fix handles
v-showwithv-bind:style(shorthand:style): - Assistant
Let me run the specific tests in the main crate's lib.rs to check for v_show:
- Assistant
Let me also verify that the fix handles the case where
v-showis used withv-bind:style(the long form of:style): - Assistant
Let me also verify that the fix doesn't break the case where
v-showis used withv-if: - Assistant
All edge case tests pass! Let me clean up the temp test file:
- Assistant
Let me run the full test suite for the atelier_ssr crate one more time to make sure everything is working correctly:
- Assistant
Let me also check if there are any other crates that depend on vize_atelier_ssr to make sure my changes don't break anything:
- Assistant
Let me verify the fix by looking at the final state of the code:
- Assistant
The diff looks correct. Let me now also verify that the fix handles the case where
v-showis used withv-bind:style(the long form). Looking at the code,v-bind:styleis processed by the same code path as:style, so it should work correctly.Let me also run a quick check to make sure the fix doesn't break any other tests in the workspace:
- Assistant
All tests pass. Let me now review the final state of my changes:
- Assistant
Let me now create a final summary of the changes I made. Let me also verify the fix one more time by looking at the actual output for the reproduction case from the issue:
- Assistant
Let me verify the final state of the code by looking at the complete modified function:
- Assistant
The code looks good. Let me now run one final comprehensive test to make sure everything is working correctly:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.