-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
fix(compiler-core): preserve start/end whitespace nodes in whitespace: 'preserve' mode #13513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(compiler-core): preserve start/end whitespace nodes in whitespace: 'preserve' mode #13513
Conversation
…: 'preserve' mode
WalkthroughWhitespace handling logic in the template parser was updated to distinguish between root and nested elements, refining how whitespace-only text nodes are preserved or removed when using the "preserve" strategy. Corresponding and expanded test cases were added to verify nuanced whitespace preservation in various scenarios, including slot content and comments. Additionally, a new test was added to verify slot behavior with implicit default slots before and after named slots, and an end-to-end test was updated to reflect whitespace preservation in transition group outputs. Changes
Sequence Diagram(s)sequenceDiagram
participant Parser
participant condenseWhitespace
Parser->>condenseWhitespace: condenseWhitespace(nodes, isRoot)
alt isRoot == true
condenseWhitespace->>condenseWhitespace: Remove leading/trailing whitespace nodes
else isRoot == false
condenseWhitespace->>condenseWhitespace: Preserve whitespace nodes at edges
end
condenseWhitespace-->>Parser: Return processed nodes
Assessment against linked issues
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (5)
🔇 Additional comments (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
Another note is that my implementation excludes children of root nodes because in general I think little value is provided by considering root children. It would result in virtually all components having leading and trailing whitespace text nodes if using the recommended Vue template formatting, and would also break the assignment of |
Size ReportBundles
Usages
|
close #7789
This would solve the scenario highlighted in this issue of a single child whitespace-only text node being wiped, and would also more generically handle scenarios like:
<span> <!--comment-->Value<!--comment--> </span>
where the whitespace is currently wiped inpreserve
mode perhaps unexpectedly.Furthermore, I think this behavior change would also closer align with the documented behavior: https://vuejs.org/api/application#app-config-compileroptions-whitespace
This is definitely a more "radical" solution compared to other ones proposed. Some notes/acknowledgements:
preserve
behavior different from Vue 2preserve
behavior (e.g. Vue 2.7.14 strips<span> </span>
to<span></span>
in preserve mode)whitespace: 'preserve'
due to extra whitespace nodesSummary by CodeRabbit
Summary by CodeRabbit
New Features
Tests