Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: open the browser pane without React's Suspense reveal hold (#17335)

Daniel Hanec6d16063def
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index bd018a37682..57015449ec6 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -345,21 +345,17 @@ import {
saveChatItemAsProjectSource,
} from "./prompt-storage/prompt-storage-dialog";
import { ExportFormatItems } from "./components/export-format-items";
+import { lazyWithoutSuspense, preloadWhenIdle } from "@/lib/lazy-without-suspense";
-const BrowserPanel = lazy(() =>
- import("@/features/browser/browser-panel").then((module) => ({
- default: module.BrowserPanel,
- })),
+// Not lazy(): a Suspense reveal is held up to 300 ms, which was most of the pane's first open.
+const BrowserPanel = lazyWithoutSuspense(() =>
+ import("@/features/browser/browser-panel").then((module) => module.BrowserPanel),
);
-const FullViewChatBar = lazy(() =>
- import("@/features/browser/full-view-chat").then((module) => ({
- default: module.FullViewChatBar,
- })),
+const FullViewChatBar = lazyWithoutSuspense(() =>
+ import("@/features/browser/full-view-chat").then((module) => module.FullViewChatBar),
);
-const FullViewChatButton = lazy(() =>
- import("@/features/browser/full-view-chat").then((module) => ({
- default: module.FullViewChatButton,
- })),
+const FullViewChatButton = lazyWithoutSuspense(() =>
+ import("@/features/browser/full-view-chat").then((module) => module.FullViewChatButton),
);
// Sandboxed page frames stay outside the trap: same-origin access would weaken their isolation.
@@ -681,6 +677,8 @@ const SingleContent = memo(function SingleContent({
const browserOpen = useBrowserStore((state) => state.open);
const browserOpenSequence = useBrowserStore((state) => state.openSequence);
const closeBrowser = useBrowserStore((state) => state.closePanel);
+ // Load the pane's module at idle (about 25 ms once) so its first open mounts with the click.
+ useEffect(() => preloadWhenIdle(BrowserPanel.preload), []);
useBrowserChatHost(chatActive);
useStagedFixPrompt(pendingFixPrompt, chatActive);
const openResearchRunId = useResearchRunStore((state) => state.openRunId);
diff --git a/studio/frontend/src/lib/lazy-without-suspense.tsx b/studio/frontend/src/lib/lazy-without-suspense.tsx
new file mode 100644
index 00000000000..804714ead72
--- /dev/null
+++ b/studio/frontend/src/lib/lazy-without-suspense.tsx
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import { type ComponentType, useEffect, useReducer, useState } from "react";
+import { onceLoader } from "./once-loader";
+
+export type LazyWithoutSuspense<P extends object> = ComponentType<P> & {
+ preload: () => Promise<ComponentType<P>>;
+};
+
+/**
+ * A code-split component that never suspends. React 19 holds a Suspense reveal for up to
+ * 300 ms after its fallback commits, so a `lazy()` panel waits that long on its first open
+ * even when its chunk is already loaded. This renders nothing until the module resolves,
+ * then the component itself; once loaded it renders synchronously. A failed import is
+ * thrown from render (as `lazy()` would) and retried on the next mount.
+ */
+export function lazyWithoutSuspense<P extends object>(
+ load: () => Promise<ComponentType<P>>,
+): LazyWithoutSuspense<P> {
+ const loader = onceLoader(load);
+
+ function Deferred(props: P) {
+ const [, rerender] = useReducer((count: number) => count + 1, 0);
+ const [failure, setFailure] = useState<{ error: unknown } | null>(null);
+ const Component = loader.current();
+ const renderedLoaded = Component !== null;
+ useEffect(() => {
+ // A load that finished between this render and the effect still re-renders: load() resolves at once.
+ if (renderedLoaded) return;
+ let live = true;
+ loader.load().then(
+ () => {
+ if (live) rerender();
+ },
+ (error: unknown) => {
+ if (live) setFailure({ error });
+ },
+ );
+ return () => {
+ live = false;
+ };
+ }, [renderedLoaded]);
+ if (failure) throw failure.error;
+ return Component ? <Component {...props} /> : null;
+ }
+
+ return Object.assign(Deferred, { preload: loader.load });
+}
+
+type IdleWindow = Window & {
+ requestIdleCallback?: (callback: () => void, options?: { timeout: number }) => number;
+ cancelIdleCallback?: (handle: number) => void;
+};
+
+/** Starts `preload` once the page is idle (a timer where idle callbacks are missing, as in Safari); returns a cancel. */
+export function preloadWhenIdle(preload: () => Promise<unknown>, fallbackDelayMs = 1500): () => void {
+ const warm = () => {
+ // A failed warm-up is retried by the next mount; the panel itself reports the error.
+ preload().catch(() => {});
+ };
+ const idle = window as IdleWindow;
+ if (typeof idle.requestIdleCallback === "function") {
+ const handle = idle.requestIdleCallback(warm, { timeout: 4000 });
+ return () => idle.cancelIdleCallback?.(handle);
+ }
+ const handle = window.setTimeout(warm, fallbackDelayMs);
+ return () => window.clearTimeout(handle);
+}
diff --git a/studio/frontend/src/lib/once-loader.ts b/studio/frontend/src/lib/once-loader.ts
new file mode 100644
index 00000000000..e9c3130abb1
--- /dev/null
+++ b/studio/frontend/src/lib/once-loader.ts
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+export type OnceLoader<T> = {
+ /** The loaded value, or null until the first load resolves. */
+ current: () => T | null;
+ /** Starts the load once; concurrent callers share it, and a failure lets the next call retry. */
+ load: () => Promise<T>;
+};
+
+export function onceLoader<T>(load: () => Promise<T>): OnceLoader<T> {
+ let value: { loaded: T } | null = null;
+ let pending: Promise<T> | null = null;
+ return {
+ current: () => (value ? value.loaded : null),
+ load: () => {
+ if (value) return Promise.resolve(value.loaded);
+ pending ??= load().then(
+ (loaded) => {
+ value = { loaded };
+ return loaded;
+ },
+ (error: unknown) => {
+ pending = null;
+ throw error;
+ },
+ );
+ return pending;
+ },
+ };
+}
diff --git a/studio/frontend/tests/lazy-without-suspense.test.ts b/studio/frontend/tests/lazy-without-suspense.test.ts
new file mode 100644
index 00000000000..a51d63d0eb2
--- /dev/null
+++ b/studio/frontend/tests/lazy-without-suspense.test.ts
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { test } from "node:test";
+import { onceLoader } from "../src/lib/once-loader.ts";
+
+test("onceLoader loads once, shares the pending load and exposes the value", async () => {
+ let calls = 0;
+ const loader = onceLoader(async () => {
+ calls += 1;
+ return "panel";
+ });
+ assert.equal(loader.current(), null);
+ const [a, b] = await Promise.all([loader.load(), loader.load()]);
+ assert.deepEqual([a, b, calls, loader.current()], ["panel", "panel", 1, "panel"]);
+ assert.equal(await loader.load(), "panel");
+ assert.equal(calls, 1);
+});
+
+test("onceLoader retries after a failed load", async () => {
+ let calls = 0;
+ const loader = onceLoader(async () => {
+ calls += 1;
+ if (calls === 1) throw new Error("chunk failed");
+ return 7;
+ });
+ await assert.rejects(loader.load(), /chunk failed/);
+ assert.equal(loader.current(), null);
+ assert.equal(await loader.load(), 7);
+ assert.equal(calls, 2);
+});
+
+test("the browser pane is code-split without Suspense, so its first open is not held 300 ms", () => {
+ const source = readFileSync(new URL("../src/features/chat/chat-page.tsx", import.meta.url), "utf8");
+ assert.match(source, /const BrowserPanel = lazyWithoutSuspense\(\(\) =>\s*import\("@\/features\/browser\/browser-panel"\)/);
+ assert.doesNotMatch(source, /lazy\(\(\) =>\s*import\("@\/features\/browser\/browser-panel"\)/);
+ assert.match(source, /useEffect\(\(\) => preloadWhenIdle\(BrowserPanel\.preload\), \[\]\);/);
+ for (const name of ["FullViewChatBar", "FullViewChatButton"]) {
+ assert.match(source, new RegExp(`const ${name} = lazyWithoutSuspense\\(`));
+ }
+ const helper = readFileSync(new URL("../src/lib/lazy-without-suspense.tsx", import.meta.url), "utf8");
+ assert.doesNotMatch(helper.match(/import \{[^}]*\} from "react";/)?.[0] ?? "", /\bSuspense\b|\blazy\b/);
+ assert.match(helper, /if \(failure\) throw failure\.error;/);
+ // A load that resolves between render and the effect must still re-render: the effect keys on what render saw.
+ const effect = helper.match(/useEffect\(\(\) => \{[\s\S]*?\}, \[renderedLoaded\]\);/)?.[0];
+ assert.ok(effect, "the load effect depends on the render-time loaded flag");
+ assert.doesNotMatch(effect, /loader\.current\(\)/);
+});