ISSUE DESCRIPTION Teleport + Suspense: unmount crashes on pending teleport with…
- User
ISSUE DESCRIPTION
Teleport + Suspense: unmount crashes on pending teleport with component child (regression since 3.5.31)
Vue version
3.5.34
Link to minimal reproduction
https://github.com/pont1s/vue-teleport-unmount-crashes
Steps to reproduce
Option 1 — Browser (primary)
pnpm dev- Open the browser DevTools console.
- Click "Unmount Suspense".
- Observe
TypeError: Cannot read properties of null (reading 'type')in the console
Option 2 — Tests (additional)
pnpm testThe repo also contains three Vitest tests in
tests/teleport-unmount.test.jsWhat is expected?
When a inside a is unmounted before its mount can run, Vue should remove it cleanly. This worked correctly in 3.5.30.
What is actually happening?
In 3.5.31..3.5.34, unmounting such a teleport throws:
TypeError: Cannot read properties of null (reading 'type') at unmountComponent (runtime-core.cjs.js) at unmount at Object.remove (TeleportImpl.remove) at unmount at unmountChildren at unmount at unmountComponent at unmount at Object.resolve (Suspense)System Info
System: OS: macOS 26.3.1 CPU: (8) arm64 Apple M1 Memory: 102.19 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.15.0 - /Users/user/.local/state/fnm_multishells/14407_1779493498078/bin/node npm: 11.12.1 - /Users/user/.local/state/fnm_multishells/14407_1779493498078/bin/npm pnpm: 11.1.3 - /Users/user/.local/state/fnm_multishells/14407_1779493498078/bin/pnpm Browsers: Chrome: 148.0.7778.179 Safari: 26.3.1 npmPackages: vue: 3.5.34 => 3.5.34Any additional comments?
This is a continuation of the regression chain that started in 3.5.31:
- PR #8619 (3.5.31) introduced
pendingMountsso teleports defer their mount whenparentSuspense.pendingBranchis set. This is what created the situation where a teleport's children can havevnode.component === null. - Issue #14640 + PR #14642 (3.5.32) added the
pendingMountcheck shown above. That gates DOM removal of element children, not theunmountComponent(null, …)call on component children. - Issue #14699 (3.5.32) reported the same crash with the same stack as this issue. Closed by the author with a note about re-filing with a more accurate reproduction.
- Issue #14701 + PR #14702 (3.5.33) added
pendingMounts.has(vnode)guard, but only inmoveTeleport. TheTeleportImpl.removepath was not touched, so 3.5.33 and 3.5.34 still crash.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /core, current file: none) bash-$
Assistant
I fixed the crash and verified it. Final diff:
- let shouldRemove = doRemove || !isTeleportDisabled(props) + const shouldRemove = doRemove || !isTeleportDisabled(props) // A deferred teleport inside a pending suspense may be unmounted before its - // content is ever mounted. Clear the queued mount effect and skip removing - // children because nothing has been mounted yet. + // content is ever mounted. Clear the queued mount effect. Since the + // children were never mounted, they must not be unmounted either - doing + // so would access uninitialized internals (e.g. `vnode.component` of a + // component child is still null). const pendingMount = pendingMounts.get(vnode) if (pendingMount) { pendingMount.flags! |= SchedulerJobFlags.DISPOSED pendingMounts.delete(vnode) - shouldRemove = false } ... - if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) { + if (!pendingMount && shapeFlag & ShapeFlags.ARRAY_CHILDREN) {Rationale:
pendingMounts.has(vnode)means the teleport's children were never mounted (the mount job is still queued). Previouslyremove()only suppressed DOM removal (shouldRemove = false) but still calledunmount()on each child, which for component children reachesunmountComponent(vnode.component!)withcomponent === null→Cannot read properties of null (reading 'type'). Now the whole child-unmount loop is skipped for pending teleports (consistent with themoveTeleportguard added for #14701), while the queued mount job is still disposed and anchors are still removed.Checklist:
- Reproduced the reported error: Yes. I wrote a temporary vitest spec (Suspense with a pending async dep containing a
<Teleport>with a component child, then unmounting) and got the exactTypeError: Cannot read properties of null (reading 'type')with the same stack (Object.remove→unmount→unmountComponent). - Confirmed the fix resolves the error: Yes. After the change the same specs pass (both enabled and disabled teleport variants, the "unmount whole Suspense" path and the "Suspense resolve unmounts old branch" path), with no unhandled warnings and the teleport target left empty; the child's
onUnmountedis correctly not called since it was never mounted. - Edge cases: Considered
deferteleports without Suspense (pending mount job also disposed; verified via a temp test), disabled teleports (pending mount also never mounts children, so skipping is correct), teleports whose mount job already ran (the job deletes itself frompendingMounts, so normal unmount still happens), and the update path where a pending vnode is replaced (n1's job is disposed and re-queued forn2, so a pending vnode is never one whose children were mounted). Also compared behavior with an element child (already non-crashing before) to make sure output is unchanged. - Ran existing tests: Yes. Full
runtime-core+runtime-domsuites pass (1244 passed, incl. Teleport.spec.ts and Suspense.spec.ts). The full monorepo run only fails on pre-existing, unrelated e2e (puppeteer/browser unavailable) and a reactivity perf test.tsc --noEmitis clean. Temporary test files were deleted; no repository tests were modified or added.
- Reproduced the reported error: Yes. I wrote a temporary vitest spec (Suspense with a pending async dep containing a
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →