From ea8e4df7984aa6d9be0b2fbad7d368e0eaca6f52 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Tue, 8 Sep 2026 16:30:42 -0400 Subject: [PATCH] test(studio): drive the thumbnail priority re-render through a prop The priority case still re-rendered by reassigning a `let` the probe closed over. Under the React Compiler that value is not reactive, so the memoized request object is reused across both renders and the new priority never reaches the lease. The old assertion only counted `load` calls, which is true either way, so the test passed while observing nothing. Priority is a prop now, and the test asserts the lease actually received the update by wrapping the scheduler's acquire. An exhaustive AST scan of all 420 test files under src finds no other instance of the pattern. --- .../src/hooks/useThumbnailLease.test.tsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/studio/src/hooks/useThumbnailLease.test.tsx b/packages/studio/src/hooks/useThumbnailLease.test.tsx index b4f1c0d004..44725ded4c 100644 --- a/packages/studio/src/hooks/useThumbnailLease.test.tsx +++ b/packages/studio/src/hooks/useThumbnailLease.test.tsx @@ -74,8 +74,21 @@ describe("useThumbnailLease", () => { resolve = accept; }); const load = vi.fn(() => pending); - let priority: ThumbnailRequest["priority"] = "overscan"; - function Probe() { + // The lease is the only place the new priority becomes observable: the scheduler + // keeps it per lease and exposes no getter. + const priorityUpdates: ThumbnailRequest["priority"][] = []; + const acquire = scheduler.acquire.bind(scheduler); + scheduler.acquire = (request, listener) => { + const lease = acquire(request, listener); + return { + release: () => lease.release(), + updatePriority: (next) => { + priorityUpdates.push(next); + lease.updatePriority(next); + }, + }; + }; + function Probe({ priority }: { priority: ThumbnailRequest["priority"] }) { useThumbnailLease( { key: "same-content", @@ -90,10 +103,10 @@ describe("useThumbnailLease", () => { return null; } const root = createRoot(document.createElement("div")); - act(() => root.render(React.createElement(Probe))); - priority = "interaction"; - act(() => root.render(React.createElement(Probe))); + act(() => root.render(React.createElement(Probe, { priority: "overscan" }))); + act(() => root.render(React.createElement(Probe, { priority: "interaction" }))); expect(load).toHaveBeenCalledTimes(1); + expect(priorityUpdates).toEqual(["interaction"]); await act(async () => { resolve({ value: { kind: "image", url: "blob:done", aspect: 1 }, weight: 1 });