Skip to content

fix(ui): remove stale task nodes when a file is re-collected#10677

Open
eldardada wants to merge 1 commit into
vitest-dev:mainfrom
eldardada:fix/ui-remove-stale-tree-nodes
Open

fix(ui): remove stale task nodes when a file is re-collected#10677
eldardada wants to merge 1 commit into
vitest-dev:mainfrom
eldardada:fix/ui-remove-stale-tree-nodes

Conversation

@eldardada

Copy link
Copy Markdown

Description

When a test is removed or commented out, the file is re-collected with fewer tasks. The sidebar tree only ever added or updated nodes while collecting; it never dropped the ones that were gone, so the orphaned entry stayed in the explorer (often still showing red) until a full page reload. Re-running all tests does not help, because the rerun goes through the same collect path. This matches the report in #10670.

createOrUpdateFileNode (when collect is set) and createOrUpdateNode (when createAll is set) rebuild a file or suite subtree from the collected tasks, but they only walked the incoming list, so any tracked child missing from it was left behind. This change reconciles the tracked children against the collected tasks after each subtree rebuild and removes any node, along with its descendants, that no longer exists.

The summary counts were already correct because they come from the live task tree rather than the UI nodes, which is why the console showed the right totals while the sidebar did not.

Resolves #10670

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster.

Tests

  • Run the tests with pnpm test:ci.

Added packages/ui/client/composables/explorer/tree.spec.ts. It collects a file containing a suite, re-collects it after a test is deleted, and checks that the orphaned node is dropped, that a removed suite takes its children with it, and that untouched and newly added tasks stay. The two removal cases fail on main and pass with this change.

I went with a unit test rather than a browser e2e because the report is intermittent ("sometimes remains"), so an e2e around the watch rerun would be timing-dependent, while the reconciliation itself is deterministic.

Documentation

  • No user-facing API changes, so no documentation update is needed.

Changesets

  • Changes in changelog are generated from PR name.
@eldardada

Copy link
Copy Markdown
Author

The two red jobs look unrelated to this change.

Browsers: windows-latest failed in hooks-timeout.test.ts with sub-400ms locator.click timeouts across chromium, firefox and webkit, while the same browser suite passed on macos-latest. Test: vite@7, macos failed in test/watch/reporter-failed.test.ts (timeout waiting for the RERUN line) and test/oxc.test.ts (an "Unknown session id" error).

This PR only touches the UI explorer tree under packages/ui/client, which is loaded only with --ui, so none of those tests run the changed code. Looks like timing/infra flakiness. Happy to rebase if a re-run would help.

Removing or commenting out a test re-collects the file with fewer tasks,
but the sidebar tree only ever added or updated nodes and never dropped
the ones that disappeared. The orphaned entry stayed in the explorer,
often still showing red, until a full page reload.

Reconcile the collected tasks against the tracked children whenever a
file or suite subtree is rebuilt, removing any node and its descendants
that is no longer present.

Fixes vitest-dev#10670
@eldardada eldardada force-pushed the fix/ui-remove-stale-tree-nodes branch from 83fe826 to b631c60 Compare June 29, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant