Fix crash when stored playground language state is invalid#3646
Conversation
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>
RichDom2185
left a comment
There was a problem hiding this comment.
This works but behaves differently than what the issue suggests.
Coverage Report for CI Build 28746807720Coverage increased (+0.02%) to 41.4%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
In what way is this different from what the issue suggests? |
The issue suggests:
But the logic implemented is:
|
Hmm, the implementation checks: so it looks for a valid combination. It falls back on the default lang/variant only if the combination is not valid. |
# Conflicts: # src/pages/createStore.ts
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>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe change updates the ChangesLanguage config validation
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)flowchart TD
loadStore --> ReadPersistedContext
ReadPersistedContext --> CheckAllLanguages
CheckAllLanguages -->|valid combination| UseStoredChapterVariant
CheckAllLanguages -->|invalid combination| UseDefaultLanguageConfig
UseStoredChapterVariant --> SetPlaygroundContext
UseDefaultLanguageConfig --> SetPlaygroundContext
Related issues: None specified. Related PRs: None specified. Suggested labels: None specified. Suggested reviewers: None specified. 🐰 A chapter stored, a variant too, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Revived this: merged @RichDom2185 — to address your note that it behaved differently from what the issue suggests: the invalid-combination fallback now resets to Prettier/eslint/tsc clean; CI re-running. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/pages/createStore.ts (1)
87-105: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFallback logic correctly validates the combined pair.
This correctly matches the PR intent: it checks the stored chapter+variant as a single combination against
ALL_LANGUAGESand falls back todefaultLanguageConfigfor both fields together (rather than resolving chapter and variant independently), avoiding the "Language config not found" crash described in the linked issue.One nit: this validity check duplicates the same
ALL_LANGUAGES.findlogic already encapsulated ingetLanguageConfig(src/commons/application/ApplicationTypes.ts). Consider reusing that helper (wrapped in try/catch) instead of re-implementing the lookup here, to keep a single source of truth for "what counts as a valid chapter/variant pair."♻️ Optional refactor using existing helper
context: (() => { const chapter = loadedStore.playgroundSourceChapter ? loadedStore.playgroundSourceChapter : defaultState.workspaces.playground.context.chapter; const variant = loadedStore.playgroundSourceVariant ? loadedStore.playgroundSourceVariant : defaultState.workspaces.playground.context.variant; - const validCombination = ALL_LANGUAGES.some( - lang => lang.chapter === chapter && lang.variant === variant, - ); + let validCombination = true; + try { + getLanguageConfig(chapter, variant); + } catch { + validCombination = false; + } // 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 : defaultLanguageConfig.chapter, variant: validCombination ? variant : defaultLanguageConfig.variant, }; })(),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/createStore.ts` around lines 87 - 105, The fallback in createStore() is validating chapter and variant correctly, but it reimplements the language-pair lookup logic already centralized in getLanguageConfig. Update the playground context initialization to reuse getLanguageConfig from ApplicationTypes instead of duplicating ALL_LANGUAGES.some, and wrap that helper call in try/catch so invalid stored combinations still fall back to defaultLanguageConfig as a pair.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/pages/createStore.ts`:
- Around line 87-105: The fallback in createStore() is validating chapter and
variant correctly, but it reimplements the language-pair lookup logic already
centralized in getLanguageConfig. Update the playground context initialization
to reuse getLanguageConfig from ApplicationTypes instead of duplicating
ALL_LANGUAGES.some, and wrap that helper call in try/catch so invalid stored
combinations still fall back to defaultLanguageConfig as a pair.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 50216437-776a-4e6f-9d01-7d8a5f6a9aec
📒 Files selected for processing (1)
src/pages/createStore.ts
AI-generated PR, fixing #3645
Generated with Claude Code, Sonnet 4.6.
Description
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).
Type of change
How to test
Start frontend using localhost, switch to conductor in feature flags, choose Source 1. Then reload in the browser. This would crash the frontend when the feature flag is reset to false, because the "Source 1" language does not have a CSE machine implementation.
Checklist