Memoize getUserConfig to avoid repeated storage reads

PE
1d ago
+1744-148

Cache getUserConfig() per extension context and share concurrent storage reads, while returning an independent deep copy to each caller.

Invalidate on settings and browser language changes, excluding conversation history writes. Keep failed migrations retryable and prevent older in-flight reads from overwriting newer cached results.

Read fresh settings at action and request boundaries so completed settings changes apply immediately. Reuse one configuration snapshot throughout each ChatGPT Web generation and cleanup, and use cloneDeep for older Safari compatibility. Add regression coverage for delayed storage events, including foreground Bing authentication, Escape handling, and return-tab selection. Keep failed Escape and Go Back actions retryable.

Summary by CodeRabbit

  • Bug Fixes
    • Configuration changes are reflected more reliably in chat generation, language preferences, service requests, context menus, and selection toolsβ€”even before browser storage notifications arrive.
    • Chat requests consistently use the settings active when they start, including service endpoints and model preferences.
    • Failed configuration migrations can be retried rather than leaving outdated settings in use.
    • Language selection, token cleanup, chat-window behavior, and Go Back actions use up-to-date settings.
    • Configuration read errors are handled without continuing the affected action.