diff --git a/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx b/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx
index 96a17ae80c2..66f2923aaf2 100644
--- a/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx
+++ b/apps/app/src/components/dialogs/ProjectPathDialog.test.tsx
@@ -92,7 +92,7 @@ describe("ProjectPathDialog machine selection", () => {
);
});
- it("preserves the direct single-machine folder flow", () => {
+ it("preserves the direct single-machine folder flow", async () => {
const onSubmit = vi.fn();
render(
{label} Loading cached {label} Loading prepared Lazy readyReport
");
diff --git a/apps/app/src/lib/define-split.test.tsx b/apps/app/src/lib/define-split.test.tsx
index f705ecf475c..7156f9ff9f1 100644
--- a/apps/app/src/lib/define-split.test.tsx
+++ b/apps/app/src/lib/define-split.test.tsx
@@ -12,6 +12,9 @@ import { afterEach, expect, it, vi } from "vitest";
import { downloadSplit } from "./split-prefetch";
import { defineSplit } from "./define-split";
+vi.unmock("react");
+vi.unmock("./define-split");
+
afterEach(() => {
cleanup();
vi.restoreAllMocks();
diff --git a/apps/app/src/test/lazy-modules.test.tsx b/apps/app/src/test/lazy-modules.test.tsx
index e35d5b78aa9..b87faa01336 100644
--- a/apps/app/src/test/lazy-modules.test.tsx
+++ b/apps/app/src/test/lazy-modules.test.tsx
@@ -2,7 +2,8 @@
import { cleanup, render, screen } from "@testing-library/react";
import { lazy, Suspense, type ComponentType } from "react";
-import { afterEach, expect, it, vi } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { defineSplit } from "@/lib/define-split";
import { settleLazyModules } from "./lazy-modules";
afterEach(cleanup);
@@ -80,3 +81,63 @@ it("lets findBy wait for an import that starts a microtask after render and outl
expect(await screen.findByText("Slow")).toBeTruthy();
});
+
+const CachedSplit = defineSplit<{ label: string }>({
+ id: "lazy-modules-test-cached",
+ load: () =>
+ trackedImport(({ label }: { label: string }) =>
( + key: unknown, + specifier: string, + loadedGeneration: number, + View: ComponentType
, + lazy: typeof React.lazy, +): React.ElementType
{ + const state = lazyImportState(); + const existing = state.renderGates.get(key); + if (existing !== undefined) return existing as React.ElementType
; + const chosen: React.ElementType
=
+ state.holding &&
+ loadedGeneration < state.generation &&
+ !state.prepared.has(key)
+ ? (() => {
+ const gate = trackLazyImport(Promise.resolve(), specifier);
+ return lazy(() => gate.then(() => ({ default: View })));
+ })()
+ : View;
+ state.renderGates.set(key, chosen as React.ElementType);
+ return chosen;
+}
+
+function beginLazyModuleTestFile(): void {
+ const state = lazyImportState();
+ state.collecting = true;
+ state.prepared.clear();
+}
+
+export function prepareLazyModuleForFile(key: string): void {
+ const state = lazyImportState();
+ if (state.collecting) state.prepared.add(key);
+}
+
function releaseHeldImports(state: LazyImportState): void {
for (const held of state.held.splice(0)) held.release();
}
@@ -66,12 +118,15 @@ async function reactAct(run: () => Promise (
+ key: string,
+ View: ComponentType ,
+): ComponentType {
+ const loadedIn = lazyModuleGeneration();
+ function GatedLoadedComponent(props: P) {
+ const react = loadedReact();
+ const Gated = gatedLazyComponent(key, key, loadedIn, View, react.lazy);
+ return react.createElement(Gated, props);
+ }
+ return GatedLoadedComponent;
+}
+
+export function gateReactLazy