Skip to content

bug: Settings page crashes when localStorage contains a stale/removed provider ID #135

@YizukiAme

Description

@YizukiAme

Description

Opening the Settings dialog and navigating to the Web Search section causes an immediate runtime crash:

TypeError: Cannot read properties of undefined (reading 'icon')
  at getHeaderContent (components/settings/index.tsx:545:25)

The root cause is that WEB_SEARCH_PROVIDERS[selectedWebSearchProviderId] returns undefined when selectedWebSearchProviderId holds an ID that no longer exists in the WEB_SEARCH_PROVIDERS registry.

How to reproduce

  1. During development of feat: add Brave Search & Baidu Search integration with sub-source support #42 (add new providers), a temporary custom web search provider was registered and selected
  2. After switching back to main (which doesn't have that provider), the stale provider ID remains in localStorage
  3. Open the app → click the Web Search settings → crash

This will also affect any user who:

  • Upgrades to a version where a previously available provider has been removed
  • Manually edits localStorage
  • Switches between branches with different provider sets during development

Affected provider types

The same unsafe lookup pattern (PROVIDERS[id] without null check) exists for all provider types:

Provider type Store field Lookup map Crash site
Web Search webSearchProviderId WEB_SEARCH_PROVIDERS settings/index.tsx:542 ✅ confirmed crash
PDF pdfProviderId PDF_PROVIDERS settings/index.tsx:522 ⚠️ same pattern
Image imageProviderId IMAGE_PROVIDERS already uses ?. — safe
Video videoProviderId VIDEO_PROVIDERS already uses ?. — safe
TTS ttsProviderId TTS_PROVIDERS already uses ?. — safe
ASR asrProviderId ASR_PROVIDERS already uses ?. — safe

LLM provider (providerId + modelId) is not affected because it already has auto-select / fallback logic in fetchServerProviders.

Proposed fix

  1. Store layer (lib/store/settings.ts): validate persisted provider IDs during rehydration; reset any invalid ID to its default value
  2. UI layer (components/settings/index.tsx): add null guards for PDF_PROVIDERS[selectedPdfProviderId] and WEB_SEARCH_PROVIDERS[selectedWebSearchProviderId] in getHeaderContent()

This should be a small, self-contained fix (~20 lines).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions