Skip to content

fix(i18n): Cache initial locale to prevent repeated warnings on page load#133

Merged
Stasshe merged 2 commits intomainfrom
copilot/improve-try-handling-on-load
Dec 3, 2025
Merged

fix(i18n): Cache initial locale to prevent repeated warnings on page load#133
Stasshe merged 2 commits intomainfrom
copilot/improve-try-handling-on-load

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

Page load triggered excessive [i18n] Saved locale 'ja' is not enabled. Trying related locales... warnings because getSavedLocale() was called multiple times before IndexedDB/extension manager was ready, and each call logged when enabled locales set was empty.

Changes

  • Cache initial locale calculation: Module-level cachedInitialLocale ensures getSavedLocale() and detectBrowserLocale() run only once
  • Skip validation when extensions not ready: Early return when enabledLocales.size === 0 — trust saved/browser locale until language packs load; extension change listener handles validation afterward
// Before: ran every render, warned every time
const initialLocale = getSavedLocale() || detectBrowserLocale() || ...

// After: cached, no warnings until extensions ready
if (cachedInitialLocale === null) {
  cachedInitialLocale = getSavedLocale() || detectBrowserLocale() || ...
}
Original prompt

184: [i18n] Saved locale 'ja' is not enabled. Trying related locales...このように、ページを開いたときに、ものすごい数のtryが走る。確かに、ページを開いた瞬間はIndexedDBはまだ準備できてないから、しょうがないんだけど。もうちょい改善できんかな?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 3, 2025
…load

Co-authored-by: Stasshe <133995608+Stasshe@users.noreply.github.com>
@Stasshe Stasshe temporarily deployed to copilot/improve-try-handling-on-load - pyxis-code PR #133 December 3, 2025 06:52 — with Render Destroyed
Copilot AI changed the title [WIP] Optimize handling of locale attempts on page load fix(i18n): Cache initial locale to prevent repeated warnings on page load Dec 3, 2025
Copilot AI requested a review from Stasshe December 3, 2025 06:55
@Stasshe Stasshe marked this pull request as ready for review December 3, 2025 06:55
@Stasshe Stasshe merged commit abda062 into main Dec 3, 2025
@Stasshe Stasshe deleted the copilot/improve-try-handling-on-load branch December 3, 2025 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants