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 find the relevant files for this issue.
The issue is about a teleport + suspense unmount crash when there's a pending teleport with a component child. The crash happens because
vnode.componentcan benullwhen unmounting a teleport that was pending in a suspense.Let me explore the repository first.
Assistant
Let me explore the packages directory to find the Vue runtime-core package, where the teleport and suspense code should be.
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/ </tool_call>
Assistant
I need to use bash_terminal to run commands. Let me list the packages directory.
Assistant
The runtime-core package is where we should find the teleport and suspense code. Let me explore it.
<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/runtime-core/src/ </tool_call>
Assistant
I need to use bash_terminal properly. Let me run the command to list the runtime-core source directory.
Assistant
The Teleport implementation should be in the
componentsfolder. Let me look at that.<tool_call> <function=bash_terminal> <parameter=command> ls -la packages/runtime-core/src/components/ </tool_call>
Assistant
The terminal command needs to be executed via the bash_terminal tool. Let me run the command.
Assistant
Now let me look at the Teleport.ts file to understand the current implementation.
Assistant
Now let me look at the
removefunction more closely. The issue is in theremovefunction where it callsunmounton children without checking if the child is a component vnode withcomponent === null. Let me look at how the unmount function works:<tool_call> <function=bash_terminal> <parameter=command> grep -n "function unmount|export function unmount" packages/runtime-core/src/renderer.ts </tool_call>
Assistant
I need to use the bash_terminal tool to run commands. Let me search for the unmount function in the renderer.ts file.
Assistant
The grep command returned exit code 1, which means no matches were found. Let me search differently.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmount" packages/runtime-core/src/renderer.ts | head -30 </tool_call>
Assistant
I need to use the bash_terminal tool. Let me search for the unmount function.
Assistant
Now let me look at the
unmountfunction around line 2120 to understand how it handles component vnodes.<tool_call> <function=bash_terminal> <parameter=command> sed -n '2120,2250p' packages/runtime-core/src/renderer.ts </tool_call>
Assistant
I need to use bash_terminal tool to execute the sed command.
Assistant
Now I understand the issue. Let me first reproduce the error by looking at the test file and running the tests.
Assistant
The find command returned exit code 1 (no matches found or error). Let me try searching more broadly.
<tool_call> <function=bash_terminal> <parameter=command> find . -type f -name ".test." 2>/dev/null | head -20 </tool_call>
Assistant
I need to use the bash_terminal tool to run the command. Let me search for test files.
Assistant
Let me search for existing teleport tests in the runtime-core package.
Assistant
The command returned exit code 0, but didn't output any results. Let me look at what's in the packages/runtime-core directory for tests.
Assistant
There's a
__tests__directory. Let me look at it.Assistant
There's a components folder. Let me look at its contents.
Assistant
Now let me look at the Teleport.spec.ts file to understand how teleport tests are structured.
Assistant
The grep command returned exit code 1, meaning no matches found. Let me search for "suspense" or "defer" related tests.
<tool_call> <function=bash_terminal> <parameter=command> grep -n -i "defer|suspense" packages/runtime-core/tests/components/Teleport.spec.ts </tool_call>
Assistant
I need to use the bash_terminal tool to run commands. Let me search for suspense/defer tests in Teleport.spec.ts.
Assistant
Good, now let me understand the issue better by looking at the current teleport remove function. Based on the issue description:
- When a
<Teleport>inside a<Suspense>is unmounted before its mount can run, Vue throwsTypeError: Cannot read properties of null (reading 'type') - The issue is that in
TeleportImpl.remove, when unmounting children, it callsunmount(child, ...)for each child, and if a child is a component vnode butchild.component === null(because the component hasn't been mounted yet due to the pending suspense), then the unmount function crashes.
Looking at the remove function in Teleport.ts (around line 470-497 based on the truncation), I can see there's a check for
pendingMountbut theunmountcall for children doesn't have the same guard.Let me look at the specific part of the remove function that handles children unmounting.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '470,510p' packages/runtime-core/src/components/Teleport.ts </tool_call>
- When a
Assistant
I need to use the bash_terminal tool. Let me run the sed command.
Assistant
Let me find the
removefunction in Teleport.ts. It's typically near the end of the TeleportImpl object.<tool_call> <function=bash_terminal> <parameter=command> grep -n "remove:" packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
I need to use the bash_terminal tool properly. Let me search for the remove function in Teleport.ts.
Assistant
The issue is in the Teleport.ts remove function. Let me see the full remove function starting from around line 321.
Assistant
Now I can see the issue. In the
removefunction (lines 349-358), when there's a pending mount, the code setsshouldRemove = falsebut still goes through the children unmounting loop. When a child is a component vnode withcomponent === null(because it hasn't been mounted yet), theunmountfunction in renderer.ts tries to accessvnode.component.typeand crashes.Let me first look at the unmount function in renderer.ts to understand exactly where the crash occurs:
Assistant
Now I see the issue clearly! At line 2173, the code does
unmountComponent(vnode.component!, ...)with a non-null assertion (!). When the teleport is pending and hasn't been mounted yet,vnode.componentisnull, and accessing.typeonnullcauses the crash.The fix should be: when there's a pending mount for the teleport, we should skip unmounting the children entirely (since they were never mounted). This is similar to what the code already does for
shouldRemove- but the children unmounting shouldn't happen at all whenpendingMountis true.Let me check if there are any other conditions under which
vnode.componentcould be null during unmount. Looking at the issue description:In 3.5.31,
pendingMountswas introduced so teleports defer their mount whenparentSuspense.pendingBranchis set. This is what created the situation where a teleport's children can havevnode.component === null.So the issue is that when the teleport is deferred (has a pending mount), its children may be component vnodes whose components haven't been created yet. The fix should skip unmounting children when the teleport has a pending mount.
Assistant
I need to use the bash_terminal tool properly. Let me run the sed command to see the remove function.
Assistant
Now I understand the issue. When there's a
pendingMountfor the teleport, the children have never been mounted yet, so their component vnodes may havecomponent === null. The current code setsshouldRemove = falsebut still tries to unmount the children, which causes the crash when trying to accessvnode.component.type.The fix is to skip unmounting children when there's a pending mount. Let me implement this:
Assistant
Now I can see the issue clearly. The comment on lines 335-337 says:
"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."
However, the current code only sets
shouldRemove = falsebut still unmounts the children. The fix should be to skip the children unmounting entirely when there's a pending mount.Let me apply the fix:
<tool_call> <function=bash_terminal> <parameter=command> cat packages/runtime-core/src/components/Teleport.ts | head -340 | tail -10 </tool_call>
Assistant
I need to use the bash_terminal tool to run the cat command. Let me see the lines around line 340.
Assistant
Now I understand the issue. The code sets
shouldRemove = falsewhen there's a pending mount, but it still tries to unmount children. When children are component vnodes that haven't been mounted yet (because the teleport is pending),vnode.componentisnull, causing the crash.The fix should skip unmounting children when there's a pending mount. Let me apply this fix:
Assistant
Now I need to apply the fix. The issue is that when there's a pending mount, we should skip unmounting children entirely. Let me use the edit tool to fix this:
Assistant
Now I need to fix this by skipping unmounting children when there's a pending mount. The fix should be:
- When
pendingMountexists, skip unmounting children entirely (they were never mounted) - Also skip removing the anchor when pendingMount exists
Let me apply this fix:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '340,365p' packages/runtime-core/src/components/Teleport.ts </tool_call>
- When
Assistant
I need to use the bash_terminal tool to execute the sed command.
Assistant
The issue is clear now. The comment at line 350-351 says "an unmounted teleport should always unmount its children whether it's disabled or not", but when there's a pending mount, the children haven't been mounted yet. In this case, trying to unmount them will crash because component vnodes may have
component === null.The fix should be to skip the children unmounting when there's a pending mount. I need to:
- Add a condition to skip unmounting children when
pendingMountexists - Also skip removing the anchor when pending mount exists
- Add a condition to skip unmounting children when
Assistant
I need to use the bash_terminal tool. Let me try using the edit tool directly since it's designed for this purpose.
Assistant
The fix has been applied. Now let me verify that the fix works by running the existing teleport tests.
Assistant
The command timed out. Let me try running the test differently, perhaps with a specific test runner or configuration.
Assistant
The test command is hanging. Let me try a different approach and build the project first, then run the tests.
Assistant
The build is also timing out. Let me try using vitest directly with a shorter timeout.
Assistant
The fix is working for the main issue (no crashes), but I've introduced a regression in the test. The tests are failing because when the teleport is discarded (unmounted while pending), the anchor (
teleport endcomment) is no longer being removed.Looking at the test failure:
- Expected:
"<div>done</div>" - Received:
"<!--teleport end--><div>done</div>"
The issue is that when there's a pending mount and the teleport is unmounted, we're skipping the
doRemove && hostRemove(anchor!)line, but the anchor was inserted into the DOM and should be removed.Let me look at the test to understand the expected behavior:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '243,295p' packages/runtime-core/tests/components/Teleport.spec.ts </tool_call>
- Expected:
Assistant
I need to use the bash_terminal tool to run the sed command.
Assistant
I see - the test shows that when a deferred teleport is discarded (i.e.,
showTeleport.value = truethen immediately set tofalsebefore the deferred mount happens), the teleport anchor should be removed from the DOM.The issue is that my fix is skipping the anchor removal when there's a pending mount. The anchor should still be removed even when there's a pending mount - it's just that the children should not be unmounted (because they were never mounted).
Let me re-examine my fix. The key insight is:
- The anchor (
teleport endcomment) was inserted into the DOM during mount and should always be removed - The children were never mounted (pending mount was disposed), so they should not be unmounted
So my fix was correct in skipping the children unmount, but I shouldn't skip the anchor removal. Let me update the fix:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '350,368p' packages/runtime-core/src/components/Teleport.ts </tool_call>
- The anchor (
Assistant
I need to use the bash_terminal tool to run the sed command to see the current state of the fix.
Assistant
The issue is that my fix is skipping both the anchor removal and the children unmount. I should only skip the children unmount when there's a pending mount - the anchor should still be removed.
Let me fix this:
<tool_call> <function=bash_terminal> <parameter=command> edit --file packages/runtime-core/src/components/Teleport.ts 350:367 << 'EOF' // an unmounted teleport should always unmount its children whether it's disabled or not. // but when it has a pending mount (e.g. inside a suspense), the children haven't been // mounted yet and should not be unmounted. doRemove && hostRemove(anchor!) if (!pendingMount && shapeFlag & ShapeFlags.ARRAY_CHILDREN) { for (let i = 0; i < (children as VNode[]).length; i++) { const child = (children as VNode[])[i] unmount( child, parentComponent, parentSuspense, shouldRemove, !!child.dynamicChildren, ) } } EOF </tool_call>
Assistant
Let me use the bash_terminal tool to run the edit command.
Assistant
Now let me run the tests again to verify the fix:
Assistant
All 51 Teleport tests pass now. Let me also run the Suspense tests to make sure the fix doesn't break anything related to suspense:
<tool_call> <function=bash_terminal> <parameter=command> cd /core && timeout 120 npx vitest run packages/runtime-core/tests/components/Suspense.spec.ts --reporter=verbose 2>&1 | tail -50 </tool_call>
Assistant
I need to use the bash_terminal tool to run the Suspense tests.
Assistant
All Suspense tests pass. Now let me look for any specific tests related to the issue mentioned in the issue description - unmounting a teleport with a component child inside a suspense. Let me search for related tests:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmount" packages/runtime-core/tests/components/Suspense.spec.ts | grep -i "teleport" </tool_call>
Assistant
The command was executed but no output was shown. Let me try a different approach to search for relevant tests.
Assistant
I see there's a test called
should not crash when moving disabled teleport with component children inside suspenseat line 2577. This is exactly the kind of scenario we're trying to fix! Let me look at that test to understand what it covers.Assistant
This test shows the scenario where a disabled teleport with component children is inside a suspense. However, it's testing the
movecase, not theremovecase. The issue description mentions that the crash happens when "unmounting a teleport inside a suspense".Let me now create a test to verify that the fix works for the exact scenario described in the issue. First, let me understand the issue better by looking at what the issue description says:
When a inside a is unmounted before its mount can run, Vue should remove it cleanly.
So the issue is:
- A Teleport is inside a Suspense
- The Teleport's mount is deferred because the Suspense is still pending
- The Teleport is unmounted before its deferred mount runs
- This causes a crash because
vnode.componentisnull
Let me look for existing tests that test unmounting a deferred teleport inside suspense:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmount" packages/runtime-core/tests/components/Suspense.spec.ts | head -20 </tool_call>
Assistant
I need to use the bash_terminal tool to run the grep command.
Assistant
The issue mentions that the fix should handle the case where a teleport inside suspense is unmounted before its deferred mount runs. Let me now verify the fix works by running all runtime-core tests:
<tool_call> <function=bash_terminal> <parameter=command> cd /core && timeout 180 npx vitest run packages/runtime-core/tests/components/ --reporter=verbose 2>&1 | tail -30 </tool_call>
Assistant
I need to use the bash_terminal tool to run the command.
Assistant
All 175 tests in the components folder pass! Now let me also run the full runtime-core tests to make sure I haven't broken anything else:
<tool_call> <function=bash_terminal> <parameter=command> cd /core && timeout 180 npx vitest run packages/runtime-core/tests/ --reporter=verbose 2>&1 | tail -30 </tool_call>
Assistant
I need to use the bash_terminal tool to run the full runtime-core tests.
Assistant
All 1014 tests pass! Now let me also check if there's an existing reproduction script in the repository. Let me also verify the fix by examining the renderer.ts to ensure that the
unmountComponentfunction won't crash whenvnode.componentis null.Wait, I need to verify that the fix is complete. The issue mentions that
unmountComponent(vnode.component!, parentSuspense, doRemove)crashes whenvnode.componentis . My fix skips unmounting children when there's a pending mount, which should prevent the crash. But let me also check if there are other places where children could be unmounted with .Assistant
Let me use the bash_terminal tool to run the sed command to see the unmountComponent function.
Assistant
I see the issue now. In the unmount function, when
shapeFlag & ShapeFlags.COMPONENT, it callsunmountComponent(vnode.component!, ...). The issue is thatvnode.componentcan benullwhen the component hasn't been created yet (e.g., when the teleport is pending).My fix addresses this by not calling
unmounton children when there's a pending mount. But let me also check if there's any additional protection needed. Looking at line 2340-2345, I can see there's already handling for (when a component is unmounted before its async setup has resolved).Assistant
I need to use the bash_terminal tool to run the grep command.
Assistant
The only place where
unmountis called is in theremovefunction (line 357), which I've already fixed. The fix looks complete.Let me also check if there are any edge cases I might have missed. The issue mentions that the teleport has a "component child" (i.e., a child that is a component vnode). Let me verify that my fix handles this case correctly.
Actually, I should also consider the case where the teleport's children might have nested component vnodes that are descendants of component children. These would be handled recursively by the
unmountfunction.Let me now verify the fix is complete by reviewing the final state of the remove function:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '330,370p' packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
I need to use the bash_terminal tool to view the remove function.
Assistant
The fix looks correct. Let me summarize what the fix does:
-
When there's a pending mount (deferred teleport inside suspense), the code:
- Disposes the pending mount job
- Removes the pending mount from the map
- Sets
shouldRemove = false(for the target anchors)
-
The target anchors are always removed from the target (lines 345-348)
-
The anchor in the main view is removed if
doRemoveis true (line 353) -
The children are only unmounted if there's no pending mount (line 354)
This fix correctly handles the case where a teleport is unmounted before its deferred mount runs. The children vnodes are never unmounted because they were never mounted, and the teleport's anchors are still removed from the DOM.
Now let me run the full test suite to make sure everything passes:
<tool_call> <function=bash_terminal> <parameter=command> cd /core && timeout 300 npx vitest run --reporter=verbose 2>&1 | tail -50 </tool_call>
-
Assistant
The full test suite is taking too long. Let me just run the runtime-core tests which are most relevant to this fix:
Assistant
The test runner is having issues. Let me try running the tests without the basic reporter:
Assistant
All 1014 runtime-core tests pass. The fix is working correctly. Let me now verify the fix by looking at the diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.