Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/livecodes/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1523,18 +1523,10 @@ const applyConfig = async (newConfig: Partial<Config>, reload = false) => {
...getEditorConfig(newConfig as Config),
...getFormatterConfig(newConfig as Config),
};

const hasEditorConfig = Object.values(editorConfig).some((value) => value != null);
if (hasEditorConfig) {
for (const key in editorConfig) {
if (
key in newConfig &&
(editorConfig as any)[key] !== (currentEditorConfig as any)[key] &&
!key.toLowerCase().includes('theme')
) {
shouldReloadEditors = true;
break;
}
}
if (hasEditorConfig && newConfig.editor && newConfig.editor !== currentEditorConfig.editor) {
shouldReloadEditors = true;
}
if ('configureTailwindcss' in editors.markup) {
if (newConfig.processors?.includes('tailwindcss')) {
Expand All @@ -1550,6 +1542,12 @@ const applyConfig = async (newConfig: Partial<Config>, reload = false) => {
}
if (shouldReloadEditors) {
await reloadEditors(combinedConfig);
} else if (hasEditorConfig) {
currentEditorConfig = {
...getEditorConfig(combinedConfig),
...getFormatterConfig(combinedConfig),
};
getAllEditors().forEach((editor) => editor.changeSettings(currentEditorConfig));
}
Comment on lines +1550 to 1555
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Guard against undefined editors before calling changeSettings.

getAllEditors() includes optional editors (console, compiled panes) and yields undefined until those panes are created. Calling editor.changeSettings(...) without a guard throws a TypeError, breaking the config update path. Restore the null check when iterating.

-    getAllEditors().forEach((editor) => editor.changeSettings(currentEditorConfig));
+    getAllEditors().forEach((editor) => editor?.changeSettings(currentEditorConfig));
🤖 Prompt for AI Agents
In src/livecodes/core.ts around lines 1546 to 1551, the loop over
getAllEditors() assumes every entry is defined and calls
editor.changeSettings(...), which can throw when optional editors are undefined;
restore a null-check by skipping undefined editors before calling changeSettings
(e.g., continue if editor is falsy) or use optional chaining to call
editor.changeSettings only when editor exists.


parent.dispatchEvent(new Event(customEvents.ready));
Expand Down