Skip to content

fix(teleport): remove stale target anchors after invalid target updates#14600

Merged
edison1105 merged 4 commits intominorfrom
teleport-invalid-target
Mar 17, 2026
Merged

fix(teleport): remove stale target anchors after invalid target updates#14600
edison1105 merged 4 commits intominorfrom
teleport-invalid-target

Conversation

@edison1105
Copy link
Copy Markdown
Member

@edison1105 edison1105 commented Mar 17, 2026

Summary by CodeRabbit

Bug Fixes

  • Fixed teleport component cleanup to properly handle cases where target elements become invalid or unavailable during component lifecycle, ensuring DOM anchors are correctly removed.

Tests

  • Added test coverage validating teleport behavior with invalid or dynamically changing targets, confirming proper anchor cleanup and DOM stability on component unmounting.

@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: fd325c29-228c-49b9-b27f-e55e0cca27dc

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:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch teleport-invalid-target
📝 Coding Plan
  • Generate coding plan for human review comments

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 17, 2026

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 (-8 B) 41.9 kB (-6 B) 37.5 kB (-23 B)
vue.global.prod.js 170 kB (-8 B) 61.7 kB (-5 B) 55 kB (-75 B)

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.8 kB 31 kB 28.1 kB
createVaporApp 28.5 kB 11 kB 10.1 kB
createSSRApp 63.9 kB 24.8 kB 22.5 kB
createVaporSSRApp 31.7 kB 12.3 kB 11.3 kB
defineCustomElement 66.2 kB 25.1 kB 22.8 kB
defineVaporCustomElement 39.1 kB 14.5 kB 13.3 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@14600
npm i https://pkg.pr.new/@vue/compiler-core@14600
yarn add https://pkg.pr.new/@vue/compiler-core@14600.tgz

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/compiler-vapor

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/runtime-vapor

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: e1c2e96

@edison1105 edison1105 force-pushed the teleport-invalid-target branch from bdd995d to e1c2e96 Compare March 17, 2026 03:05
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)

309-314: Non-null assertion relies on paired creation of anchors.

The remove method at line 312 uses a non-null assertion (this.targetAnchor!) within the if (this.targetStart) block, assuming that if targetStart exists, targetAnchor must also exist.

While this is currently safe (both anchors are always created together in mountToTarget and mountChildren), consider guarding targetAnchor removal with its own existence check for defensive coding:

 if (this.targetStart) {
   remove(this.targetStart, parentNode(this.targetStart)!)
   this.targetStart = undefined
+}
+if (this.targetAnchor) {
   remove(this.targetAnchor!, parentNode(this.targetAnchor!)!)
   this.targetAnchor = undefined
 }

This matches the pattern used in the runtime-core implementation at packages/runtime-core/src/components/Teleport.ts:323-328.

🤖 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 309 - 314,
The removal block in Teleport.remove currently uses a non-null assertion on
this.targetAnchor inside the if (this.targetStart) branch; change it to
defensively check for this.targetAnchor before calling remove to avoid assuming
paired creation (referencing methods/fields: Teleport class, targetStart,
targetAnchor, remove, mountToTarget, mountChildren). Update the code so that
after unsetting this.targetStart you only call remove(this.targetAnchor,
parentNode(this.targetAnchor)!) if this.targetAnchor is truthy, then set
this.targetAnchor = undefined, mirroring the defensive pattern used in
runtime-core.
🤖 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 309-314: The removal block in Teleport.remove currently uses a
non-null assertion on this.targetAnchor inside the if (this.targetStart) branch;
change it to defensively check for this.targetAnchor before calling remove to
avoid assuming paired creation (referencing methods/fields: Teleport class,
targetStart, targetAnchor, remove, mountToTarget, mountChildren). Update the
code so that after unsetting this.targetStart you only call
remove(this.targetAnchor, parentNode(this.targetAnchor)!) if this.targetAnchor
is truthy, then set this.targetAnchor = undefined, mirroring the defensive
pattern used in runtime-core.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 635017b2-55b2-4c77-a2fc-ef53e2432703

📥 Commits

Reviewing files that changed from the base of the PR and between f6952b2 and e1c2e96.

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

@edison1105 edison1105 merged commit e7828d4 into minor Mar 17, 2026
16 of 17 checks passed
@edison1105 edison1105 deleted the teleport-invalid-target branch March 17, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant