Skip to content

fix(chat): ChatInterface's init keeps running after unmount, so a slow-init test crashes a later test's fallback #16274

Description

@mrveiss

ChatInterface.test.ts passes, 23/23. Each run also logs this error twice:

[ERROR] [ChatInterface] ❌ Chat initialization failed: TypeError: Cannot read properties of undefined (reading 'catch')
    at initializeChatInterface (ChatInterface.vue:1102)

It happens on base 65609f9, and also on a branch that carries #16265. The test stays green, so nothing surfaces it.

Cause (line numbers from base 65609f9)

  1. components/__tests__/ChatInterface.test.ts:307, "shows loading state while fetching chat history", mocks initializeChatInterface with a 5 s delay (:310). It asserts synchronously and ends, and nothing awaits or unmounts that init.
  2. components/chat/ChatInterface.vue:1054-1056 races the init against a 10 s setTimeout. onUnmounted (:1156) doesn't cancel it. The timer also isn't cleared when the init wins the race.
  3. The timeout fires during a later test. The catch block then runs the fallback controller.loadChatSessions().catch(...) (:1102).
  4. By that point mockReset: true (vitest.config.ts:75) has stripped :95's vi.fn().mockResolvedValue(undefined), so the call returns undefined and .catch throws. This is the class of bug the warning at vitest.config.ts:71 (Enhancement: document vitest mockReset interaction with vi.mock factories #3070) describes.

Production impact

This isn't only a test problem. An init that outlives its component still runs the fallback and writes to the chat store after unmount. On every successful mount, the 10 s timer is also left pending.

Acceptance criteria

  • ChatInterface.vue clears the init timeout whether the init wins or loses the race.
  • Once the component has unmounted, nothing after an await in the init runs. A test unmounts mid-init and asserts the fallback is never called.
  • A run of ChatInterface.test.ts logs no Chat initialization failed.

Found while verifying #16253.

Activity

  1. mrveiss commented on Sep 11, 2026

    @mrveiss
    OwnerAuthor

    Folded into #16253's PR (coordinator's call): it touches the same component and the same init path, so it goes through one lifecycle review. That PR will close this issue against the ACs above.

  2. added this to the v0.9.0 milestone on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions