crash-restart.fixture.tsx 811 B

123456789101112131415161718192021222324
  1. import { createRoot } from "react-dom/client";
  2. import { AppErrorBoundary } from "@/ErrorBoundary.js";
  3. import "@/styles.css";
  4. const params = new URLSearchParams(location.search);
  5. localStorage.setItem("zcode-locale-preference", params.get("locale") ?? "en-US");
  6. document.documentElement.className =
  7. params.get("theme") === "light" ? "theme-zai-light" : "theme-zai-dark dark";
  8. function Broken(): never {
  9. throw new Error("E2E_CRASH_RESTART_COMPONENT");
  10. }
  11. const restart =
  12. params.get("desktop") === "1"
  13. ? async () => {
  14. document.body.dataset.restartCount = String(
  15. Number(document.body.dataset.restartCount ?? 0) + 1,
  16. );
  17. }
  18. : undefined;
  19. createRoot(document.getElementById("root")!).render(
  20. <AppErrorBoundary onRestart={restart}>
  21. <Broken />
  22. </AppErrorBoundary>,
  23. );