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 what we're working with.
Assistant
This is the Vue.js core repository. Let me look at the packages directory
Assistant
me see the rest of the file, particularly the
removefunction:Assistant
me look at the unmount function in renderer.ts:
Assistant
me look at the unmountComponent function:
Assistant
Let me re-examine the
removefunction and understand the issue better:Assistant
Let me search for related issues and PRs:
Assistant
Now let me look at PR 14642 which introduced the pendingMount check:
Assistant
Now let me try to reproduce the issue. Let me first look at the existing tests for Teleport and Suspense:
Assistant
Let me look at the imports of the Suspense test:
Assistant
me create a simple reproduction script first. Let me check if vitest is available:
Assistant
Let me create a reproduction test script. First, let me check what kind of test setup we should use:
Assistant
me look at the related test files first and how they're set up:
Assistant
me create a temporary test file in the existing test directory to reproduce the bug:
Assistant
me fix the path:
Assistant
The test passed but didn't reproduce the crash. Let me try a more accurate reproduction. Looking at the stack trace from the issue, the crash happens during Suspense.resolve. Let me look at how Suspense.resolve works:
Assistant
Let me look at how Suspense is unmounted:
Assistant
Now I understand the issue. The fix needs to be in
TeleportImpl.remove. Let me first try to reproduce the bug properly:Assistant
Let me check how the pending branch is mounted:
Assistant
Let me check the current test by adding debug output:
Assistant
me check the Suspense resolve code more carefully and try to understand the exact reproduction scenario:
Assistant
Assistant
Let me add more detailed debugging to understand what's happening:
Assistant
Let me try to access the linked repo:
Assistant
Now I understand the actual test setup. Let me update my test:
Assistant
I reproduced the bug! Now let me apply the fix:
Assistant
Now let me apply the fix to skip unmounting children when there's a pending mount:
Assistant
Let me use a different approach. I'll use a temp script.
Assistant
me verify the change:
Assistant
Now let me run my reproduction test to verify the fix:
Assistant
The fix works. Let me run the existing Teleport and Suspense tests to make sure nothing is broken:
Assistant
broke two tests. Let me look at them:
Assistant
Assistant
The test is for a teleport with
disabled: true. The teleport contains a component child. When unmounted, the component should be unmounted (beforeUnmount called).In my fix, the logic is:
let shouldRemove = doRemove || !isTeleportDisabled(props) // shouldRemove = true || !true = true const pendingMount = pendingMounts.get(vnode) if (pendingMount) { // pendingMount is null for this test ... shouldRemove = false } ... if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) { if (shouldRemove) { // shouldRemove = true for (let i = 0; i < (children as VNode[]).length; i++) { const child = (children as VNode[])[i] unmount( child, parentComponent, parentSuspense, true, // doRemove !!child.dynamicChildren, ) } } }Hmm, this should work. The component child should be unmounted. But the test is failing.
Wait, the test is for a teleport with
disabled: trueANDto: null. Let me check what happens with .Assistant
Let me check the shapeFlag behavior:
Assistant
So when the teleport has children, the children are normalized. Let me check the Tele
Assistant
me check by reverting my change temporarily and running the test:
Assistant
tests pass with the original code. Now let me re-apply my fix and check what's different:
Assistant
me debug the shapeFlag issue:
Assistant
Let me look at the failing test more carefully:
Assistant
The ShapeFlag is 80 = TELEPORT(64) + ARRAY_CHILDREN(16). So the children loop should be entered.
Let me check the actual test flow:
Assistant
hooks are NOT being called even after my fix. Let me check the issue - the test expects hooks to be called but they aren't:
Assistant
Let me verify my fix is actually applied:
Assistant
Let me check by running the actual Teleport test:
Assistant
Let me revert and check the original behavior:
Assistant
OK with the original code, the tests pass. Now let me apply my fix again and investigate more carefully
Assistant
me add debug output to see what's happening:
Assistant
I see the issue. The
doRemoveisfalsein this test because it's called fromunmountChildren(which defaults doRemove to false). The original code always iterates children and calls unmount regardless ofshouldRemove. TheshouldRemoveis just used as thedoRemovefor the children's unmount call.Let me revert my fix and apply a better one:
Assistant
Assistant
Let me re-run the fix:
Assistant
Now let me run the tests:
Assistant
All Teleport tests pass. Now let me run my reproduction test:
Assistant
Now let me run all Suspense and Teleport tests to make sure nothing is broken:
Assistant
tests pass. Let me run the broader test suite to make sure I didn't break anything:
Assistant
All 1015 tests pass. Now let me run the runtime-dom tests:All 1015 tests pass. Let me run the runtime-dom and vue tests too:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[npx vitest run packages/runtime-dom/tests/ 2>&1 | tail -30]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The e2e tests fail due to browser launch issues (unrelated to my fix). Let me run only the unit tests for vue:
Assistant
Only 1 test fails and it's an unrelated performance test in reactivity. Let me verify by checking if this test fails without my fix:
Assistant
Hmm, the test passes alone. Let me re-run all tests with my fix to see if the test fails:
Assistant
The test passes when run alone - the earlier failure was due to system load (unrelated to my fix).
Let me test more edge cases:
Assistant
me also test with a more complex scenario that mirrors the linked repo's tests:
Assistant
Now let me also run the test without my fix to confirm the test fails:Let me also confirm the test fails without my fix:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git stash -- packages/runtime-core/src/components/Teleport.ts npx vitest run packages/runtime-core/tests/components/SuspenseTeleportRepro.spec.ts 2>&1 | tail -30 git stash pop]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me retry the command
Assistant
test fails without my fix and passes with my fix. Now let me re-run with my fix to confirm:
Assistant
Now let me run the full test suite once more to verify nothing is broken:Now let me run the full test suite once more to verify nothing is broken:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[npx vitest run packages/runtime-core/tests/components/Suspense.spec.ts packages/runtime-core/tests/components/Teleport.spec.ts 2>&1 | tail -10]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All tests pass. Now let me clean up the temporary test file I created (since the instructions say not to add new tests):
Assistant
me verify the final state of my changes:
Assistant
The diff looks clean. Let me look at the full file to make sure everything is in order:Let me see the full updated
removefunction:Let me see the full updatedremovefunction:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[sed -n '315,370p' packages/runtime-core/src/components/Teleport.ts]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>Assistant
I need to retry the command. The bash tool requires proper formatting
Assistant
The fix is clean. Let me re-run all the relevant tests once more to make sure everything works:Let me re-run all the relevant tests once more to make sure everything works:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[npx vitest run packages/runtime-core/tests/components/ packages/runtime-core/tests/rendererComponent.spec.ts packages/runtime-core/tests/rendererOptimizedMode.spec.ts 2>&1 | tail -15]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All 225 tests pass. Let me also verify by looking at the final diff:Let me also verify by looking at the final diff:All 225 tests pass. Let me also verify by looking at the final diff:Let me also verify by looking at the final diff:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git diff packages/runtime-core/src/components/Teleport.ts]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me re-invoke the tool
Assistant
The fix is minimal and clean. Let me also check by listing all my changes:Let me check the final state of my changes:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git status]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.