core icon indicating copy to clipboard operation
core copied to clipboard

fix(Teleport): nested teleport should use parent css vars

Open linzhe141 opened this issue 1 year ago • 8 comments

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.

linzhe141 avatar May 27 '24 03:05 linzhe141

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)

github-actions[bot] avatar May 27 '24 11:05 github-actions[bot]

When the slot does not use style vars, should avoid changing the dom. image

edison1105 avatar May 29 '24 09:05 edison1105

When the slot does not use style vars, should avoid changing the dom. image


When the Teleport does not use style vars, it alse changes the dom. So I think this is ok

image

linzhe141 avatar May 29 '24 12:05 linzhe141

Is there a chance to merge it soon? 👉👈

Rusinas avatar Jun 16 '24 13:06 Rusinas

@yyx990803 I beg You 😭

Rusinas avatar Aug 13 '24 00:08 Rusinas

Open in StackBlitz

@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

pkg-pr-new[bot] avatar Oct 15 '24 05:10 pkg-pr-new[bot]

For deeply nested Teleport, it still doesn't work. see Playground

edison1105 avatar Oct 15 '24 06:10 edison1105

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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

coderabbitai[bot] avatar May 22 '25 09:05 coderabbitai[bot]