|
| 1 | +/** |
| 2 | + * A verdict reader mounts a fresh Loading under an action hold (semantic |
| 3 | + * fuzzer, mount-under-hold seed 3289 cases 119 and 323). |
| 4 | + * |
| 5 | + * `<Show when={latest(x) > 0}>` (gated through a memo) opens while an action |
| 6 | + * holds `x`, and mounts a `<Loading>` whose content reads `x` directly with |
| 7 | + * no load of its own. The boundary's output is born into the held frame, so |
| 8 | + * it has no committed value; the render effect inserting it is verdict-lane |
| 9 | + * work that read its staging. Since #3869 the seam re-queued that effect to |
| 10 | + * re-derive on the committed world every round the frame stayed parked, and |
| 11 | + * each re-run read the same staging: "Potential Infinite Loop Detected". |
| 12 | + */ |
| 13 | +import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; |
| 14 | +import { |
| 15 | + action, |
| 16 | + createLoadingBoundary, |
| 17 | + createMemo, |
| 18 | + createRenderEffect, |
| 19 | + createRoot, |
| 20 | + createSignal, |
| 21 | + flush, |
| 22 | + latest, |
| 23 | + untrack |
| 24 | +} from "../src/index.js"; |
| 25 | + |
| 26 | +beforeEach(() => vi.useFakeTimers()); |
| 27 | +afterEach(() => vi.useRealTimers()); |
| 28 | + |
| 29 | +const resolve = (v: unknown): unknown => { |
| 30 | + while (typeof v === "function") v = (v as () => unknown)(); |
| 31 | + return v; |
| 32 | +}; |
| 33 | + |
| 34 | +function mount(anchor: boolean) { |
| 35 | + const [x, setX] = createSignal(0); |
| 36 | + const screen = { x: undefined as number | undefined, slot: undefined as unknown }; |
| 37 | + createRoot(() => { |
| 38 | + if (anchor) |
| 39 | + createRenderEffect(x, v => { |
| 40 | + screen.x = v; |
| 41 | + }); |
| 42 | + const condition = createMemo(() => latest(x) > 0); |
| 43 | + const children = createMemo(() => |
| 44 | + condition() |
| 45 | + ? untrack(() => |
| 46 | + createLoadingBoundary( |
| 47 | + () => untrack(() => () => `content ${x()}`), |
| 48 | + () => "fallback" |
| 49 | + ) |
| 50 | + ) |
| 51 | + : undefined |
| 52 | + ); |
| 53 | + createRenderEffect( |
| 54 | + () => resolve(children()), |
| 55 | + v => { |
| 56 | + screen.slot = v; |
| 57 | + } |
| 58 | + ); |
| 59 | + }); |
| 60 | + flush(); |
| 61 | + const committed = () => (anchor ? screen.x : untrack(x)); |
| 62 | + let release!: () => void; |
| 63 | + const hold = () => |
| 64 | + action(function* () { |
| 65 | + setX(1); |
| 66 | + yield new Promise<void>(r => (release = r)); |
| 67 | + })(); |
| 68 | + return { screen, committed, hold, release: () => release() }; |
| 69 | +} |
| 70 | + |
| 71 | +describe("a verdict reader mounts a fresh Loading under an action hold", () => { |
| 72 | + for (const anchor of [false, true]) |
| 73 | + describe(anchor ? "with a reader of x on screen (case 323)" : "case 119", () => { |
| 74 | + test("flush settles while held, and the commit reveals the content", async () => { |
| 75 | + const m = mount(anchor); |
| 76 | + expect(m.screen.slot).toBeUndefined(); |
| 77 | + expect(m.committed()).toBe(0); |
| 78 | + |
| 79 | + const done = m.hold(); |
| 80 | + expect(() => flush()).not.toThrow(); |
| 81 | + await Promise.resolve(); |
| 82 | + expect(() => flush()).not.toThrow(); |
| 83 | + expect(m.committed()).toBe(0); |
| 84 | + |
| 85 | + m.release(); |
| 86 | + await done; |
| 87 | + flush(); |
| 88 | + expect(m.committed()).toBe(1); |
| 89 | + expect(m.screen.slot).toBe("content 1"); |
| 90 | + }); |
| 91 | + |
| 92 | + // A29: a fresh, never-shown Loading over held data shows its fallback |
| 93 | + // now. Pre-#3869 behavior, still open (MH1): the content shows the held |
| 94 | + // value beside the committed `x = 0`. |
| 95 | + test.fails("while held, the fresh boundary shows its fallback (A29)", async () => { |
| 96 | + const m = mount(anchor); |
| 97 | + m.hold(); |
| 98 | + flush(); |
| 99 | + await Promise.resolve(); |
| 100 | + flush(); |
| 101 | + expect(m.committed()).toBe(0); |
| 102 | + expect(m.screen.slot).toBe("fallback"); |
| 103 | + }); |
| 104 | + }); |
| 105 | +}); |
0 commit comments