The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Hub pages stay drawn while they hydrate; late tabs show a skeleton
Adarsh99e533f148f2
diff --git a/src/app/(studio)/audio/layout.tsx b/src/app/(studio)/audio/layout.tsxindex fb7e5ceb..0bda4271 100644--- a/src/app/(studio)/audio/layout.tsx+++ b/src/app/(studio)/audio/layout.tsx@@ -1,6 +1,11 @@+import { HubBodySkeleton } from "@/components/skeletons";import { HubFrame } from "@/components/studio/hub-chrome";/** The hub's title bar and mode tabs: shared by /audio and /audio/<mode>, so a tab switch keeps them on screen. */export default function Layout({ children }: { children: React.ReactNode }) {- return <HubFrame kind="audio">{children}</HubFrame>;+ return (+ <HubFrame kind="audio" skeleton={<HubBodySkeleton />}>+ {children}+ </HubFrame>+ );}diff --git a/src/app/(studio)/audio/loading.tsx b/src/app/(studio)/audio/loading.tsxnew file mode 100644index 00000000..ecec4d27--- /dev/null+++ b/src/app/(studio)/audio/loading.tsx@@ -0,0 +1,6 @@+import { HubBodySkeleton } from "@/components/skeletons";++/** A mode whose page is still on its way: its body's skeleton, under the hub's title bar and tabs (the layout). */+export default function Loading() {+ return <HubBodySkeleton />;+}diff --git a/src/app/(studio)/upscale/layout.tsx b/src/app/(studio)/upscale/layout.tsxindex 8bbee557..76da899b 100644--- a/src/app/(studio)/upscale/layout.tsx+++ b/src/app/(studio)/upscale/layout.tsx@@ -1,6 +1,11 @@+import { HubBodySkeleton } from "@/components/skeletons";import { HubFrame } from "@/components/studio/hub-chrome";/** The hub's title bar and mode tabs: shared by /upscale and /upscale/<mode>, so a tab switch keeps them on screen. */export default function Layout({ children }: { children: React.ReactNode }) {- return <HubFrame kind="upscale">{children}</HubFrame>;+ return (+ <HubFrame kind="upscale" skeleton={<HubBodySkeleton />}>+ {children}+ </HubFrame>+ );}diff --git a/src/app/(studio)/upscale/loading.tsx b/src/app/(studio)/upscale/loading.tsxnew file mode 100644index 00000000..ecec4d27--- /dev/null+++ b/src/app/(studio)/upscale/loading.tsx@@ -0,0 +1,6 @@+import { HubBodySkeleton } from "@/components/skeletons";++/** A mode whose page is still on its way: its body's skeleton, under the hub's title bar and tabs (the layout). */+export default function Loading() {+ return <HubBodySkeleton />;+}diff --git a/src/app/(studio)/video-tools/layout.tsx b/src/app/(studio)/video-tools/layout.tsxindex 003f6aaa..ac93f6f3 100644--- a/src/app/(studio)/video-tools/layout.tsx+++ b/src/app/(studio)/video-tools/layout.tsx@@ -1,6 +1,11 @@+import { HubBodySkeleton } from "@/components/skeletons";import { HubFrame } from "@/components/studio/hub-chrome";/** The hub's title bar and mode tabs: shared by /video-tools and /video-tools/<mode>, so a tab switch keeps them on screen. */export default function Layout({ children }: { children: React.ReactNode }) {- return <HubFrame kind="video-tools">{children}</HubFrame>;+ return (+ <HubFrame kind="video-tools" skeleton={<HubBodySkeleton />}>+ {children}+ </HubFrame>+ );}diff --git a/src/app/(studio)/video-tools/loading.tsx b/src/app/(studio)/video-tools/loading.tsxnew file mode 100644index 00000000..ecec4d27--- /dev/null+++ b/src/app/(studio)/video-tools/loading.tsx@@ -0,0 +1,6 @@+import { HubBodySkeleton } from "@/components/skeletons";++/** A mode whose page is still on its way: its body's skeleton, under the hub's title bar and tabs (the layout). */+export default function Loading() {+ return <HubBodySkeleton />;+}diff --git a/src/components/studio/hub-chrome.tsx b/src/components/studio/hub-chrome.tsxindex 66e8985f..c5652324 100644--- a/src/components/studio/hub-chrome.tsx+++ b/src/components/studio/hub-chrome.tsx@@ -1,8 +1,8 @@"use client";-import Link from "next/link";+import Link, { useLinkStatus } from "next/link";import { usePathname, useRouter } from "next/navigation";-import { createContext, Suspense, useContext, useEffect, useMemo, useRef, useState } from "react";+import { createContext, Suspense, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";import { createPortal } from "react-dom";import { SidebarTrigger } from "@/components/ui/sidebar";import { EngineSwitch } from "@/components/studio/engine-switch";@@ -20,19 +20,67 @@ import { useEdgeFade } from "./use-edge-fade";* pill, a tool's extra buttons) into the bar with <HubHeaderExtras>.*/-const HubCtx = createContext<{ slot: HTMLElement | null } | null>(null);+/**+ * Where a frame's page puts its header controls: the element in the frame's own title bar. A store rather than a value+ * passed down, so the context never changes after the first render: a context change that reaches a part of the page+ * still waiting to hydrate makes React throw that part's server HTML away and show its skeleton until its code arrives.+ */+interface SlotStore {+ get: () => HTMLElement | null;+ set: (el: HTMLElement | null) => void;+ subscribe: (cb: () => void) => () => void;+}++function createSlotStore(): SlotStore {+ let slot: HTMLElement | null = null;+ const listeners = new Set<() => void>();+ return {+ get: () => slot,+ set: (el) => {+ if (el === slot) return;+ slot = el;+ for (const l of listeners) l();+ },+ subscribe: (cb) => {+ listeners.add(cb);+ return () => {+ listeners.delete(cb);+ };+ },+ };+}++const HubCtx = createContext<SlotStore | null>(null);+const noSlot = () => null;+const noSubscribe = () => () => {};/** Inside a hub's frame: the page leaves the title bar and tabs to it. */export function useInHub(): boolean {return useContext(HubCtx) !== null;}-/** A page's own header controls, shown in the hub's title bar left of the engine switch. */+/** A page's own header controls, shown in its hub's title bar left of the engine switch. */export function HubHeaderExtras({ children }: { children: React.ReactNode }) {- const slot = useContext(HubCtx)?.slot;+ const store = useContext(HubCtx);+ const slot = useSyncExternalStore(store?.subscribe ?? noSubscribe, store?.get ?? noSlot, noSlot);return slot ? createPortal(children, slot) : null;}+/**+ * Reports while its tab's navigation waits (useLinkStatus is pending only when the page wasn't prefetched yet; a+ * prefetched page skips it). Inside the tab's <Link>.+ */+function TabWaiting({ onWaiting }: { onWaiting?: (waiting: boolean) => void }) {+ const { pending } = useLinkStatus();+ // Before paint: when the page arrives, the skeleton goes in the same frame.+ useLayoutEffect(() => {+ if (!pending || !onWaiting) return;+ onWaiting(true);+ return () => onWaiting(false);+ }, [pending, onWaiting]);+ return null;+}+/*** The hub's mode tabs: underline tabs on their own row under the title; they scroll sideways (with faded edges) on* phones. Each mode is its own history entry, so Back returns to the mode before.@@ -41,7 +89,17 @@ export function HubHeaderExtras({ children }: { children: React.ReactNode }) {* page (each is prerendered, so the prefetch comes from the static cache), and the tabs a phone's row scrolls out of* view are prefetched too once the page is idle: a tap then renders the mode from the client cache, with no blank frame.*/-function HubTabs({ kind, pathname, onActive }: { kind: HubKind; pathname: string | null; onActive?: (mode: string) => void }) {+function HubTabs({+ kind,+ pathname,+ onActive,+ onWaiting,+}: {+ kind: HubKind;+ pathname: string | null;+ onActive?: (mode: string) => void;+ onWaiting?: (waiting: boolean) => void;+}) {const router = useRouter();const [ref, fade] = useEdgeFade<HTMLDivElement>();const activeRef = useRef<HTMLAnchorElement>(null);@@ -56,11 +114,16 @@ function HubTabs({ kind, pathname, onActive }: { kind: HubKind; pathname: stringif (active) onActive?.(active);}, [active, onActive]);- // Keep the selected tab in view when the row scrolls (only the row: the page stays put).+ // Keep the selected tab in view when the row scrolls (only the row: the page stays put). The first time, a row the+ // visitor already swiped before the page became interactive stays where they put it (a tap there is on its way).+ const placed = useRef(false);useEffect(() => {const el = activeRef.current;const row = ref.current;if (!el || !row) return;+ const first = !placed.current;+ placed.current = true;+ if (first && row.scrollLeft > 0) return;const left = el.offsetLeft - row.offsetLeft;if (left < row.scrollLeft || left + el.offsetWidth > row.scrollLeft + row.clientWidth) row.scrollLeft = left - 12;}, [active, ref]);@@ -98,6 +161,7 @@ function HubTabs({ kind, pathname, onActive }: { kind: HubKind; pathname: string)}>{m.label}+ <TabWaiting onWaiting={onWaiting} /></Link>);})}@@ -107,22 +171,42 @@ function HubTabs({ kind, pathname, onActive }: { kind: HubKind; pathname: string}/** Reads the path (runtime data while a route prerenders) inside Suspense; the fallback is the same row, unselected. */-function PathTabs({ kind, onActive }: { kind: HubKind; onActive: (mode: string) => void }) {+function PathTabs({ kind, onActive, onWaiting }: { kind: HubKind; onActive: (mode: string) => void; onWaiting: (waiting: boolean) => void }) {const pathname = usePathname();- return <HubTabs kind={kind} pathname={pathname} onActive={onActive} />;+ return <HubTabs kind={kind} pathname={pathname} onActive={onActive} onWaiting={onWaiting} />;}+/** How long a tapped tab's page may keep the old one on screen before the skeleton replaces it. */+export const HUB_SKELETON_AFTER_MS = 60;+function HubEngine({ kind, mode }: { kind: HubKind; mode: string | undefined }) {const [engine, setEngine] = useEngine();const selfHostedOnly = !!HUB_MODES[kind].find((m) => m.id === mode)?.selfHostedOnly;return <EngineSwitch value={engine} onChange={setEngine} selfHostedOnly={selfHostedOnly} />;}-/** The title bar and the tabs of a hub. `children`: the mode's page (or, while a route loads, its skeleton). */-export function HubFrame({ kind, children }: { kind: HubKind; children: React.ReactNode }) {- const [slot, setSlot] = useState<HTMLElement | null>(null);+/**+ * The title bar and the tabs of a hub. `children`: the mode's page (or, while a route loads, its skeleton). `skeleton`:+ * the page body's skeleton, shown in place of the old page when a tapped tab's page wasn't prefetched yet and hasn't come+ * within HUB_SKELETON_AFTER_MS (the old page stays mounted under it, so its state is kept if the tap is undone).+ */+export function HubFrame({ kind, skeleton, children }: { kind: HubKind; skeleton: React.ReactNode; children: React.ReactNode }) {+ // Made once: the context's value never changes (see SlotStore).+ const [store] = useState(createSlotStore);+ const slotRef = useCallback((el: HTMLElement | null) => store.set(el), [store]);const [mode, setMode] = useState<string | undefined>(undefined);- const ctx = useMemo(() => ({ slot }), [slot]);+ const [waiting, setWaiting] = useState(false);+ const [late, setLate] = useState(false);+ useEffect(() => {+ if (!waiting) return;+ const timer = window.setTimeout(() => setLate(true), HUB_SKELETON_AFTER_MS);+ return () => {+ window.clearTimeout(timer);+ setLate(false);+ };+ }, [waiting]);+ // `waiting` ends before paint when the page arrives, so the skeleton never covers the new page.+ const skeletonShown = waiting && late;return (<div className="flex min-h-svh min-w-0 flex-col" data-hub={kind}><div className="sticky top-0 z-20 bg-background/85 backdrop-blur" data-hub-chrome>@@ -130,16 +214,19 @@ export function HubFrame({ kind, children }: { kind: HubKind; children: React.Re<SidebarTrigger className="md:hidden" /><h1 className="min-w-0 truncate font-heading text-[22px] leading-[1.15]">{HUB_TITLE[kind]}</h1><div className="ml-auto flex shrink-0 items-center gap-2">- <div ref={setSlot} className="contents" />+ <div ref={slotRef} className="contents" /><HubEngine kind={kind} mode={mode} /></div></header><Suspense fallback={<HubTabs kind={kind} pathname={null} />}>- <PathTabs kind={kind} onActive={setMode} />+ <PathTabs kind={kind} onActive={setMode} onWaiting={setWaiting} /></Suspense></div>- <HubCtx.Provider value={ctx}>- <div className="flex min-w-0 flex-1 flex-col" data-hub-body>{children}</div>+ <HubCtx.Provider value={store}>+ <div className="flex min-w-0 flex-1 flex-col" data-hub-body>+ {skeletonShown && skeleton}+ <div className={skeletonShown ? "hidden" : "contents"}>{children}</div>+ </div></HubCtx.Provider></div>);@@ -147,7 +234,13 @@ export function HubFrame({ kind, children }: { kind: HubKind; children: React.Refunction PathSkeleton({ generic, hubBody }: { generic: React.ReactNode; hubBody: React.ReactNode }) {const hub = hubOfPath(usePathname());- return hub ? <HubFrame kind={hub}>{hubBody}</HubFrame> : generic;+ return hub ? (+ <HubFrame kind={hub} skeleton={hubBody}>+ {hubBody}+ </HubFrame>+ ) : (+ generic+ );}/**diff --git a/src/components/ui/sidebar.tsx b/src/components/ui/sidebar.tsxindex a4d9a7e9..a6d4b23b 100644--- a/src/components/ui/sidebar.tsx+++ b/src/components/ui/sidebar.tsx@@ -5,7 +5,7 @@ import { cva, type VariantProps } from "class-variance-authority"import { cn } from "cn"import { Slot } from "radix-ui"-import { useIsMobile } from "@/hooks/use-mobile"+import { useIsMobileAfterHydration } from "@/hooks/use-mobile"import { Button } from "@/components/ui/button"import { Input } from "@/components/ui/input"import { Separator } from "@/components/ui/separator"@@ -68,7 +68,7 @@ function SidebarProvider({/** Remember the expanded/collapsed choice in the cookie (off while a page decides it for itself). */persistOpen?: boolean}) {- const isMobile = useIsMobile()+ const isMobile = useIsMobileAfterHydration()const [openMobile, setOpenMobile] = React.useState(false)// This is the internal state of the sidebar.diff --git a/src/hooks/use-mobile.ts b/src/hooks/use-mobile.tsindex bdd2877a..65d2dbf9 100644--- a/src/hooks/use-mobile.ts+++ b/src/hooks/use-mobile.ts@@ -3,14 +3,31 @@ import * as React from "react"const MOBILE_BREAKPOINT = 768const QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`+function subscribe(cb: () => void) {+ const mql = window.matchMedia(QUERY)+ mql.addEventListener("change", cb)+ return () => mql.removeEventListener("change", cb)+}+export function useIsMobile() {return React.useSyncExternalStore(- (cb) => {- const mql = window.matchMedia(QUERY)- mql.addEventListener("change", cb)- return () => mql.removeEventListener("change", cb)- },+ subscribe,() => window.matchMedia(QUERY).matches,() => false,)}++/**+ * useIsMobile for a value that feeds a context over the whole page (the sidebar's). It starts as the server's answer and+ * takes the phone's in a transition after hydration: a plain update would reach parts of the page that are still+ * waiting to hydrate, and React would throw their server HTML away and show their skeletons until their code arrives.+ */+export function useIsMobileAfterHydration() {+ const [mobile, setMobile] = React.useState(false)+ React.useEffect(() => {+ const read = () => setMobile(window.matchMedia(QUERY).matches)+ React.startTransition(read)+ return subscribe(read)+ }, [])+ return mobile+}diff --git a/tests/e2e/instant-tabs.mjs b/tests/e2e/instant-tabs.mjsindex 4e09ea48..86b8b4ee 100644--- a/tests/e2e/instant-tabs.mjs+++ b/tests/e2e/instant-tabs.mjs@@ -6,7 +6,10 @@// 1. Hub tabs (Audio, Video tools, Upscale): the title and the tab row are on screen in every frame, the tapped tab is the// current one within two frames, and the area under the tabs always shows a page or its skeleton, never nothing.// Both after the page has settled (every mode prefetched: no request on the tap, no skeleton) and straight after load-// (nothing prefetched yet: the skeleton under the tabs may show).+// (nothing prefetched yet: the skeleton under the tabs may show). Within 100 ms of the tap the new page or its skeleton+// is there, never the old page.+// 1b. A fresh load of a mode (phone CPU 4× slower): once drawn, the page never goes blank or back to its skeleton, and a+// tab row swiped before the page is interactive stays where it was put.// 2. Going back to a mode shows that mode's header controls once (the hidden pages kept for Back add none), and Back marks// the tab of the page it returns to (Audio, the Marketing suite).// 2b. Marketing suite tabs: the tapped tab is current within two frames and the tab row never leaves.@@ -156,6 +159,9 @@ try {check(!blank.length, `the page under the tabs was blank in ${blank.length} frame(s), ${blank[0]?.ms}–${blank[blank.length - 1]?.ms} ms`);const moved = frames.findIndex((f) => f.current === sw.tab);check(moved >= 0 && moved <= 1, `the tapped tab became current only at frame ${moved} (${frames[moved]?.ms} ms)`);+ // Within 100 ms of the tap (a frame's slack) the area under the tabs is the new page or its skeleton, not the old page.+ const answered = frames.find((f) => f.path === sw.to || f.skeleton);+ check(answered && answered.ms <= 120, `neither ${sw.to} nor its skeleton showed within 100 ms (first at ${answered?.ms} ms)`);if (settled) {// Once the page has settled every mode is prefetched (ahead of the sidebar's routes): the switch is drawn from the// client cache, with no request and no skeleton.@@ -169,6 +175,47 @@ try {}}+ // A fresh load (a slow phone: CPU 4× slower): once the mode's page has drawn it stays drawn until it is interactive (a+ // context change that reaches a part still hydrating makes React swap its server HTML for the skeleton), and the area+ // under the hub's bar is never blank.+ for (const device of ["phone", "desktop"]) {+ for (const path of ["/audio/music", "/upscale/fps"]) {+ if (!step(`${device}, fresh load: ${path} draws once and never goes blank or back to its skeleton`)) continue;+ const { ctx, page } = await context(device);+ const cdp = await ctx.newCDPSession(page);+ await cdp.send("Emulation.setCPUThrottlingRate", { rate: 4 });+ await page.addInitScript((cfg) => {+ const go = () => (window.__frames ? window.__frames.start(cfg) : requestAnimationFrame(go));+ go();+ }, HUB);+ await page.goto(app + path, { waitUntil: "load" });+ await page.waitForTimeout(5000);+ const { list } = await page.evaluate(() => window.__frames.stop());+ const drawn = list.findIndex((f) => f.bar && f.body > 0 && !f.skeleton);+ check(drawn >= 0, `${path} never drew its page`);+ const flip = list.slice(drawn).filter((f) => f.body === 0 || f.skeleton);+ check(!flip.length, `after drawing at ${Math.round(list[drawn]?.t)} ms the page went back to ${flip[0]?.skeleton ? "its skeleton" : "blank"} in ${flip.length} frame(s)`);+ const blank = list.filter((f) => f.bar && f.body === 0 && !f.skeleton);+ check(!blank.length, `the area under the bar was blank in ${blank.length} frame(s) of the load`);+ await ctx.close();+ }+ }++ if (step("phone: a tab row swiped before the page is interactive stays where it was put")) {+ const { ctx, page } = await context("phone");+ await page.goto(`${app}/audio`, { waitUntil: "commit" });+ const row = `${HUB.bar} > div`;+ await page.waitForSelector(row, { state: "attached", timeout: 30_000 });+ await page.evaluate((sel) => {+ document.querySelector(sel).scrollLeft = 200;+ }, row);+ await page.waitForLoadState("load");+ await page.waitForTimeout(4000);+ const left = await page.evaluate((sel) => document.querySelector(sel).scrollLeft, row);+ check(left >= 150, `the row was scrolled back to ${left} px`);+ await ctx.close();+ }+if (step("going back to a mode shows its header controls once")) {const { ctx, page } = await context("desktop");await openRoute(page, `${app}/audio/music`, { settleMs: 2500 });diff --git a/tests/instant-tabs.test.ts b/tests/instant-tabs.test.tsindex b189f648..be497e59 100644--- a/tests/instant-tabs.test.ts+++ b/tests/instant-tabs.test.ts@@ -29,10 +29,39 @@ describe("hub tabs never leave the screen during a switch", () => {it("each hub's layout draws the title bar and the tabs, shared by every mode", () => {for (const kind of HUBS) {const layout = src(`src/app/(studio)/${kind}/layout.tsx`);- expect(layout).toContain(`<HubFrame kind="${kind}">`);+ expect(layout).toContain(`<HubFrame kind="${kind}" skeleton={<HubBodySkeleton />}>`);+ // A mode still on its way (a cold load's stream, a page not prefetched) is the body's skeleton under the hub's bar.+ expect(src(`src/app/(studio)/${kind}/loading.tsx`)).toMatch(/return <HubBodySkeleton \/>;/);}});+ it("the frame's context never changes after the first render, so it never reaches a part of the page still hydrating", () => {+ const chrome = src("src/components/studio/hub-chrome.tsx");+ expect(chrome).toMatch(/const \[store\] = useState\(createSlotStore\);/);+ expect(chrome).toMatch(/<HubCtx\.Provider value=\{store\}>/);+ expect(chrome).toMatch(/const slotRef = useCallback\(\(el: HTMLElement \| null\) => store\.set\(el\), \[store\]\);/);+ expect(chrome).toMatch(/<div ref=\{slotRef\} className="contents" \/>/);+ // The sidebar's context takes the phone's answer in a transition after hydration, for the same reason.+ expect(src("src/components/ui/sidebar.tsx")).toMatch(/const isMobile = useIsMobileAfterHydration\(\)/);+ expect(src("src/hooks/use-mobile.ts")).toMatch(/React\.startTransition\(read\)/);+ });++ it("a tapped tab whose page wasn't prefetched shows the body's skeleton within 100 ms, and never over a page that came", () => {+ const chrome = src("src/components/studio/hub-chrome.tsx");+ expect(Number(chrome.match(/export const HUB_SKELETON_AFTER_MS = (\d+);/)?.[1])).toBeLessThanOrEqual(70);+ // useLinkStatus is pending only while a navigation waits (a prefetched page skips it); it is reported before paint.+ const link = chrome.slice(chrome.indexOf("<Link"), chrome.indexOf("</Link>"));+ expect(link).toMatch(/<TabWaiting onWaiting=\{onWaiting\} \/>/);+ expect(chrome).toMatch(/const \{ pending \} = useLinkStatus\(\);\s+\/\/[^\n]*\n\s+useLayoutEffect\(/);+ expect(chrome).toMatch(/const skeletonShown = waiting && late;/);+ // The old page stays mounted under the skeleton.+ expect(chrome).toMatch(/<div className=\{skeletonShown \? "hidden" : "contents"\}>\{children\}<\/div>/);+ });++ it("a row swiped before the page is interactive stays where it was put", () => {+ expect(src("src/components/studio/hub-chrome.tsx")).toMatch(/if \(first && row\.scrollLeft > 0\) return;/);+ });+it("no mode page draws its own tabs, and the per-mode boundary has a skeleton, never an empty fallback", () => {const hub = src("src/components/studio/mode-switch-studio.tsx");expect(hub).not.toMatch(/fallback=\{null\}/);@@ -79,9 +108,10 @@ describe("other tab bars switch without a round trip", () => {expect(lib).not.toMatch(/router\.replace\(/);});- it("sidebar rows prefetch once the page is idle, not only on hover or touch", () => {+ it("the sidebar rows next to the open page's row prefetch once the page is idle; the others on hover, touch or focus", () => {const sidebar = src("src/components/app-sidebar.tsx");- expect(sidebar).toMatch(/<IntentLink\s+href=\{item\.href\}\s+eager=\{item\.eager\}\s+settled\s/);+ expect(sidebar).toMatch(/const NEAR_ROWS = 2;/);+ expect(sidebar).toMatch(/<IntentLink\s+href=\{item\.href\}\s+eager=\{item\.eager\}\s+settled=\{here >= 0 && i !== here && Math\.abs\(i - here\) <= NEAR_ROWS\}\s/);// The clicked row is the open page's row from the next frame on, in every group; the address takes over once it moves.expect(sidebar).toMatch(/onClick=\{\(e\) => isPlainClick\(e\) && setTappedRow\(item\.href\)\}/);expect(sidebar).toMatch(/useLayoutEffect\(\(\) => setTappedRow\(null\), \[pathname, search\]\);/);@@ -120,11 +150,11 @@ describe("other tab bars switch without a round trip", () => {expect(lib).toMatch(/if \(set && set\.from !== routed\.toString\(\)\) setSet\(null\);/);});- it("gallery categories mark the chip in an urgent render and filter the grid in a deferred one", () => {+ it("gallery categories change the chip and the grid in the same frame", () => {+ // A deferred grid marked the chip a little sooner but showed the filtered grid much later.const gallery = src("src/components/preset-gallery.tsx");- expect(gallery).toMatch(/const listCat = useDeferredValue\(cat\);/);- expect(gallery).toMatch(/aria-pressed=\{cat === c\}/);- expect(gallery).not.toMatch(/p\.category === cat\)/);+ expect(gallery).not.toMatch(/useDeferredValue\(cat\)/);+ expect(gallery).toMatch(/p\.category === cat\)/);});it("the studio's route skeleton keeps a hub's bar and tabs on the way in", () => {@@ -239,6 +269,27 @@ describe("idle prefetches: the page's own tabs go before the sidebar's routes",expect(order).toEqual(["row image"]);});+ it("drops the sidebar's idle prefetches for someone who asked to save data, never the page's own tabs", async () => {+ const { queueIdlePrefetch } = await load();+ vi.stubGlobal("navigator", { connection: { saveData: true } });+ queueIdlePrefetch("nav", "/image", () => order.push("row image"));+ queueIdlePrefetch("page", "/audio/music", () => order.push("tab music"));+ idle[0]();+ tick(9000);+ expect(order).toEqual(["tab music"]);+ });++ it('relies on Next still reading router.prefetch\'s undocumented `kind` ("full": the whole page, not only the shell)', async () => {+ const next = (p: string) => fs.readFileSync(path.join(__dirname, "..", "node_modules/next/dist/client/components", p), "utf8");+ const prefetch = next("prefetch.js");+ expect(prefetch).toMatch(/const prefetchKind = options\?\.kind \?\? _routerreducertypes\.PrefetchKind\.AUTO;/);+ expect(prefetch).toMatch(/case _routerreducertypes\.PrefetchKind\.FULL:\s*\{\s*fetchStrategy = _types\.FetchStrategy\.Full;/);+ expect(next("router-reducer/router-reducer-types.js")).toMatch(/PrefetchKind\["FULL"\] = "full";/);+ const { prefetchOptions } = await load();+ expect(prefetchOptions(true)).toMatchObject({ kind: "full" });+ expect(prefetchOptions(false)).toMatchObject({ kind: "auto" });+ });+it("relies on Next serving route trees and shells before any URL-specific part (the phase order of its prefetch queue)", () => {const scheduler = fs.readFileSync(path.join(__dirname, "..", "node_modules/next/dist/client/components/segment-cache/scheduler.js"), "utf8");const compare = scheduler.slice(scheduler.indexOf("function compareQueuePriority"), scheduler.indexOf("function heapPush"));