Major Refactor: Move js-slang evaluation context out of Redux #3295
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a major architectural refactor to move mutable js-slang evaluation contexts out of Redux state, resolving critical issues with immutability violations and Immer compatibility.
Problem
The current implementation stores mutable js-slang
Context
objects directly in Redux state, which violates two fundamental Redux principles:This has caused significant issues:
setAutoFreeze(false)
)Solution
Implemented a global context store that manages js-slang contexts outside of Redux:
Core Architecture
Migration Pattern
Before:
After:
Implementation Details
Files Changed
JsSlangContextStore.ts
- Global singleton with Map-based storageuseJsSlangContext.ts
- Transparent context access for componentsWorkspaceTypes.ts
- Changedcontext: Context
tocontextId: string
WorkspaceReducer.ts
,ApplicationTypes.ts
,createStore.ts
Key Benefits
✅ Redux Compliance - State is now fully immutable with only primitives
✅ Mutable Contexts - js-slang contexts can be mutated during evaluation as needed
✅ Immer Compatible - No more auto-freezing conflicts
✅ Circular References - Context objects with circular data structures work properly
✅ Performance - Reduced Redux payload size and serialization overhead
✅ Transparency - Existing component patterns preserved via custom hook
Testing
Added comprehensive test suite (9/9 tests passing) covering:
Backward Compatibility
The refactor maintains full backward compatibility through the
useJsSlangContext()
hook, which abstracts away the complexity of the new architecture. Most existing component code requires minimal changes.Example Usage
This architectural change resolves the fundamental Redux violations while maintaining a clean, performant, and maintainable codebase.
Fixes #3294.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.