|
| 1 | +/** |
| 2 | + * @jsxImportSource @solidjs/web |
| 3 | + * @vitest-environment jsdom |
| 4 | + * |
| 5 | + * The adopted (document) face of frames-rulings 3.3 / A7: a frame the page |
| 6 | + * carried is one async value outward too. Its first landing is the |
| 7 | + * document's and never errors, but an error AFTER it — the escaped server |
| 8 | + * error the document face delivers as an `sc:live` error op (A6's C12 (c3) |
| 9 | + * arm), or any `:error` written at the address — is the L2 "errored flight |
| 10 | + * after a landing" case: the mount's address-source reader (the effect |
| 11 | + * `adoptBoundary` keeps for the switch's pending) throws it to the nearest |
| 12 | + * client `<Errored>`, and the boundary's `reset` re-asks the call the |
| 13 | + * document answered (recorded at the intercept), over the wire. |
| 14 | + * |
| 15 | + * A mount placed WITHOUT a binding (`_$SC.r(fid)` used directly as a |
| 16 | + * component) has no such reader: its frame keeps the record only — the |
| 17 | + * direct-placeholder gap, recorded under 3.3. |
| 18 | + */ |
| 19 | +import { afterEach, describe, expect, test, vi } from "vitest"; |
| 20 | +import { createRoot, Errored, Loading, resetErrorHalt } from "solid-js"; |
| 21 | +import { dynamic, hydrate } from "@solidjs/web"; |
| 22 | +import { createServerReference } from "../../server-functions/src/client.js"; |
| 23 | +import { frameAddress } from "../../server-functions/src/shared.js"; |
| 24 | +import { |
| 25 | + bootPage, |
| 26 | + frameHtml, |
| 27 | + freshFid, |
| 28 | + heldStream, |
| 29 | + quiesce, |
| 30 | + type Page |
| 31 | +} from "../consistency/support.js"; |
| 32 | + |
| 33 | +let page: Page | undefined; |
| 34 | +const disposers: (() => void)[] = []; |
| 35 | +afterEach(async () => { |
| 36 | + for (const d of disposers.splice(0)) d(); |
| 37 | + await page?.cleanup(); |
| 38 | + page = undefined; |
| 39 | + resetErrorHalt(); |
| 40 | +}); |
| 41 | + |
| 42 | +describe("adopted frame: an error after the document's landing throws outward; reset re-asks", () => { |
| 43 | + test("a `dynamic` mount over the document's element: the sc:live error op errors the mount, the <Errored> shows it, reset() fetches and the new content lands in place", async () => { |
| 44 | + const fid = freshFid("adopt-err"); |
| 45 | + page = bootPage(frameHtml(fid, "<h1>doc</h1>")); |
| 46 | + const address = frameAddress(fid, [1]); |
| 47 | + // The re-ask goes to the wire: one held frame response for it. |
| 48 | + const wire = heldStream(fid); |
| 49 | + const calls: string[] = []; |
| 50 | + vi.stubGlobal("fetch", async (input: any, init: any) => { |
| 51 | + calls.push(`${init?.method} ${JSON.parse(String(init?.body))[0]}`); |
| 52 | + return wire.response; |
| 53 | + }); |
| 54 | + const getX = createServerReference(fid); |
| 55 | + // The call is answered by the page (the intercept); the record of it |
| 56 | + // is what a later reset re-asks. |
| 57 | + const Site = dynamic(() => getX(1) as any); |
| 58 | + let resetFn: (() => void) | undefined; |
| 59 | + disposers.push( |
| 60 | + hydrate( |
| 61 | + () => ( |
| 62 | + <Errored |
| 63 | + fallback={(err, reset) => { |
| 64 | + resetFn = reset; |
| 65 | + return <em class="err">{String(err())}</em>; |
| 66 | + }} |
| 67 | + > |
| 68 | + <Loading fallback={<span>fallback</span>}> |
| 69 | + <Site /> |
| 70 | + </Loading> |
| 71 | + </Errored> |
| 72 | + ), |
| 73 | + page.container |
| 74 | + ) |
| 75 | + ); |
| 76 | + await quiesce(); |
| 77 | + const el = page.container.querySelector("solid-frame")!; |
| 78 | + expect(el).not.toBeNull(); |
| 79 | + expect(page.container.querySelector("h1")!.textContent).toBe("doc"); |
| 80 | + expect(calls).toEqual([]); |
| 81 | + |
| 82 | + // The escaped server error, as the document face delivers it: the |
| 83 | + // frame's `:error`, after its landing. |
| 84 | + page.live.push({ type: "error", fid, error: "boom" }); |
| 85 | + await quiesce(); |
| 86 | + await quiesce(); |
| 87 | + expect((page.host.get(address) as any).error).toBe("boom"); |
| 88 | + expect(page.container.querySelector("em.err")!.textContent).toBe("boom"); |
| 89 | + expect(page.container.querySelector("h1")).toBeNull(); |
| 90 | + expect(calls).toEqual([]); |
| 91 | + |
| 92 | + // `reset` re-asks the call the document answered: the same function, |
| 93 | + // the same args, over the wire; the response lands in the SAME element |
| 94 | + // (the mount stood behind the fallback) and the boundary shows it. |
| 95 | + resetFn!(); |
| 96 | + await quiesce(); |
| 97 | + expect(calls).toEqual(["POST 1"]); |
| 98 | + wire.send({ type: "start", id: fid, version: 1 }); |
| 99 | + wire.send({ type: "html", id: fid, version: 1, html: "<h1>re-asked</h1>" }); |
| 100 | + wire.send({ type: "complete", id: fid, version: 1 }); |
| 101 | + wire.close(); |
| 102 | + await quiesce(); |
| 103 | + await quiesce(); |
| 104 | + expect(page.container.querySelector("em.err")).toBeNull(); |
| 105 | + expect(page.container.querySelector("solid-frame")).toBe(el); |
| 106 | + expect(page.container.querySelector("h1")!.textContent).toBe("re-asked"); |
| 107 | + expect((page.host.get(address) as any).error).toBeUndefined(); |
| 108 | + }); |
| 109 | + |
| 110 | + test("the direct-placeholder gap: a mount placed without a binding keeps the record only (no reader to throw it)", async () => { |
| 111 | + const fid = freshFid("adopt-err-bare"); |
| 112 | + page = bootPage(frameHtml(fid, "<h1>doc</h1>")); |
| 113 | + const Comp = (globalThis as any)._$SC.r(fid); |
| 114 | + disposers.push( |
| 115 | + hydrate( |
| 116 | + () => ( |
| 117 | + <Errored fallback={<em class="err">caught</em>}> |
| 118 | + <Comp /> |
| 119 | + </Errored> |
| 120 | + ), |
| 121 | + page.container |
| 122 | + ) |
| 123 | + ); |
| 124 | + await quiesce(); |
| 125 | + page.live.push({ type: "error", fid, error: "boom" }); |
| 126 | + await quiesce(); |
| 127 | + await quiesce(); |
| 128 | + expect((page.host.get(fid) as any).error).toBe("boom"); |
| 129 | + expect(page.container.querySelector("em.err")).toBeNull(); |
| 130 | + expect(page.container.querySelector("h1")!.textContent).toBe("doc"); |
| 131 | + }); |
| 132 | +}); |
0 commit comments