From fbf182a3d7f93732bab158c1648a978ed314f72a Mon Sep 17 00:00:00 2001 From: henz Date: Tue, 10 Mar 2026 13:33:54 +0800 Subject: [PATCH 1/2] Fix crash when stored playground language state is invalid Validate the stored chapter+variant combination against ALL_LANGUAGES when loading from localStorage. Falls back to the default language config if the combination is invalid (e.g. chapter 1 + explicit-control). Co-Authored-By: Claude Sonnet 4.6 --- src/pages/createStore.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/pages/createStore.ts b/src/pages/createStore.ts index fbe3112b60..0f9d4d5ab9 100644 --- a/src/pages/createStore.ts +++ b/src/pages/createStore.ts @@ -4,7 +4,7 @@ import { throttle } from 'lodash'; import createSagaMiddleware from 'redux-saga'; import { SourceActionType } from 'src/commons/utils/ActionsHelper'; -import { defaultState, OverallState } from '../commons/application/ApplicationTypes'; +import { ALL_LANGUAGES, defaultState, OverallState } from '../commons/application/ApplicationTypes'; import rootReducer from '../commons/application/reducers/RootReducer'; import MainSaga from '../commons/sagas/MainSaga'; import { generateOctokitInstance } from '../commons/utils/GitHubPersistenceHelper'; @@ -82,15 +82,24 @@ function loadStore(loadedStore: SavedState | undefined) { externalLibrary: loadedStore.playgroundExternalLibrary ? loadedStore.playgroundExternalLibrary : defaultState.workspaces.playground.externalLibrary, - context: { - ...defaultState.workspaces.playground.context, - chapter: loadedStore.playgroundSourceChapter + context: (() => { + const chapter = loadedStore.playgroundSourceChapter ? loadedStore.playgroundSourceChapter - : defaultState.workspaces.playground.context.chapter, - variant: loadedStore.playgroundSourceVariant + : defaultState.workspaces.playground.context.chapter; + const variant = loadedStore.playgroundSourceVariant ? loadedStore.playgroundSourceVariant - : defaultState.workspaces.playground.context.variant - } + : defaultState.workspaces.playground.context.variant; + const validCombination = ALL_LANGUAGES.some( + lang => lang.chapter === chapter && lang.variant === variant + ); + return { + ...defaultState.workspaces.playground.context, + chapter: validCombination + ? chapter + : defaultState.workspaces.playground.context.chapter, + variant: validCombination ? variant : defaultState.workspaces.playground.context.variant + }; + })() } }, stories: { From 08645da7595f25741c928b4e2c6067e4760e8985 Mon Sep 17 00:00:00 2001 From: henz Date: Mon, 6 Jul 2026 00:05:54 +0800 Subject: [PATCH 2/2] Fall back to defaultLanguageConfig for invalid stored language state When the stored chapter+variant combination is not in ALL_LANGUAGES, reset to `defaultLanguageConfig` (a known-valid pair) rather than to the individual default context fields, so the fallback is explicitly "the default language config" as the issue describes. Co-Authored-By: Claude Opus 4.8 --- src/pages/createStore.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/createStore.ts b/src/pages/createStore.ts index 90b6e12179..34ea0779e8 100644 --- a/src/pages/createStore.ts +++ b/src/pages/createStore.ts @@ -6,6 +6,7 @@ import type { SourceActionType } from 'src/commons/utils/ActionsHelper'; import { ALL_LANGUAGES, + defaultLanguageConfig, defaultState, type OverallState, } from '../commons/application/ApplicationTypes'; @@ -93,14 +94,13 @@ function loadStore(loadedStore: SavedState | undefined) { const validCombination = ALL_LANGUAGES.some( lang => lang.chapter === chapter && lang.variant === variant, ); + // Invalid stored combinations (e.g. chapter 1 + explicit-control, which can be + // persisted when toggling feature flags) would crash on load, so fall back to + // the default language config as a coherent, always-valid pair. return { ...defaultState.workspaces.playground.context, - chapter: validCombination - ? chapter - : defaultState.workspaces.playground.context.chapter, - variant: validCombination - ? variant - : defaultState.workspaces.playground.context.variant, + chapter: validCombination ? chapter : defaultLanguageConfig.chapter, + variant: validCombination ? variant : defaultLanguageConfig.variant, }; })(), },