Skip to content

Commit 5b9b157

Browse files
martin-henzclaudeRichDom2185
authored
Fix crash when stored playground language state is invalid (#3646)
* 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 <noreply@anthropic.com> * 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 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
1 parent 3100183 commit 5b9b157

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

src/pages/createStore.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { throttle } from 'lodash-es';
44
import createSagaMiddleware from 'redux-saga';
55
import type { SourceActionType } from 'src/commons/utils/ActionsHelper';
66

7-
import { defaultState, type OverallState } from '../commons/application/ApplicationTypes';
7+
import {
8+
ALL_LANGUAGES,
9+
defaultLanguageConfig,
10+
defaultState,
11+
type OverallState,
12+
} from '../commons/application/ApplicationTypes';
813
import rootReducer from '../commons/application/reducers/RootReducer';
914
import MainSaga from '../commons/sagas/MainSaga';
1015
import { generateOctokitInstance } from '../commons/utils/GitHubPersistenceHelper';
@@ -79,15 +84,25 @@ function loadStore(loadedStore: SavedState | undefined) {
7984
externalLibrary: loadedStore.playgroundExternalLibrary
8085
? loadedStore.playgroundExternalLibrary
8186
: defaultState.workspaces.playground.externalLibrary,
82-
context: {
83-
...defaultState.workspaces.playground.context,
84-
chapter: loadedStore.playgroundSourceChapter
87+
context: (() => {
88+
const chapter = loadedStore.playgroundSourceChapter
8589
? loadedStore.playgroundSourceChapter
86-
: defaultState.workspaces.playground.context.chapter,
87-
variant: loadedStore.playgroundSourceVariant
90+
: defaultState.workspaces.playground.context.chapter;
91+
const variant = loadedStore.playgroundSourceVariant
8892
? loadedStore.playgroundSourceVariant
89-
: defaultState.workspaces.playground.context.variant,
90-
},
93+
: defaultState.workspaces.playground.context.variant;
94+
const validCombination = ALL_LANGUAGES.some(
95+
lang => lang.chapter === chapter && lang.variant === variant,
96+
);
97+
// Invalid stored combinations (e.g. chapter 1 + explicit-control, which can be
98+
// persisted when toggling feature flags) would crash on load, so fall back to
99+
// the default language config as a coherent, always-valid pair.
100+
return {
101+
...defaultState.workspaces.playground.context,
102+
chapter: validCombination ? chapter : defaultLanguageConfig.chapter,
103+
variant: validCombination ? variant : defaultLanguageConfig.variant,
104+
};
105+
})(),
91106
},
92107
},
93108
};

0 commit comments

Comments
 (0)