fix: Excalidraw loading forever — ReactDOM.createRoot undefined
CI / lint (push) Failing after 21s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / e2e (push) Has been skipped
CI / security (push) Successful in 17s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
CI / lint (push) Failing after 21s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / e2e (push) Has been skipped
CI / security (push) Successful in 17s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
Root cause: 'import ReactDOM from react-dom' resolves to the root react-dom package which does NOT export createRoot in React 18. createRoot lives in react-dom/client. Changes: - Changed import to 'react-dom/client' (line 109) - Added error handling around the render call so loading spinner shows an error message instead of spinning forever on failures
This commit is contained in:
@@ -106,7 +106,7 @@
|
||||
<!-- Single module script -->
|
||||
<script type="module">
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import { decompressFromBase64 } from "https://esm.sh/[email protected]";
|
||||
import * as ExcalidrawLib from "https://esm.sh/@excalidraw/[email protected]?alias=react:[email protected],react-dom:[email protected]";
|
||||
|
||||
@@ -246,12 +246,22 @@
|
||||
currentTheme = msg.theme || "light";
|
||||
setTheme(currentTheme);
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
React.createElement(App, {
|
||||
initialData: initialData,
|
||||
theme: currentTheme,
|
||||
})
|
||||
);
|
||||
try {
|
||||
if (typeof ReactDOM.createRoot !== "function") {
|
||||
throw new Error("ReactDOM.createRoot is not available — check react-dom/client import");
|
||||
}
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
React.createElement(App, {
|
||||
initialData: initialData,
|
||||
theme: currentTheme,
|
||||
})
|
||||
);
|
||||
} catch (renderErr) {
|
||||
console.error("Excalidraw render failed:", renderErr);
|
||||
loadingEl.textContent = "Error loading Excalidraw: " + renderErr.message;
|
||||
loadingEl.style.color = "#f44336";
|
||||
loadingEl.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user