fix(renderer): remove let ModalManager to prevent SyntaxError on load

ModalManager.js is loaded via <script> tag in index.html, which
declares class ModalManager in the global script scope. renderer.js
was then doing 'let ModalManager;' which caused:
  SyntaxError: Identifier 'ModalManager' has already been declared

This prevented renderer.js from executing at all, breaking tabs,
editor, file open, and preview rendering.

Fix: conditionally require ModalManager only if undefined, without
re-declaring. In sloppy mode this safely assigns to the existing global.

Amit Haridas
This commit is contained in:
2026-06-03 15:25:22 +05:30
parent 272215f9af
commit c574d77c20
+4 -7
View File
@@ -11,13 +11,10 @@ const DOMPurify = createDOMPurify(window);
const hljs = require('highlight.js'); const hljs = require('highlight.js');
const { createEditor } = require('./editor/codemirror-setup'); const { createEditor } = require('./editor/codemirror-setup');
const { undo, redo } = require('@codemirror/commands'); const { undo, redo } = require('@codemirror/commands');
// Use window.ModalManager if already set by script tag, otherwise require it. // ModalManager is loaded via <script src="utils/ModalManager.js"> in index.html.
// This prevents "Identifier 'ModalManager' has already been declared" when // It already exists in the global scope — re-declaring with let/const causes
// both the script tag in index.html and CommonJS require() declare it. // SyntaxError: "Identifier 'ModalManager' has already been declared".
let ModalManager; if (typeof ModalManager === 'undefined') {
if (typeof window !== 'undefined' && window.ModalManager) {
ModalManager = window.ModalManager;
} else {
const result = require('./utils/ModalManager'); const result = require('./utils/ModalManager');
ModalManager = result.ModalManager || result; ModalManager = result.ModalManager || result;
} }