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 + (3.5.32) added the check shown above. That gates DOM removal of children, not the call on children.
Assistant
Let me start by exploring the repository structure to understand the codebase and then find the relevant files related to the issue.
Assistant
Let me make a single tool call first.
Assistant
Let me explore the relevant files related to teleport and unmount.
Assistant
Let me look at the Teleport remove function and the relevant code.
Assistant
Now let me look at the
unmountfunction in the renderer to understand the crash path.Assistant
Now I understand the crash. When
unmountis called on a child vnode that hasshapeFlag & ShapeFlags.COMPONENTbutvnode.component === null(because the mount was pending/deferred), it callsunmountComponent(vnode.component!, parentSuspense, doRemove)wherevnode.componentis null, leading toCannot read properties of null (reading 'type').Let me look at
unmountComponent:Assistant
Let me look at the full Teleport process function and mount logic.
Assistant
Let me see the rest of the
unmountfunction to understand howelis removed.Assistant
Now I understand the crash path. Let me look at existing tests to understand the test setup for teleport + suspense.
Assistant
Let me look at how the Suspense tests are structured, especially around pending branch and unmount.
Assistant
Now let me create a reproduction script to confirm the crash. Let me first check the test infrastructure.
Assistant
Let me create a reproduction test file based on the issue scenario.
Assistant
Let me examine the Suspense implementation to understand the resolve/unmount flow.
Assistant
Assistant
Let me write a comprehensive reproduction test covering the described scenario.
Assistant
The
nodeOpsfrom@vue/runtime-testare not real DOM nodes. Let me check how the existing tests handle the teleport target.Assistant
The test renderer doesn't support
querySelector. Let me see how existing tests pass the teleport target element.Assistant
I see — I should pass an actual element as the
toprop. Let me fix the reproduction test.Assistant
The first test needs a single root. Let me restructure using a wrapper sync component, since the teleport must be in the pending branch (rendered) but with its mount deferred.
Assistant
It passed without crashing, which is surprising. Let me investigate when
pendingBranchis set and the exact timing.Assistant
The test passed without crashing, which is unexpected. Let me add debugging to understand whether the pendingMount is actually being set. Let me rewrite with the target accessible and add diagnostics.
Assistant
The target is empty (mount deferred), but no crash. The teleport child is a slot function. Let me check how teleport children are normalized — maybe the shapeFlag isn't
ARRAY_CHILDREN.Assistant
The teleport child as a slot function results in
SLOTS_CHILDREN, which skips theARRAY_CHILDRENunmount loop entirely. The crash happens withARRAY_CHILDREN. Let me update the reproduction to use an array child.Assistant
I've reproduced the crash! The stack trace matches exactly. The crash is at
Teleport.ts:355(theunmount(child, ...)call). Now let me apply the fix.Assistant
Now let me apply the fix. When there's a pending mount, the children were never mounted, so we should skip the children unmount loop entirely.
Assistant
Let me use the
editcommand instead.Assistant
Now let me apply the edit using the
editcommand:Assistant
The fix is applied. Now let me run the reproduction test to confirm the crash is fixed.
Assistant
The crash is fixed. Now let me write a comprehensive test covering edge cases to verify the fix is robust. Let me test element children, resolve-then-unmount, hooks behavior, and nested suspense.
Assistant
Two tests have setup issues (unrelated to the fix). Let me debug the resolve-then-unmount target serialization and fix the nested suspense test's single-root issue.
Assistant
Interesting — after resolve + nextTick, the target is still empty. Let me check whether the suspense even resolved and whether the async component is registered as a suspense dep.
Assistant
Let me add more logging to understand the resolve behavior.
Assistant
The suspense resolved (root shows async content) but the teleport content never mounted into the target even after 3 nextTicks. Let me check
queuePostRenderEffectand how effects are flushed.Assistant
Let me add temporary logging to the teleport mountJob to understand why content isn't mounting.
Assistant
Let me add a temporary console.log to the mountJob to see if it runs in the async case.
Assistant
The Wrapper only renders once, and the target stays empty. The mountJob isn't running or is being disposed. Let me add temporary logging to the mountJob.
Assistant
The edit broke the structure. Let me revert it.
Assistant
Now let me carefully add the log line:
Assistant
MOUNTJOB ran with
get===job? true, so it proceeded tomountToTarget. But the target is empty. Let me look atprepareAnchorandmount.Assistant
Let me add more detailed logging inside the mountJob to see what happens after mountToTarget.
Assistant
I accidentally removed the closing brace of mountJob. Let me fix it.
Assistant
This is getting messy with debugging. Let me revert and re-apply just the clean fix, then investigate the resolve-mounting separately.
Assistant
Now let me re-apply the clean fix:
Assistant
Let me carefully add just one diagnostic log after
mountToTargetto see the target's state.Assistant
The mountJob runs and mounts 3 children into the target (
target kids: 3), butserializeInnerreads the target before the mountJob runs — a test timing issue with synchronous promise resolution. The existing tests usesetTimeout+Promise.all(deps)pattern to avoid this. Let me revert the debug log and rewrite my tests properly.Assistant
Now let me verify the fix is intact and clean up debug files.
Assistant
The fix is clean. Now let me rewrite the test suite properly using the
setTimeout/Promise.all(deps)pattern to avoid the timing issue, and remove the debug files.Assistant
The first two tests (the crash fix) pass. The third needs an extra tick for the teleport's deferred mount job (which runs in a later post-flush). Let me add an extra
nextTick.Assistant
The replace operates on the currently open file. Let me use
--fileto target the test file.Assistant
All 3 tests pass. The fix correctly handles the crash while preserving normal mount/unmount behavior. Now let me run the existing test suites that could be affected by this change.
Assistant
Existing Teleport and Suspense tests pass. Let me also run hydration and renderer tests that exercise teleport unmount paths.
Assistant
Let me run a broader set of related tests including HMR and runtime-dom teleport tests.
Assistant
All tests pass. Now let me run the full runtime-core test suite to be thorough, then I'll remove my temporary test file (since I shouldn't add new tests to the repo).
Assistant
Let me verify the resolve-path scenario too, since the issue's stack trace shows
Object.resolve (Suspense). Let me understand how the suspense boundary's methods get invoked.Assistant
Let me look at how the suspense boundary's unmount is invoked in the renderer (line 2176 area).
Assistant
Let me look at the Suspense
pendingmethod to understand if there's a resolve-path that unmounts a pending-mount teleport.Assistant
My fix is in the shared
TeleportImpl.removepath, which all unmount triggers (resolve, unmount, fallback) funnel through. Let me construct one more scenario to verify the fix covers the resolve-path trigger mentioned in the issue stack — a two-async-deps scenario where the first async renders the teleport.Assistant
Need single root again. Let me wrap the two async deps in a Wrapper component.
Assistant
This scenario passes. Let me verify it actually exercises the bug by temporarily reverting the fix.
Assistant
Confirmed: WITHOUT my fix, both scenarios crash at
TeleportImpl.remove→unmountComponentreadinginstance.typeof null. WITH my fix, both pass. The fix is validated.Now let me clean up my temporary test files (I must not add new tests to the repo).
Assistant
Only the Teleport.ts change remains. Let me do a final review of the complete diff.
Assistant
The diff is clean and minimal. Let me run the most directly relevant test suites one final time to confirm no regressions, plus a type check.
Assistant
All tests pass. Let me run a type check to be thorough.
Assistant
Those errors are from running
tscon a single file without the project's global definitions (__DEV__, etc.). Let me run the proper project typecheck.Assistant
No type errors in Teleport.ts. Let me verify the overall typecheck didn't introduce any errors.
Assistant
Typecheck passes cleanly. Let me run the linter on the changed file.
Assistant
Lint passes. Let me verify prettier formatting on the changed file.
Assistant
All checks pass: typecheck, lint, prettier, and all tests. Let me do a final review of the complete change.
Assistant
The change is clean, minimal, and well-documented. Let me verify the final state of the
removefunction once more.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.