-
-
Notifications
You must be signed in to change notification settings - Fork 213
Description
Bug Report 🐛
While exploring the playground architecture, I noticed a race condition with the Monaco Editor instances and a rendering bottleneck tied to the global state management.
Expected Behavior
Syntax error markers generated by the Concerto compiler should exclusively attach to the Concerto editor model. Furthermore, typing inside the editor should only trigger React re-renders for components directly consuming the modified state.
Current Behavior
The ConcertoEditor component attempts to apply error markers by grabbing the first model from the global Monaco instance (monacoInstance.editor.getModels()?.[0]). Because multiple editors (JSON, Markdown, Concerto) mount concurrently, the global index [0] is not guaranteed to be the Concerto model. This causes error markers to either fail silently or attach to the wrong editor panel (like the JSON editor).
Additionally, the Zustand store selectors in ConcertoEditor.tsx and App.tsx return new object references on every state change. Because Zustand uses strict equality by default, this forces full component re-renders on every single keystroke, causing noticeable UI lag.
Possible Solution
- Capture the specific
IStandaloneCodeEditorinstance using auseRefduring the MonacoonMountevent, and apply markers explicitly toeditorRef.current.getModel(). - Wrap all object-returning Zustand selectors in
useShallowfromzustand/react/shallowto memoize the state and prevent unnecessary render cycles.
Steps to Reproduce
- Launch the
template-playgroundlocal development server. - Open the UI with both the Concerto and JSON editor panels visible side-by-side.
- Introduce a deliberate syntax error (e.g., delete a closing brace) in the Concerto editor.
- Observe the red error markers failing to appear on the Concerto text, or incorrectly appearing on the JSON text.
- Open React DevTools Profiler, record a session, type a few characters in the editor, and observe the entire component tree re-rendering.
Context (Environment)
This affects the core developer experience within the playground, making debugging Concerto models confusing when errors map to the wrong panels, and degrading typing performance.
Desktop
- OS: Windows / macOS / Linux
- Browser: Chrome / Firefox / Safari
- Version: Latest
mainbranch
Detailed Description
The root of the issue lies in relying on the global monacoInstance array to identify specific text models in a multi-editor environment. By scoping the model directly to the React component that spawns it, we eliminate the race condition. For the performance issue, Zustand's default strict equality fails when a selector returns a constructed object, which requires a shallow comparison hook to resolve.
Possible Implementation
I will open a Pull Request utilizing useRef to scope the Monaco instance in ConcertoEditor.tsx, and integrate useShallow across the primary editor components to optimize the React render tree.