Skip to content

fix(teleport): reapply teleport css vars after root replacement#14594

Merged
edison1105 merged 2 commits intominorfrom
edison/fix/teleportCssVars
Mar 17, 2026
Merged

fix(teleport): reapply teleport css vars after root replacement#14594
edison1105 merged 2 commits intominorfrom
edison/fix/teleportCssVars

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented Mar 17, 2026

Summary by CodeRabbit

  • New Features

    • Introduced useVaporCssVars public API to enable reactive CSS variable propagation in teleported elements.
  • Bug Fixes

    • Fixed CSS variable updates failing to reapply correctly when root children of teleported elements are replaced, ensuring reactive state changes propagate properly.
  • Tests

    • Added test coverage verifying CSS variable reapplication in teleported elements.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb3e3e2c-bc2b-4f97-8445-7bac3fbdee25

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/fix/teleportCssVars
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@edison1105 edison1105 changed the title fix(runtime-vapor): reapply teleport css vars after root replacement fix(teleport): reapply teleport css vars after root replacement Mar 17, 2026
@edison1105 edison1105 added scope: teleport scope: vapor related to vapor mode labels Mar 17, 2026
@github-actions
Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.4 kB 30.2 kB 26.6 kB
runtime-dom.global.prod.js 111 kB 41.9 kB 37.6 kB
vue.global.prod.js 170 kB 61.7 kB 55 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 50.6 kB 19.8 kB 18 kB
createApp 59.6 kB 23.1 kB 21 kB
createApp + vaporInteropPlugin 83.6 kB 31 kB 28 kB
createVaporApp 28.4 kB 11 kB 10.1 kB
createSSRApp 63.9 kB 24.8 kB 22.5 kB
createVaporSSRApp 31.6 kB 12.2 kB 11.2 kB
defineCustomElement 66.2 kB 25.1 kB 22.8 kB
defineVaporCustomElement 39 kB 14.4 kB 13.2 kB
overall 74.5 kB 28.4 kB 25.8 kB

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14594
npm i https://pkg.pr.new/@vue/compiler-core@14594
yarn add https://pkg.pr.new/@vue/compiler-core@14594.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14594
npm i https://pkg.pr.new/@vue/compiler-dom@14594
yarn add https://pkg.pr.new/@vue/compiler-dom@14594.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14594
npm i https://pkg.pr.new/@vue/compiler-sfc@14594
yarn add https://pkg.pr.new/@vue/compiler-sfc@14594.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14594
npm i https://pkg.pr.new/@vue/compiler-ssr@14594
yarn add https://pkg.pr.new/@vue/compiler-ssr@14594.tgz

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@14594
npm i https://pkg.pr.new/@vue/compiler-vapor@14594
yarn add https://pkg.pr.new/@vue/compiler-vapor@14594.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14594
npm i https://pkg.pr.new/@vue/reactivity@14594
yarn add https://pkg.pr.new/@vue/reactivity@14594.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14594
npm i https://pkg.pr.new/@vue/runtime-core@14594
yarn add https://pkg.pr.new/@vue/runtime-core@14594.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14594
npm i https://pkg.pr.new/@vue/runtime-dom@14594
yarn add https://pkg.pr.new/@vue/runtime-dom@14594.tgz

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@14594
npm i https://pkg.pr.new/@vue/runtime-vapor@14594
yarn add https://pkg.pr.new/@vue/runtime-vapor@14594.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14594
npm i https://pkg.pr.new/@vue/server-renderer@14594
yarn add https://pkg.pr.new/@vue/server-renderer@14594.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14594
npm i https://pkg.pr.new/@vue/shared@14594
yarn add https://pkg.pr.new/@vue/shared@14594.tgz

vue

pnpm add https://pkg.pr.new/vue@14594
npm i https://pkg.pr.new/vue@14594
yarn add https://pkg.pr.new/vue@14594.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14594
npm i https://pkg.pr.new/@vue/compat@14594
yarn add https://pkg.pr.new/@vue/compat@14594.tgz

commit: 8f08934

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/runtime-vapor/__tests__/components/Teleport.spec.ts (1)

1452-1488: Consider adding an assertion for initial CSS var state.

The test currently only verifies CSS vars after the toggle. Adding an assertion before showAlt.value = true would ensure CSS vars are correctly applied on initial render as well, providing more complete coverage.

💡 Suggested improvement
   }).render()
   await nextTick()
 
+  // Verify initial CSS vars are applied
+  const initialEl = target.firstElementChild as HTMLElement
+  expect(initialEl.tagName).toBe('SPAN')
+  expect(initialEl.style.getPropertyValue('--color')).toBe('red')
+
   showAlt.value = true
   await nextTick()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/__tests__/components/Teleport.spec.ts` around lines
1452 - 1488, Add an assertion verifying the initial teleported node's CSS var
and element before toggling: after the first await nextTick() (right after
render) check target.firstElementChild is a SPAN, has a data-v-owner attribute,
and that its style.getPropertyValue('--color') equals 'red' so use the existing
variables (target, state, showAlt, useVaporCssVars, VaporTeleport, teleported)
to locate the initial element and assert its CSS var is applied before changing
showAlt.value.
packages/runtime-vapor/src/components/Teleport.ts (1)

155-171: Minor: forEach callback return value flagged by linter.

The static analysis tool flags line 166 for returning a value from forEach callback. While functionally harmless (forEach ignores return values), the same pattern exists in initChildren (lines 135-137), so this is consistent with existing code.

If you want to address the linter warning for both locations:

🔧 Suggested fix
       block.forEach(
-          node => isVaporComponent(node) && (node.parentTeleport = this),
+          node => {
+            if (isVaporComponent(node)) node.parentTeleport = this
+          },
       )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/src/components/Teleport.ts` around lines 155 - 171,
The linter flags returning a value from the forEach callback in bindChildren
(and the similar pattern in initChildren); change the arrow callback from an
expression using && that returns the assignment to a block that performs the
assignment without returning (e.g. node => { if (isVaporComponent(node))
node.parentTeleport = this } ) so the callback has no return value; update both
bindChildren and initChildren to use this explicit if-block (or a for...of loop)
while keeping the same conditions and assignment to parentTeleport.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/runtime-vapor/__tests__/components/Teleport.spec.ts`:
- Around line 1452-1488: Add an assertion verifying the initial teleported
node's CSS var and element before toggling: after the first await nextTick()
(right after render) check target.firstElementChild is a SPAN, has a
data-v-owner attribute, and that its style.getPropertyValue('--color') equals
'red' so use the existing variables (target, state, showAlt, useVaporCssVars,
VaporTeleport, teleported) to locate the initial element and assert its CSS var
is applied before changing showAlt.value.

In `@packages/runtime-vapor/src/components/Teleport.ts`:
- Around line 155-171: The linter flags returning a value from the forEach
callback in bindChildren (and the similar pattern in initChildren); change the
arrow callback from an expression using && that returns the assignment to a
block that performs the assignment without returning (e.g. node => { if
(isVaporComponent(node)) node.parentTeleport = this } ) so the callback has no
return value; update both bindChildren and initChildren to use this explicit
if-block (or a for...of loop) while keeping the same conditions and assignment
to parentTeleport.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0520833f-34b7-4c0b-952b-d299b65640ff

📥 Commits

Reviewing files that changed from the base of the PR and between 5d6814f and b0826dd.

📒 Files selected for processing (2)
  • packages/runtime-vapor/__tests__/components/Teleport.spec.ts
  • packages/runtime-vapor/src/components/Teleport.ts

@edison1105 edison1105 force-pushed the edison/fix/teleportCssVars branch from b0826dd to b981bb7 Compare March 17, 2026 00:18
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/runtime-vapor/src/components/Teleport.ts (1)

149-153: Avoid returning values from forEach callbacks.

The && expression returns a value that forEach ignores. Use an explicit conditional for clarity.

♻️ Suggested fix
       } else if (isArray(block)) {
-        block.forEach(
-          node => isVaporComponent(node) && (node.parentTeleport = this),
-        )
+        block.forEach(node => {
+          if (isVaporComponent(node)) {
+            node.parentTeleport = this
+          }
+        })
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/runtime-vapor/src/components/Teleport.ts` around lines 149 - 153,
The forEach callback is using a short-circuit expression that returns a value
(block.forEach(node => isVaporComponent(node) && (node.parentTeleport = this))),
which is ignored and unclear; change the callback to an explicit conditional so
it doesn't return a value — e.g., in the Teleport code path that checks
isArray(block) replace the arrow expression with a body that does if
(isVaporComponent(node)) { node.parentTeleport = this } to set parentTeleport
without returning a value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/runtime-vapor/src/components/Teleport.ts`:
- Around line 149-153: The forEach callback is using a short-circuit expression
that returns a value (block.forEach(node => isVaporComponent(node) &&
(node.parentTeleport = this))), which is ignored and unclear; change the
callback to an explicit conditional so it doesn't return a value — e.g., in the
Teleport code path that checks isArray(block) replace the arrow expression with
a body that does if (isVaporComponent(node)) { node.parentTeleport = this } to
set parentTeleport without returning a value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2bbd577b-7aba-4374-bbb6-69ed16612225

📥 Commits

Reviewing files that changed from the base of the PR and between b0826dd and b981bb7.

📒 Files selected for processing (2)
  • packages/runtime-vapor/__tests__/components/Teleport.spec.ts
  • packages/runtime-vapor/src/components/Teleport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/runtime-vapor/tests/components/Teleport.spec.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: teleport scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant