fix(Teleport): nested teleport should use parent css vars
close #11022
Summary by CodeRabbit
-
New Features
- Improved support for CSS variable propagation in complex component structures, including nested Teleport components.
-
Bug Fixes
- Enhanced reliability of CSS variable updates on teleported elements.
-
Tests
- Added a test to verify correct CSS variable application in nested Teleport scenarios.
-
Refactor
- Updated internal handling of CSS variable updaters for better scalability and maintainability.
Size Report
Bundles
| File | Size | Gzip | Brotli |
|---|---|---|---|
| runtime-dom.global.prod.js | 101 kB (+276 B) | 38.4 kB (+108 B) | 34.6 kB (+113 B) |
| vue.global.prod.js | 159 kB (+276 B) | 58.6 kB (+96 B) | 52.2 kB (+196 B) |
Usages
| Name | Size | Gzip | Brotli |
|---|---|---|---|
| createApp (CAPI only) | 46.8 kB (+186 B) | 18.3 kB (+59 B) | 16.7 kB (+51 B) |
| createApp | 54.7 kB (+186 B) | 21.3 kB (+62 B) | 19.5 kB (+51 B) |
| createSSRApp | 59 kB (+186 B) | 23 kB (+53 B) | 21 kB (+50 B) |
| defineCustomElement | 59.7 kB (+186 B) | 22.9 kB (+68 B) | 20.9 kB (+58 B) |
| overall | 68.8 kB (+186 B) | 26.5 kB (+55 B) | 24.1 kB (+49 B) |
When the slot does not use style vars, should avoid changing the dom.
When the slot does not use style vars, should avoid changing the dom.
When the Teleport does not use style vars, it alse changes the dom. So I think this is ok
Is there a chance to merge it soon? 👉👈
@yyx990803 I beg You 😭
@vue/compiler-core
npm i https://pkg.pr.new/@vue/compiler-core@11023
@vue/compiler-dom
npm i https://pkg.pr.new/@vue/compiler-dom@11023
@vue/compiler-ssr
npm i https://pkg.pr.new/@vue/compiler-ssr@11023
@vue/compiler-sfc
npm i https://pkg.pr.new/@vue/compiler-sfc@11023
@vue/reactivity
npm i https://pkg.pr.new/@vue/reactivity@11023
@vue/runtime-core
npm i https://pkg.pr.new/@vue/runtime-core@11023
@vue/runtime-dom
npm i https://pkg.pr.new/@vue/runtime-dom@11023
@vue/server-renderer
npm i https://pkg.pr.new/@vue/server-renderer@11023
@vue/shared
npm i https://pkg.pr.new/@vue/shared@11023
vue
npm i https://pkg.pr.new/vue@11023
@vue/compat
npm i https://pkg.pr.new/@vue/compat@11023
commit: db5a86b
For deeply nested Teleport, it still doesn't work. see Playground
Walkthrough
The changes refactor the handling of CSS variable propagation for Teleport components, updating the internal structure from a single updater function to an array of updater objects with unique IDs and update methods. The update also adds a test to verify correct CSS variable application in nested Teleport scenarios.
Changes
| File(s) | Change Summary |
|---|---|
| packages/runtime-core/src/component.ts | Changed ComponentInternalInstance.ut from an optional function to an optional array of { uid, update } objects. |
| packages/runtime-core/src/components/Teleport.ts | Refactored to iterate over ctx.ut array, setting unique attributes and calling each updater's update method for teleported nodes. |
| packages/runtime-core/src/vnode.ts | Added updateUt function to propagate and merge ut arrays from parent to vnode for components and teleports during vnode creation. |
| packages/runtime-dom/src/helpers/useCssVars.ts | Refactored CSS vars updater from a single function to an array of updater objects; updated attribute selector and propagation logic. |
| packages/runtime-dom/tests/helpers/useCssVars.spec.ts | Added a test case verifying correct CSS variable propagation in nested Teleport scenarios. |
Sequence Diagram(s)
sequenceDiagram
participant ParentComponent
participant ChildComponent
participant Teleport
participant DOM
ParentComponent->>ChildComponent: Render (with useCssVars)
ChildComponent->>Teleport: Render Teleport with content
Teleport->>DOM: Move content to target
ChildComponent->>Teleport: Provide ut updater array
Teleport->>DOM: Set data-v-owner-<uid> attributes
ChildComponent->>Teleport: Call each ut.update()
Teleport->>DOM: Apply CSS vars to teleported nodes
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Ensure style vars (CSS variables) work with Teleport components nested within other components (#11022) | ✅ |
Poem
A rabbit hopped through Teleport’s gate,
With CSS vars that wouldn’t propagate.
Now updaters abound, each with their own key,
Ensuring the styles flow perfectly.
Nested or wrapped, the colors don’t fade—
Thanks to this patch, the bug’s been waylaid!
🐇✨
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need 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)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
