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 understanding the issue:
-
There's a regression in Vue 3.5.31+ where unmounting a
<Teleport>inside a<Suspense>before its mount can run crashes withTypeError: Cannot read properties of null (reading 'type'). -
The crash happens in
unmountComponentbecausevnode.componentisnullfor a component child that was pending mount. -
Previous fixes addressed similar issues in
moveTeleport(PR #14702) but not inTeleportImpl.remove.
Let me explore the repository structure and understand the codebase.
The issue mentions the crash in
TeleportImpl.remove- let me find that code.-
Assistant
Let me look at the Teleport.ts file to understand the
removemethod and thependingMountslogic.Assistant
The open command seems to be failing. Let me use the correct format.
Assistant
Now let me look at the
unmountandunmountComponentfunctions in the renderer:Assistant
Let me look at the unmount function and unmountComponent.
Assistant
Now I understand the issue clearly. Let me read the full
removemethod in Teleport.tsAssistant
Let me read the full remove method.
Assistant
Now I can see the issue clearly. The comment in the code says "skip removing children because nothing has been mounted yet", but the code only sets
shouldRemove = false— it still callsunmounton each child, which crashes for component children becausevnode.componentisnull.The fix: when a pending mount exists, skip the children unmount loop entirely.
Let me first confirm the issue and look at existing tests:
Assistant
Let me look at the Teleport spec and Suspense spec for relevant test patterns.
Assistant
Let me search for tests related to the recent fixes (PR #14702, #14642):
Assistant
Let me look at the Suspense test around line 2576 and also the Teleport spec for relevant tests.
Assistant
Now let me look at the Teleport spec for related tests:
Assistant
Let me look at the "defer mode should work inside suspense" test and also create a reproduction script.
Assistant
Now let me create a minimal reproduction script to confirm the bug before fixing it
Assistant
Let me look at how tests are structured and run the existing teleport tests first
Assistant
Let me look at the end of the Teleport spec to see the latest tests and understand patterns
Assistant
Let me look at the last portion of the Teleport spec
Assistant
Let me write a small test script to reproduce the issue
Assistant
Let me check the build status and try running the teleport tests
Assistant
The dist directory doesn't exist. Let me check package.json for how to build/run tests.
Assistant
Let me try running the specific teleport tests with vitest
Assistant
All existing tests pass. Let me now write a quick reproduction test to confirm the bug:
Assistant
Let me write a quick script to reproduce the issue:
Assistant
Let me write a more accurate reproduction. The scenario is: a Teleport inside a Suspense with an async dependency, where the teleport's children include a component that was never mounted.
Assistant
Let me run this test to see if it reproduces the crash:
Assistant
Let me put the test in the proper location:
Assistant
The test didn't crash — my reproduction isn't accurate. Let me study the Suspense implementation and the crash path more carefully.
Assistant
Let me look at the Suspense resolve method and unmount method:
Assistant
Let me continue reading the resolve method and the unmount method:
Assistant
Let me look at the Suspense.unmount method:
Assistant
Let me find the Suspense unmount method:
Assistant
Let me look at the Suspense.unmount method at line 780:
Assistant
Let me check how reactive updates work in these tests:
Assistant
Let me look at how the tests use reactive rendering to understand the pattern:
Assistant
Let me look at how other tests in the Suspense spec handle reactive rendering:
Assistant
Let me look at a Suspense test that unmounts by updating a reactive value:
Assistant
Let me look at the test around line 159:
Assistant
Now I understand the pattern. Let me update my test to properly reproduce the crash:
Assistant
Let me look at the Suspense process flow more carefully:
Assistant
Now I understand the flow. The Teleport's process returns early (line with
queuePendingMount) without mounting children, so component children havevnode.component === null. Let me update the test with async deps:Assistant
Let me run this test to see if it reproduces the crash:
Assistant
I've successfully reproduced the crash. Now let me fix it. The issue is in
TeleportImpl.remove— when there's a pending mount, it disposes the pending mount and setsshouldRemove = false, but still iterates over children and callsunmount, which crashes for component children that were never mounted.The fix: when a pending mount exists, skip the children unmount loop entirely.
Let me look at the exact code:
Assistant
Now I have a clear understanding of the issue and the fix. Let me implement it
Assistant
I see the edit introduced duplicate lines. Let me fix this by removing the duplicate trailing lines
Assistant
Still have a duplicate. Let me fix it:
Assistant
Let me verify the full remove method looks correct:
Assistant
I see that the edit accidentally removed the closing brace of the
if (target)block. Let me fix this:Assistant
The code looks correct now. Let me run the reproduction test to confirm the fix:
Assistant
The test passes. Now let me run the existing Teleport and Suspense tests to make sure nothing is broken:
Assistant
All existing tests pass. Let me clean up the temporary test file and run a broader test suite:
Assistant
Let me run the full runtime-core test suite to make sure nothing else is broken:
Assistant
All 3165 tests pass. Let me verify the final state of my change:
Assistant
The diff looks correct. Let me clean up the minor formatting issue (extra blank line) and then submit:
Assistant
Still a duplicate. Let me fix it properly:
Assistant
Let me verify the final diff is clean:
Assistant
Let me verify the final code and run the tests once more:
Assistant
I see an indentation issue - the closing brace for the
if (shapeFlag & ...)block is misaligned. Let me fix it:Assistant
Wait, I see that
hydrateis missing! Let me check and fix:Assistant
The
hydrateline is missing! Let me add it back:Assistant
Now the code looks correct. Let me verify the final diff and run the tests:
Assistant
The diff is clean. Let me run the full test suite one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.