@rsc-kit/core 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apiPrerender.js +25 -12
- package/dist/apiPrerender.js.map +1 -1
- package/dist/buildProcess.d.ts +12 -0
- package/dist/buildProcess.js +202 -0
- package/dist/buildProcess.js.map +1 -0
- package/dist/buildScope.d.ts +61 -0
- package/dist/buildScope.js +172 -0
- package/dist/buildScope.js.map +1 -0
- package/dist/conformance.d.ts +3 -0
- package/dist/conformance.js +23 -3
- package/dist/conformance.js.map +1 -1
- package/dist/conformanceBuild.d.ts +5 -0
- package/dist/conformanceBuild.js +154 -0
- package/dist/conformanceBuild.js.map +1 -0
- package/dist/csp.d.ts +11 -2
- package/dist/csp.js +55 -6
- package/dist/csp.js.map +1 -1
- package/dist/formArgs.d.ts +10 -0
- package/dist/formArgs.js +41 -0
- package/dist/formArgs.js.map +1 -0
- package/dist/hostCalls.d.ts +17 -0
- package/dist/hostCalls.js +103 -103
- package/dist/hostCalls.js.map +1 -1
- package/dist/hostSources.d.ts +23 -0
- package/dist/hostSources.js +65 -0
- package/dist/hostSources.js.map +1 -0
- package/dist/prerender.d.ts +18 -5
- package/dist/prerender.js +95 -16
- package/dist/prerender.js.map +1 -1
- package/dist/typegen.js +11 -2
- package/dist/typegen.js.map +1 -1
- package/dist/vite.d.ts +17 -2
- package/dist/vite.js +245 -105
- package/dist/vite.js.map +1 -1
- package/package.json +5 -1
package/dist/hostCalls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostCalls.js","sourceRoot":"","sources":["../src/hostCalls.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,4EAA4E;AAC5E,+DAA+D;AAE/D,OA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CAAC,SAAS,CAAC,IAAI,CAAC,sCAAsC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAC5F,CAAA;QACH,CAAC;QAED,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjC,OAAO,KAAK,CAAC,MAAM,IAAI,IAAI,CAAA;IAC7B,CAAC;IAED,SAAS,eAAe,CAAC,OAA6B;QACpD,IAAI,CAAC,OAAO,EAAE,MAAM;YAAE,OAAM;QAC5B,IAAI,YAAY;YAAE,YAAY,CAAC,OAAO,CAAC,CAAA;QACvC,uEAAuE;QACvE,sEAAsE;;YACjE,KAAK,MAAM,MAAM,IAAI,OAAO;gBAAE,UAAU,CAAC,MAA0B,CAAC,CAAA;IAC3E,CAAC;IAED,OAAO,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,GAAG,IAAe;QAC7D,MAAM,OAAO,GAAG,MAAM,gBAAgB,EAAE,CAAA;QACxC,wEAAwE;QACxE,qEAAqE;QACrE,wEAAwE;QACxE,6BAA6B;QAC7B,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;QAClC,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;QAE3G,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC,CAAA;AACH,CAAC","sourcesContent":["// Host calls over HTTP, so a host in any language can answer them.\n//\n// A server component writing `await rpc('Orders.recent')` needs the host\n// mid-render. The Laravel path answers on a second unix socket with its own\n// framing (PROTOCOL.md, \"The callback channel\"), which every non-JS host has\n// to reimplement before it can render a single page that fetches anything.\n// This is the same conversation over an ordinary POST.\n//\n// The transport is the only thing that changes. The engine still sees one\n// function, the deferred-release ordering in streaming.ts still applies, and a\n// reply may still carry `revalidate` — a Go host that answers this endpoint\n// gets the same semantics the socket has, without the framing.\n\nimport { checkedCall, headers as incomingHeaders, passSetCookies, renderingAsNobody, requestClientIp } from './request.js'\nimport { revalidate } from './revalidate.js'\nimport type { RevalidateTarget } from './routes.js'\nimport { ActionRefusal, ActionValidationError } from './action.js'\nimport { redirect } from './redirect.js'\nimport { ServerAuthenticationError, ServerAuthorizationError } from './js/errors.js'\nimport { NotFoundSignal } from './notFound.js'\n\nexport interface HttpHostCallsOptions {\n /**\n * Where calls are POSTed. A loopback address or a unix socket url — see the\n * note on `secret` for why this must not be a public one.\n */\n endpoint: string\n /**\n * Sent as `X-RSC-Host-Secret`, and required rather than optional.\n *\n * This endpoint runs functions by name on behalf of a render. PROTOCOL.md\n * Part 3b draws the line at client-supplied input deciding what RUNS, and an\n * unauthenticated callback endpoint is on the wrong side of it: anyone who\n * can reach it can invoke any registered host function directly, with\n * whatever arguments they like and none of the app's routing in front. A\n * default of \"off\" would be the kind that ships.\n */\n secret: string\n /**\n * Request headers copied from the render's own request onto the call.\n *\n * This is what makes a host call run as the person browsing: the backend's\n * session middleware reads its cookie and finds the same user. Nothing else\n * is forwarded, because everything else is either meaningless to the backend\n * or actively wrong — `content-length` and `content-type` describe this POST,\n * not the page request.\n */\n forwardHeaders?: string[]\n /**\n * Fixed headers sent on every call, whatever the render: the same value for\n * every visitor. For a platform in front of the backend that wants one -\n * a preview's access token, say - read from RSC_BACKEND_HEADERS by\n * `backendHeaders()`. Never sent anywhere but `endpoint`.\n */\n headers?: Record<string, string>\n /** Defaults to 30s. A render blocked on a host that never answers is a hung request. */\n timeoutMs?: number\n /** Injectable for tests and for a runtime whose fetch is not global. */\n fetch?: typeof fetch\n /**\n * How long a refused connection is tried again, in ms. Defaults to 2s.\n *\n * A backend started beside the renderer - two processes in one container -\n * is often still coming up when the first page renders, and its port\n * refuses. A refused connection never delivered the request, so trying it\n * again cannot run anything twice, an action included. Nothing else is\n * retried: a timeout or an error after connecting may have run the call.\n * 0 turns it off.\n */\n refusedRetryMs?: number\n /**\n * What to do with whatever a reply reported as invalidated.\n *\n * Defaults to marking it on the engine, which is the only thing that makes\n * `Revalidate(ctx, \"orders\")` on the host side mean anything: an action's\n * answer carries the re-rendered region only if the target reached the\n * revalidation scope before the action returned. Without it a host reports\n * what it dirtied, nothing listens, and the browser is told nothing — the\n * page simply shows stale data with no error anywhere.\n */\n onRevalidate?: (targets: string[]) => void\n}\n\nconst DEFAULT_FORWARDED = ['cookie', 'authorization']\n\n/** The visitor's address, on every host call made for a request. */\nexport const CLIENT_IP_HEADER = 'x-rsc-client-ip'\n\n/**\n * The visitor's browser, on every host call made for a request. The call's own\n * User-Agent is the renderer's runtime, the same for everyone.\n */\nexport const CLIENT_USER_AGENT_HEADER = 'x-rsc-client-user-agent'\n\nexport interface HostCallReply {\n result?: unknown\n error?: string\n revalidate?: string[]\n /**\n * Field name to messages, when the host refused the input.\n *\n * The same shape everything else here already uses: Laravel's own\n * `$e->errors()`, the socket protocol's `validation_errors`, and what\n * `issuesToErrors` turns a Standard Schema result into. Dot-joined for a\n * nested field, the empty string for a message about the form rather than\n * any one field.\n */\n validationErrors?: Record<string, string[]>\n /** The caller has no session. Becomes the engine's own authentication error. */\n unauthenticated?: boolean\n /** The caller has a session and still may not. */\n unauthorized?: boolean\n /**\n * Where the host says this request should go instead.\n *\n * Answered with a 200 and this field, never as a 3xx: fetch follows a\n * redirect transparently, so a real one would send the host call itself to\n * the destination and hand whatever came back to the render as the\n * function's result.\n */\n redirect?: string\n /**\n * Where an unexpected failure happened in the backend, sent only in\n * development (Laravel's app.debug, Go's CallbackHandler.Debug): the\n * thrown type, its message, and frames newest first.\n */\n debug?: { type?: string; message?: string; trace?: string[] }\n /** The status to redirect with. Defaults to 307, which preserves the method. */\n redirectStatus?: number\n /**\n * The status a refusal should be answered with.\n *\n * A middleware that aborted meant what it aborted with — throttle answers\n * 429, a signed-url check 403 — and collapsing those to 500 makes a\n * rate-limited visitor indistinguishable from a broken server.\n */\n refusalStatus?: number\n /**\n * What a deliberate refusal carries beside its message (`error`): the\n * records blocking a delete, say. Raised as the action client's own\n * refusal, so an action passes it to the page as `result.refusal`, checked\n * against the schema the action declared - see `refuse()`.\n */\n refusalData?: unknown\n}\n\n/**\n * A batch on the wire: several calls in one POST, answered in order.\n *\n * Calls issued in the same tick of a render - sibling components each\n * awaiting rpc() - travel together, so a page's parallel reads cost the host\n * one request rather than one each. A host that has never heard of the\n * envelope answers it as a malformed single call, and the calls are sent one\n * at a time from then on; nothing is lost but the saving.\n */\nexport interface HostCallBatch {\n calls: { function: string; args: unknown[] }[]\n}\n\nexport interface HostCallBatchReply {\n /** One per call, in order. Each carries the status that call would have had. */\n replies: (HostCallReply & { status?: number })[]\n}\n\n/**\n * A batch answered as it goes: one line per call, each as the host finishes\n * it, in whatever order that is.\n *\n * `application/x-ndjson`, each line a reply with the call's `index` in the\n * batch. A host that answers this way lets a fast call resolve while a slow\n * sibling is still running - which is what keeps a page's boundaries\n * streaming independently when their reads travelled together. A host that\n * answers the whole batch at once, as one JSON object of `replies`, is read\n * as before; the saving of the batch stays, the independence does not.\n */\nexport type HostCallBatchLine = HostCallReply & { index: number; status?: number }\n\n/** How many calls one POST carries at most. */\nconst BATCH_LIMIT = 50\n\ntype Settled = { status: number; reply: HostCallReply | null; text: string; setCookies?: string[] }\n\ninterface Pending {\n name: string\n args: unknown[]\n resolve: (settled: Settled) => void\n reject: (error: unknown) => void\n}\n\ninterface Bucket {\n headers: Record<string, string>\n calls: Pending[]\n}\n\n// After the current I/O, before the next timer: what a render issued\n// synchronously - and across the microtasks between one component's awaits -\n// is in the bucket by then. setImmediate where the runtime has it, a zero\n// timer where it does not (a Worker).\nconst nextTick: (fn: () => void) => void =\n typeof setImmediate === 'function' ? (fn) => setImmediate(fn) : (fn) => setTimeout(fn, 0)\n\n/**\n * The function to hand to `installHostFn`, or to `hostCalls` on the JS host.\n */\n/**\n * The backend's trace, on the error the render sees.\n *\n * As its cause - an Error named for the backend's type, whose stack is the\n * backend's frames - so Node, Bun and the dev overlay print it under the\n * renderer's own stack; and appended to that stack, for whatever prints only\n * the one. Before this a failed rpc() pointed at a line of JavaScript, and the\n * PHP or Go that failed was a separate search through another log.\n */\nfunction withBackendTrace(failure: Error, debug: NonNullable<HostCallReply['debug']>): void {\n const frames = (debug.trace ?? []).map((frame) => ' at ' + frame).join('\\n')\n const cause = new Error(debug.message ?? '')\n\n cause.name = 'Backend ' + (debug.type ?? 'Error')\n cause.stack = cause.name + ': ' + (debug.message ?? '') + (frames ? '\\n' + frames : '')\n\n failure.cause = cause\n failure.stack = (failure.stack ?? String(failure)) + '\\nCaused in the backend by ' + cause.stack\n}\n\n/**\n * Names a fixed header may not take: the protocol's own, and the visitor's,\n * which are forwarded per render and must not be one value for everyone.\n */\nconst RESERVED_HEADERS = new Set(['host', 'content-type', 'content-length', 'cookie', 'authorization', 'forwarded', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto'])\n\n/**\n * The fixed headers sent on every request to the backend - host calls, and\n * the urls forwarded to it - from RSC_BACKEND_HEADERS, a JSON object:\n *\n * RSC_BACKEND_HEADERS={\"X-Preview-Token\":\"...\"}\n *\n * Read once, when the server starts. Malformed is an error naming the\n * variable, never its value: what is in it is usually a credential. Names\n * come back lowercased; none when the variable is unset or empty.\n */\nexport function backendHeaders(value: string | Record<string, string> | undefined): Record<string, string> {\n if (value === undefined || value === '') return {}\n\n const refuse = (why: string): never => {\n throw new Error(`RSC_BACKEND_HEADERS must be a JSON object of header names to strings, e.g. {\"X-Preview-Token\":\"...\"}: ${why}`)\n }\n\n let parsed: unknown = value\n\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value)\n } catch {\n refuse('it is not JSON')\n }\n }\n\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) refuse('it is not an object')\n\n const headers: Record<string, string> = {}\n\n for (const [name, header] of Object.entries(parsed as Record<string, unknown>)) {\n const lower = name.toLowerCase()\n\n if (!/^[!#$%&'*+.^_`|~0-9a-z-]+$/.test(lower)) refuse(`${JSON.stringify(name)} is not a header name`)\n if (typeof header !== 'string') refuse(`${name} is not a string`)\n if (/[\\r\\n\\0]/.test(header as string)) refuse(`${name} holds a line break`)\n if (RESERVED_HEADERS.has(lower) || lower.startsWith('x-rsc-')) refuse(`${name} is set by rsc-kit itself`)\n\n headers[lower] = header as string\n }\n\n return headers\n}\n\nexport function httpHostCalls(\n options: HttpHostCallsOptions,\n): (name: string, ...args: unknown[]) => Promise<unknown> {\n const {\n endpoint,\n secret,\n forwardHeaders = DEFAULT_FORWARDED,\n timeoutMs = 30_000,\n fetch: fetchImpl,\n refusedRetryMs = 2_000,\n onRevalidate,\n } = options\n\n const fixed = backendHeaders(options.headers ?? {})\n\n if (!secret) {\n throw new Error('httpHostCalls requires a secret — see the note on the option.')\n }\n\n const forwarded = forwardHeaders.map((name) => name.toLowerCase())\n\n // One bucket per set of forwarded headers: two visitors' renders in flight\n // at once must not share a request, because the host reads the cookie off\n // the request to know whose session a call runs under.\n const buckets = new Map<string, Bucket>()\n\n async function forwardedHeaders(): Promise<Record<string, string>> {\n const headers: Record<string, string> = {\n ...fixed,\n 'content-type': 'application/json',\n 'x-rsc-host-secret': secret,\n }\n\n // A page a shared cache may keep renders as nobody: no cookie, no\n // authorization, so what the backend answers is the same for everyone.\n // Asked before reading the request, so the read is not counted as one.\n if (renderingAsNobody()) return headers\n\n // Who the visitor is, as the server saw them. The backend reads it in\n // place of the address this call came from - which is this renderer's,\n // and the same for everyone - once the secret has said the caller may be\n // believed. Laravel's `$request->ip()`, and every throttle keyed on it.\n const ip = requestClientIp()\n\n if (ip !== null) headers[CLIENT_IP_HEADER] = ip\n\n // Outside a render — a prerender pass, or a host calling one directly —\n // there is no request to forward from, and that is not an error. The call\n // simply carries no session, which is exactly what a build-time render\n // should be doing.\n //\n // Only that one condition is swallowed. A blanket catch here is the wrong\n // shape: anything else going wrong while reading the request would come\n // out as a call with no session, which is not a failure the caller sees —\n // it is the visitor silently becoming anonymous, and the page rendering as\n // though they were logged out.\n try {\n const from = await incomingHeaders()\n\n for (const key of forwarded) {\n const value = from.get(key)\n if (value !== null) headers[key] = value\n }\n\n // Who the visitor's browser says it is, for whatever the backend keeps\n // about a request: a log, a session list, an audit trail. Sent beside\n // the call's own, which stays this runtime's.\n const agent = from.get('user-agent')\n\n if (agent) headers[CLIENT_USER_AGENT_HEADER] = agent\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n\n if (!message.startsWith('No request in scope')) throw error\n }\n\n return headers\n }\n\n /** One POST. `label` names what is being sent, for the error messages. */\n async function post(\n body: unknown,\n headers: Record<string, string>,\n label: string,\n ): Promise<{ status: number; text: string; setCookies: string[] }> {\n const response = await send(body, headers, label)\n\n // Read the body before branching on status: a host that reports the error\n // in JSON with a 500 is saying something more useful than \"500\", and\n // throwing on the status alone discards it.\n return {\n status: response.status,\n text: await response.text(),\n // A login's session cookie: kept to put on the page's response.\n setCookies: response.headers.getSetCookie?.() ?? [],\n }\n }\n\n /** The POST itself, headers in hand, body still to read. */\n async function send(body: unknown, headers: Record<string, string>, label: string): Promise<Response> {\n const doFetch = fetchImpl ?? globalThis.fetch\n\n // AbortSignal.timeout is not on every runtime this engine targets, so the\n // controller is written out rather than assumed.\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeoutMs)\n\n let response: Response\n // From the first refusal, not from the send: the window is how long the\n // backend may take to start listening.\n let refusedAt: number | undefined\n\n try {\n for (let wait = 50; ; wait = Math.min(wait * 2, 400)) {\n try {\n response = await doFetch(endpoint, {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: controller.signal,\n })\n\n break\n } catch (error) {\n // Refused: the backend is not listening yet, and nothing was sent.\n if (!refused(error) || controller.signal.aborted) throw error\n\n refusedAt ??= Date.now()\n\n if (Date.now() - refusedAt + wait > refusedRetryMs) throw error\n\n await new Promise((resolve) => setTimeout(resolve, wait))\n }\n }\n } catch (error) {\n if (controller.signal.aborted) {\n throw new Error(`Host call ${label} timed out after ${timeoutMs}ms`)\n }\n\n throw new Error(\n `Host call ${label} could not reach the host at ${endpoint}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n } finally {\n clearTimeout(timer)\n }\n\n return response\n }\n\n /** A connection the backend refused: Bun says so on the error, Node on its cause. */\n function refused(error: unknown): boolean {\n const code = (e: unknown) => (e as { code?: unknown } | null)?.code\n\n return code(error) === 'ECONNREFUSED' || code((error as { cause?: unknown } | null)?.cause) === 'ECONNREFUSED'\n }\n\n function parse(text: string): HostCallReply | null {\n try {\n return text ? (JSON.parse(text) as HostCallReply) : null\n } catch {\n return null\n }\n }\n\n async function single(\n name: string,\n args: unknown[],\n headers: Record<string, string>,\n validate?: string[],\n ): Promise<Settled> {\n const body = validate ? { function: name, args, validate } : { function: name, args }\n const { status, text, setCookies } = await post(body, headers, JSON.stringify(name))\n\n return { status, reply: parse(text), text, setCookies }\n }\n\n /** Read a streamed batch, one reply per line, resolving each call as its line lands. */\n async function resolveAsLinesArrive(body: ReadableStream<Uint8Array>, calls: Pending[]): Promise<void> {\n const answered = new Set<number>()\n const reader = body.getReader()\n const decoder = new TextDecoder()\n let buffered = ''\n\n const take = (line: string) => {\n const trimmed = line.trim()\n\n if (!trimmed) return\n\n let parsed: Partial<HostCallBatchLine> | null\n\n try {\n parsed = JSON.parse(trimmed) as Partial<HostCallBatchLine>\n } catch {\n return\n }\n\n const index = parsed?.index\n\n if (typeof index !== 'number' || !calls[index] || answered.has(index)) return\n\n const { index: _, status: own, ...reply } = parsed as HostCallBatchLine\n\n answered.add(index)\n calls[index]!.resolve({ status: own ?? 200, reply, text: JSON.stringify(reply) })\n }\n\n try {\n for (;;) {\n const { done, value } = await reader.read()\n\n if (done) break\n\n buffered += decoder.decode(value, { stream: true })\n\n let at: number\n\n while ((at = buffered.indexOf('\\n')) !== -1) {\n take(buffered.slice(0, at))\n buffered = buffered.slice(at + 1)\n }\n }\n\n buffered += decoder.decode()\n take(buffered)\n } catch (error) {\n for (const [i, call] of calls.entries()) {\n if (!answered.has(i)) call.reject(error)\n }\n\n return\n }\n\n // The host closed the batch with a call unanswered: a fault on its side,\n // reported to the call rather than left pending forever.\n for (const [i, call] of calls.entries()) {\n if (!answered.has(i)) {\n call.reject(new Error(`Host call ${JSON.stringify(call.name)} was not answered in its batch`))\n }\n }\n }\n\n /**\n * Send a bucket. One call goes as itself, so a host that speaks only the\n * single shape - or a request that happened to be alone - sees nothing\n * new on the wire.\n */\n async function flush(bucket: Bucket): Promise<void> {\n const { headers, calls } = bucket\n\n if (calls.length === 1) {\n const [only] = calls\n\n try {\n only.resolve(await single(only.name, only.args, headers))\n } catch (error) {\n only.reject(error)\n }\n\n return\n }\n\n const label = `batch of ${calls.length} (${calls.map((c) => c.name).join(', ')})`\n let response: Response\n\n try {\n response = await send(\n { calls: calls.map((c) => ({ function: c.name, args: c.args })) } satisfies HostCallBatch,\n headers,\n label,\n )\n } catch (error) {\n // The host could not be reached, or did not answer in time. Not\n // re-sent one by one: the calls may have run, and an action run twice\n // is worse than one reported as failed.\n for (const call of calls) call.reject(error)\n\n return\n }\n\n // Answered as it goes: each call resolves the moment its line arrives,\n // so a component waiting on a fast read paints while a slow sibling's\n // is still running. The batch saved the round trips; this keeps the\n // streaming the batch would otherwise have cost.\n if (response.status < 400 && (response.headers.get('content-type') ?? '').includes('x-ndjson') && response.body) {\n await resolveAsLinesArrive(response.body, calls)\n\n return\n }\n\n const status = response.status\n const text = await response.text()\n const parsed = parse(text) as Partial<HostCallBatchReply> | null\n const replies = parsed?.replies\n\n if (status < 400 && Array.isArray(replies) && replies.length === calls.length) {\n calls.forEach((call, i) => {\n const { status: own, ...reply } = replies[i]!\n\n call.resolve({ status: own ?? 200, reply, text: JSON.stringify(reply) })\n })\n\n return\n }\n\n // Not a batch answer. Taking batches is part of the protocol - the\n // conformance suite checks it - so this is a backend that does not, or\n // one that failed before reading the calls: wrong secret, down, too many.\n // Every call fails with what the backend said, and none is sent again:\n // they may have run, and an action run twice is worse than one reported.\n const said = parsed && typeof (parsed as HostCallReply).error === 'string' ? (parsed as HostCallReply).error : text.slice(0, 200)\n const failure = new Error(\n `Host call ${label} was not answered as a batch (${status}${said ? `: ${said}` : ''}). ` +\n 'A backend answers { \"calls\": [...] } line by line or as { \"replies\": [...] }: ' +\n 'https://docs.rsc-kit.dev/hosts/your-own-backend/calls#batches',\n )\n\n for (const call of calls) call.reject(failure)\n }\n\n function enqueue(name: string, args: unknown[], headers: Record<string, string>): Promise<Settled> {\n return new Promise<Settled>((resolve, reject) => {\n const key = JSON.stringify(headers)\n let bucket = buckets.get(key)\n\n if (!bucket) {\n bucket = { headers, calls: [] }\n buckets.set(key, bucket)\n\n const mine = bucket\n\n nextTick(() => {\n if (buckets.get(key) === mine) buckets.delete(key)\n\n void flush(mine)\n })\n }\n\n bucket.calls.push({ name, args, resolve, reject })\n\n if (bucket.calls.length >= BATCH_LIMIT) {\n buckets.delete(key)\n\n void flush(bucket)\n }\n })\n }\n\n /**\n * What a reply means, in the caller's own async context.\n *\n * Deliberately not done where the response arrives: a batch is answered in\n * a timer, outside every caller's request scope, and `redirect()` and\n * `revalidate()` both write to that scope. Interpreting here, after the\n * caller's await resumed, puts each reply back inside the render it belongs\n * to.\n */\n function interpret(name: string, { status, reply, text, setCookies }: Settled): unknown {\n // First, whatever the outcome: a login that then redirects still logged\n // the visitor in. In the caller's context, where the page's response is.\n // Dropped as nobody: a cookie on a page kept for everyone is handed to\n // everyone - and its Set-Cookie alone would make the page private.\n if (setCookies?.length && !renderingAsNobody()) passSetCookies(setCookies)\n\n // Refusing the input is not the call failing — it is the call answering.\n //\n // Thrown rather than returned, so a handler stops where it is instead of\n // carrying on with data the host rejected. createActionClient catches this\n // on the way out and returns { validationErrors }, which is the shape\n // useForm reads: React serialises a REJECTED server action opaquely, so a\n // validation error that stays thrown reaches the browser as \"an error\n // occurred\" with every field it named gone.\n //\n // Checked before `error`, so a host that sends both is read as a refusal\n // rather than as a failure with no fields.\n //\n // One error for both places a call is made. In an action, the mark is\n // what returns the fields to the form. In a page's render there is no\n // form: refusalStatus makes the page answer 422 rather than 500, and the\n // message says which call refused which fields, where \"Validation failed\"\n // read like an action had run.\n if (reply?.validationErrors) {\n const refused = new ActionValidationError(reply.validationErrors)\n const fields = Object.keys(reply.validationErrors).map((field) => field || '(the input as a whole)')\n\n refused.message = `Host call ${JSON.stringify(name)} refused its input: ${fields.join(', ')}`\n ;(refused as ActionValidationError & { refusalStatus?: number }).refusalStatus = 422\n\n throw refused\n }\n\n // Raised as the engine's own redirect, so it travels the path every other\n // redirect travels — a real 3xx above a Suspense boundary, the digest\n // below one — rather than becoming an error the page has to interpret.\n //\n // What it revalidated is marked first: a backend that switched the team\n // and redirected - Rsc::revalidate('all') then redirect() in PHP - goes\n // to a page whose layout reads the team, and the redirect carries the\n // revalidation to the client only if it was marked before the throw.\n if (reply?.redirect) {\n markRevalidated(reply.revalidate)\n redirect(reply.redirect as never, reply.redirectStatus ?? 307)\n }\n\n if (reply?.unauthenticated) {\n throw new ServerAuthenticationError(reply.error ?? 'Unauthenticated.')\n }\n\n if (reply?.unauthorized) {\n throw new ServerAuthorizationError(reply.error ?? 'This action is unauthorized.')\n }\n\n // The backend says there is no such thing - Go's Refuse(404), Laravel's\n // abort(404), a record this caller cannot see. Raised as the engine's\n // own notFound(), so the page answers with not-found.tsx and a 404,\n // exactly as a component calling notFound() would; as an error it\n // reached the page as \"something went wrong\". The backend's message rides\n // on it for an action, which has no not-found page and shows the message.\n if (reply?.refusalStatus === 404) throw new NotFoundSignal(reply.error ?? 'Not found')\n\n // A status is what makes a reply a refusal rather than a failure: the\n // backend's refuse(), Go's Refuse, Laravel's abort(). Its message was\n // written for the person asking - Laravel shows an HttpException's in its\n // own production JSON - so it is raised as one, with or without data, and\n // onError never replaces it. Only refusals carried data at first, and\n // Refuse(503, \"busy\") reached the form as \"Something went wrong.\".\n if (reply?.error !== undefined && (reply.refusalStatus !== undefined || reply.refusalData !== undefined)) {\n throw new ActionRefusal(reply.error, reply.refusalData, reply.refusalStatus ?? 409)\n }\n\n if (reply?.error !== undefined) {\n const failure = new Error(`Host call ${JSON.stringify(name)} failed: ${reply.error}`)\n\n if (reply.debug) withBackendTrace(failure, reply.debug)\n\n throw failure\n }\n\n if (status >= 400) {\n throw new Error(\n `Host call ${JSON.stringify(name)} failed: ${status}`.trim() +\n (text ? ` — ${text.slice(0, 200)}` : ''),\n )\n }\n\n if (reply === null) {\n throw new Error(\n `Host call ${JSON.stringify(name)} returned a body that is not JSON: ${text.slice(0, 200)}`,\n )\n }\n\n markRevalidated(reply.revalidate)\n\n return reply.result ?? null\n }\n\n function markRevalidated(targets: string[] | undefined): void {\n if (!targets?.length) return\n if (onRevalidate) onRevalidate(targets)\n // Named by the host over the wire - Rsc::revalidate('orders') in PHP -\n // so nothing here can check it; the renderer refuses an unknown name.\n else for (const target of targets) revalidate(target as RevalidateTarget)\n }\n\n return async function hostCall(name: string, ...args: unknown[]): Promise<unknown> {\n const headers = await forwardedHeaders()\n // A check rather than a run: the backend validates the fields named and\n // stops - success is a null result, a refusal the 422 it always was.\n // Alone, never in a batch: the envelope has no room for it, and a check\n // is one call by definition.\n const validate = checkedCall(name)\n const settled = validate ? await single(name, args, headers, validate) : await enqueue(name, args, headers)\n\n return interpret(name, settled)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hostCalls.js","sourceRoot":"","sources":["../src/hostCalls.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,4EAA4E;AAC5E,+DAA+D;AAE/D,OAAO,EAAE,WAAW,EAAE,OAAO,IAAI,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC1H,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,C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O,CAAA;IACf,CAAC;IAED,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,MAAM,EAAE,CAAC,IAAI,EAAE;YAC1D,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC3C,CAAA;IACH,CAAC;IAED,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,sCAAsC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAC5F,CAAA;IACH,CAAC;IAED,eAAe,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;IAE/C,OAAO,KAAK,CAAC,MAAM,IAAI,IAAI,CAAA;AAC7B,CAAC;AAED,SAAS,eAAe,CAAC,OAA6B,EAAE,YAA0C;IAChG,IAAI,CAAC,OAAO,EAAE,MAAM;QAAE,OAAM;IAC5B,IAAI,YAAY;QAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IACvC,uEAAuE;IACvE,sEAAsE;;QACjE,KAAK,MAAM,MAAM,IAAI,OAAO;YAAE,UAAU,CAAC,MAA0B,CAAC,CAAA;AAC3E,CAAC","sourcesContent":["// Host calls over HTTP, so a host in any language can answer them.\n//\n// A server component writing `await rpc('Orders.recent')` needs the host\n// mid-render. The Laravel path answers on a second unix socket with its own\n// framing (PROTOCOL.md, \"The callback channel\"), which every non-JS host has\n// to reimplement before it can render a single page that fetches anything.\n// This is the same conversation over an ordinary POST.\n//\n// The transport is the only thing that changes. The engine still sees one\n// function, the deferred-release ordering in streaming.ts still applies, and a\n// reply may still carry `revalidate` — a Go host that answers this endpoint\n// gets the same semantics the socket has, without the framing.\n\nimport { checkedCall, headers as incomingHeaders, passSetCookies, renderingAsNobody, requestClientIp } from './request.js'\nimport { revalidate } from './revalidate.js'\nimport type { RevalidateTarget } from './routes.js'\nimport { ActionRefusal, ActionValidationError } from './action.js'\nimport { redirect } from './redirect.js'\nimport { ServerAuthenticationError, ServerAuthorizationError } from './js/errors.js'\nimport { NotFoundSignal } from './notFound.js'\n\nexport interface HttpHostCallsOptions {\n /**\n * Where calls are POSTed. A loopback address or a unix socket url — see the\n * note on `secret` for why this must not be a public one.\n */\n endpoint: string\n /**\n * Sent as `X-RSC-Host-Secret`, and required rather than optional.\n *\n * This endpoint runs functions by name on behalf of a render. PROTOCOL.md\n * Part 3b draws the line at client-supplied input deciding what RUNS, and an\n * unauthenticated callback endpoint is on the wrong side of it: anyone who\n * can reach it can invoke any registered host function directly, with\n * whatever arguments they like and none of the app's routing in front. A\n * default of \"off\" would be the kind that ships.\n */\n secret: string\n /**\n * Request headers copied from the render's own request onto the call.\n *\n * This is what makes a host call run as the person browsing: the backend's\n * session middleware reads its cookie and finds the same user. Nothing else\n * is forwarded, because everything else is either meaningless to the backend\n * or actively wrong — `content-length` and `content-type` describe this POST,\n * not the page request.\n */\n forwardHeaders?: string[]\n /**\n * Fixed headers sent on every call, whatever the render: the same value for\n * every visitor. For a platform in front of the backend that wants one -\n * a preview's access token, say - read from RSC_BACKEND_HEADERS by\n * `backendHeaders()`. Never sent anywhere but `endpoint`.\n */\n headers?: Record<string, string>\n /** Defaults to 30s. A render blocked on a host that never answers is a hung request. */\n timeoutMs?: number\n /** Injectable for tests and for a runtime whose fetch is not global. */\n fetch?: typeof fetch\n /**\n * How long a refused connection is tried again, in ms. Defaults to 2s.\n *\n * A backend started beside the renderer - two processes in one container -\n * is often still coming up when the first page renders, and its port\n * refuses. A refused connection never delivered the request, so trying it\n * again cannot run anything twice, an action included. Nothing else is\n * retried: a timeout or an error after connecting may have run the call.\n * 0 turns it off.\n */\n refusedRetryMs?: number\n /**\n * What to do with whatever a reply reported as invalidated.\n *\n * Defaults to marking it on the engine, which is the only thing that makes\n * `Revalidate(ctx, \"orders\")` on the host side mean anything: an action's\n * answer carries the re-rendered region only if the target reached the\n * revalidation scope before the action returned. Without it a host reports\n * what it dirtied, nothing listens, and the browser is told nothing — the\n * page simply shows stale data with no error anywhere.\n */\n onRevalidate?: (targets: string[]) => void\n}\n\nconst DEFAULT_FORWARDED = ['cookie', 'authorization']\n\n/** The visitor's address, on every host call made for a request. */\nexport const CLIENT_IP_HEADER = 'x-rsc-client-ip'\n\n/**\n * The visitor's browser, on every host call made for a request. The call's own\n * User-Agent is the renderer's runtime, the same for everyone.\n */\nexport const CLIENT_USER_AGENT_HEADER = 'x-rsc-client-user-agent'\n\nexport interface HostCallReply {\n result?: unknown\n error?: string\n revalidate?: string[]\n /**\n * Field name to messages, when the host refused the input.\n *\n * The same shape everything else here already uses: Laravel's own\n * `$e->errors()`, the socket protocol's `validation_errors`, and what\n * `issuesToErrors` turns a Standard Schema result into. Dot-joined for a\n * nested field, the empty string for a message about the form rather than\n * any one field.\n */\n validationErrors?: Record<string, string[]>\n /** The caller has no session. Becomes the engine's own authentication error. */\n unauthenticated?: boolean\n /** The caller has a session and still may not. */\n unauthorized?: boolean\n /**\n * Where the host says this request should go instead.\n *\n * Answered with a 200 and this field, never as a 3xx: fetch follows a\n * redirect transparently, so a real one would send the host call itself to\n * the destination and hand whatever came back to the render as the\n * function's result.\n */\n redirect?: string\n /**\n * Where an unexpected failure happened in the backend, sent only in\n * development (Laravel's app.debug, Go's CallbackHandler.Debug): the\n * thrown type, its message, and frames newest first.\n */\n debug?: { type?: string; message?: string; trace?: string[] }\n /** The status to redirect with. Defaults to 307, which preserves the method. */\n redirectStatus?: number\n /**\n * The status a refusal should be answered with.\n *\n * A middleware that aborted meant what it aborted with — throttle answers\n * 429, a signed-url check 403 — and collapsing those to 500 makes a\n * rate-limited visitor indistinguishable from a broken server.\n */\n refusalStatus?: number\n /**\n * What a deliberate refusal carries beside its message (`error`): the\n * records blocking a delete, say. Raised as the action client's own\n * refusal, so an action passes it to the page as `result.refusal`, checked\n * against the schema the action declared - see `refuse()`.\n */\n refusalData?: unknown\n}\n\n/**\n * A batch on the wire: several calls in one POST, answered in order.\n *\n * Calls issued in the same tick of a render - sibling components each\n * awaiting rpc() - travel together, so a page's parallel reads cost the host\n * one request rather than one each. A host that has never heard of the\n * envelope answers it as a malformed single call, and the calls are sent one\n * at a time from then on; nothing is lost but the saving.\n */\nexport interface HostCallBatch {\n calls: { function: string; args: unknown[] }[]\n}\n\nexport interface HostCallBatchReply {\n /** One per call, in order. Each carries the status that call would have had. */\n replies: (HostCallReply & { status?: number })[]\n}\n\n/**\n * A batch answered as it goes: one line per call, each as the host finishes\n * it, in whatever order that is.\n *\n * `application/x-ndjson`, each line a reply with the call's `index` in the\n * batch. A host that answers this way lets a fast call resolve while a slow\n * sibling is still running - which is what keeps a page's boundaries\n * streaming independently when their reads travelled together. A host that\n * answers the whole batch at once, as one JSON object of `replies`, is read\n * as before; the saving of the batch stays, the independence does not.\n */\nexport type HostCallBatchLine = HostCallReply & { index: number; status?: number }\n\n/** How many calls one POST carries at most. */\nconst BATCH_LIMIT = 50\n\ntype Settled = { status: number; reply: HostCallReply | null; text: string; setCookies?: string[] }\n\ninterface Pending {\n name: string\n args: unknown[]\n resolve: (settled: Settled) => void\n reject: (error: unknown) => void\n}\n\ninterface Bucket {\n headers: Record<string, string>\n calls: Pending[]\n}\n\n// After the current I/O, before the next timer: what a render issued\n// synchronously - and across the microtasks between one component's awaits -\n// is in the bucket by then. setImmediate where the runtime has it, a zero\n// timer where it does not (a Worker).\nconst nextTick: (fn: () => void) => void =\n typeof setImmediate === 'function' ? (fn) => setImmediate(fn) : (fn) => setTimeout(fn, 0)\n\n/**\n * The function to hand to `installHostFn`, or to `hostCalls` on the JS host.\n */\n/**\n * The backend's trace, on the error the render sees.\n *\n * As its cause - an Error named for the backend's type, whose stack is the\n * backend's frames - so Node, Bun and the dev overlay print it under the\n * renderer's own stack; and appended to that stack, for whatever prints only\n * the one. Before this a failed rpc() pointed at a line of JavaScript, and the\n * PHP or Go that failed was a separate search through another log.\n */\nfunction withBackendTrace(failure: Error, debug: NonNullable<HostCallReply['debug']>): void {\n const frames = (debug.trace ?? []).map((frame) => ' at ' + frame).join('\\n')\n const cause = new Error(debug.message ?? '')\n\n cause.name = 'Backend ' + (debug.type ?? 'Error')\n cause.stack = cause.name + ': ' + (debug.message ?? '') + (frames ? '\\n' + frames : '')\n\n failure.cause = cause\n failure.stack = (failure.stack ?? String(failure)) + '\\nCaused in the backend by ' + cause.stack\n}\n\n/**\n * Names a fixed header may not take: the protocol's own, and the visitor's,\n * which are forwarded per render and must not be one value for everyone.\n */\nconst RESERVED_HEADERS = new Set(['host', 'content-type', 'content-length', 'cookie', 'authorization', 'forwarded', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto'])\n\n/**\n * The fixed headers sent on every request to the backend - host calls, and\n * the urls forwarded to it - from RSC_BACKEND_HEADERS, a JSON object:\n *\n * RSC_BACKEND_HEADERS={\"X-Preview-Token\":\"...\"}\n *\n * Read once, when the server starts. Malformed is an error naming the\n * variable, never its value: what is in it is usually a credential. Names\n * come back lowercased; none when the variable is unset or empty.\n */\nexport function backendHeaders(value: string | Record<string, string> | undefined): Record<string, string> {\n if (value === undefined || value === '') return {}\n\n const refuse = (why: string): never => {\n throw new Error(`RSC_BACKEND_HEADERS must be a JSON object of header names to strings, e.g. {\"X-Preview-Token\":\"...\"}: ${why}`)\n }\n\n let parsed: unknown = value\n\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value)\n } catch {\n refuse('it is not JSON')\n }\n }\n\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) refuse('it is not an object')\n\n const headers: Record<string, string> = {}\n\n for (const [name, header] of Object.entries(parsed as Record<string, unknown>)) {\n const lower = name.toLowerCase()\n\n if (!/^[!#$%&'*+.^_`|~0-9a-z-]+$/.test(lower)) refuse(`${JSON.stringify(name)} is not a header name`)\n if (typeof header !== 'string') refuse(`${name} is not a string`)\n if (/[\\r\\n\\0]/.test(header as string)) refuse(`${name} holds a line break`)\n if (RESERVED_HEADERS.has(lower) || lower.startsWith('x-rsc-')) refuse(`${name} is set by rsc-kit itself`)\n\n headers[lower] = header as string\n }\n\n return headers\n}\n\nexport function httpHostCalls(\n options: HttpHostCallsOptions,\n): (name: string, ...args: unknown[]) => Promise<unknown> {\n const {\n endpoint,\n secret,\n forwardHeaders = DEFAULT_FORWARDED,\n timeoutMs = 30_000,\n fetch: fetchImpl,\n refusedRetryMs = 2_000,\n onRevalidate,\n } = options\n\n const fixed = backendHeaders(options.headers ?? {})\n\n if (!secret) {\n throw new Error('httpHostCalls requires a secret — see the note on the option.')\n }\n\n const forwarded = forwardHeaders.map((name) => name.toLowerCase())\n\n // One bucket per set of forwarded headers: two visitors' renders in flight\n // at once must not share a request, because the host reads the cookie off\n // the request to know whose session a call runs under.\n const buckets = new Map<string, Bucket>()\n\n async function forwardedHeaders(): Promise<Record<string, string>> {\n const headers: Record<string, string> = {\n ...fixed,\n 'content-type': 'application/json',\n 'x-rsc-host-secret': secret,\n }\n\n // A page a shared cache may keep renders as nobody: no cookie, no\n // authorization, so what the backend answers is the same for everyone.\n // Asked before reading the request, so the read is not counted as one.\n if (renderingAsNobody()) return headers\n\n // Who the visitor is, as the server saw them. The backend reads it in\n // place of the address this call came from - which is this renderer's,\n // and the same for everyone - once the secret has said the caller may be\n // believed. Laravel's `$request->ip()`, and every throttle keyed on it.\n const ip = requestClientIp()\n\n if (ip !== null) headers[CLIENT_IP_HEADER] = ip\n\n // Outside a render — a prerender pass, or a host calling one directly —\n // there is no request to forward from, and that is not an error. The call\n // simply carries no session, which is exactly what a build-time render\n // should be doing.\n //\n // Only that one condition is swallowed. A blanket catch here is the wrong\n // shape: anything else going wrong while reading the request would come\n // out as a call with no session, which is not a failure the caller sees —\n // it is the visitor silently becoming anonymous, and the page rendering as\n // though they were logged out.\n try {\n const from = await incomingHeaders()\n\n for (const key of forwarded) {\n const value = from.get(key)\n if (value !== null) headers[key] = value\n }\n\n // Who the visitor's browser says it is, for whatever the backend keeps\n // about a request: a log, a session list, an audit trail. Sent beside\n // the call's own, which stays this runtime's.\n const agent = from.get('user-agent')\n\n if (agent) headers[CLIENT_USER_AGENT_HEADER] = agent\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n\n if (!message.startsWith('No request in scope')) throw error\n }\n\n return headers\n }\n\n /** One POST. `label` names what is being sent, for the error messages. */\n async function post(\n body: unknown,\n headers: Record<string, string>,\n label: string,\n ): Promise<{ status: number; text: string; setCookies: string[] }> {\n const response = await send(body, headers, label)\n\n // Read the body before branching on status: a host that reports the error\n // in JSON with a 500 is saying something more useful than \"500\", and\n // throwing on the status alone discards it.\n return {\n status: response.status,\n text: await response.text(),\n // A login's session cookie: kept to put on the page's response.\n setCookies: response.headers.getSetCookie?.() ?? [],\n }\n }\n\n /** The POST itself, headers in hand, body still to read. */\n async function send(body: unknown, headers: Record<string, string>, label: string): Promise<Response> {\n const doFetch = fetchImpl ?? globalThis.fetch\n\n // AbortSignal.timeout is not on every runtime this engine targets, so the\n // controller is written out rather than assumed.\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), timeoutMs)\n\n let response: Response\n // From the first refusal, not from the send: the window is how long the\n // backend may take to start listening.\n let refusedAt: number | undefined\n\n try {\n for (let wait = 50; ; wait = Math.min(wait * 2, 400)) {\n try {\n response = await doFetch(endpoint, {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: controller.signal,\n })\n\n break\n } catch (error) {\n // Refused: the backend is not listening yet, and nothing was sent.\n if (!refused(error) || controller.signal.aborted) throw error\n\n refusedAt ??= Date.now()\n\n if (Date.now() - refusedAt + wait > refusedRetryMs) throw error\n\n await new Promise((resolve) => setTimeout(resolve, wait))\n }\n }\n } catch (error) {\n if (controller.signal.aborted) {\n throw new Error(`Host call ${label} timed out after ${timeoutMs}ms`)\n }\n\n throw new Error(\n `Host call ${label} could not reach the host at ${endpoint}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n )\n } finally {\n clearTimeout(timer)\n }\n\n return response\n }\n\n /** A connection the backend refused: Bun says so on the error, Node on its cause. */\n function refused(error: unknown): boolean {\n const code = (e: unknown) => (e as { code?: unknown } | null)?.code\n\n return code(error) === 'ECONNREFUSED' || code((error as { cause?: unknown } | null)?.cause) === 'ECONNREFUSED'\n }\n\n function parse(text: string): HostCallReply | null {\n try {\n return text ? (JSON.parse(text) as HostCallReply) : null\n } catch {\n return null\n }\n }\n\n async function single(\n name: string,\n args: unknown[],\n headers: Record<string, string>,\n validate?: string[],\n ): Promise<Settled> {\n const body = validate ? { function: name, args, validate } : { function: name, args }\n const { status, text, setCookies } = await post(body, headers, JSON.stringify(name))\n\n return { status, reply: parse(text), text, setCookies }\n }\n\n /** Read a streamed batch, one reply per line, resolving each call as its line lands. */\n async function resolveAsLinesArrive(body: ReadableStream<Uint8Array>, calls: Pending[]): Promise<void> {\n const answered = new Set<number>()\n const reader = body.getReader()\n const decoder = new TextDecoder()\n let buffered = ''\n\n const take = (line: string) => {\n const trimmed = line.trim()\n\n if (!trimmed) return\n\n let parsed: Partial<HostCallBatchLine> | null\n\n try {\n parsed = JSON.parse(trimmed) as Partial<HostCallBatchLine>\n } catch {\n return\n }\n\n const index = parsed?.index\n\n if (typeof index !== 'number' || !calls[index] || answered.has(index)) return\n\n const { index: _, status: own, ...reply } = parsed as HostCallBatchLine\n\n answered.add(index)\n calls[index]!.resolve({ status: own ?? 200, reply, text: JSON.stringify(reply) })\n }\n\n try {\n for (;;) {\n const { done, value } = await reader.read()\n\n if (done) break\n\n buffered += decoder.decode(value, { stream: true })\n\n let at: number\n\n while ((at = buffered.indexOf('\\n')) !== -1) {\n take(buffered.slice(0, at))\n buffered = buffered.slice(at + 1)\n }\n }\n\n buffered += decoder.decode()\n take(buffered)\n } catch (error) {\n for (const [i, call] of calls.entries()) {\n if (!answered.has(i)) call.reject(error)\n }\n\n return\n }\n\n // The host closed the batch with a call unanswered: a fault on its side,\n // reported to the call rather than left pending forever.\n for (const [i, call] of calls.entries()) {\n if (!answered.has(i)) {\n call.reject(new Error(`Host call ${JSON.stringify(call.name)} was not answered in its batch`))\n }\n }\n }\n\n /**\n * Send a bucket. One call goes as itself, so a host that speaks only the\n * single shape - or a request that happened to be alone - sees nothing\n * new on the wire.\n */\n async function flush(bucket: Bucket): Promise<void> {\n const { headers, calls } = bucket\n\n if (calls.length === 1) {\n const [only] = calls\n\n try {\n only.resolve(await single(only.name, only.args, headers))\n } catch (error) {\n only.reject(error)\n }\n\n return\n }\n\n const label = `batch of ${calls.length} (${calls.map((c) => c.name).join(', ')})`\n let response: Response\n\n try {\n response = await send(\n { calls: calls.map((c) => ({ function: c.name, args: c.args })) } satisfies HostCallBatch,\n headers,\n label,\n )\n } catch (error) {\n // The host could not be reached, or did not answer in time. Not\n // re-sent one by one: the calls may have run, and an action run twice\n // is worse than one reported as failed.\n for (const call of calls) call.reject(error)\n\n return\n }\n\n // Answered as it goes: each call resolves the moment its line arrives,\n // so a component waiting on a fast read paints while a slow sibling's\n // is still running. The batch saved the round trips; this keeps the\n // streaming the batch would otherwise have cost.\n if (response.status < 400 && (response.headers.get('content-type') ?? '').includes('x-ndjson') && response.body) {\n await resolveAsLinesArrive(response.body, calls)\n\n return\n }\n\n const status = response.status\n const text = await response.text()\n const parsed = parse(text) as Partial<HostCallBatchReply> | null\n const replies = parsed?.replies\n\n if (status < 400 && Array.isArray(replies) && replies.length === calls.length) {\n calls.forEach((call, i) => {\n const { status: own, ...reply } = replies[i]!\n\n call.resolve({ status: own ?? 200, reply, text: JSON.stringify(reply) })\n })\n\n return\n }\n\n // Not a batch answer. Taking batches is part of the protocol - the\n // conformance suite checks it - so this is a backend that does not, or\n // one that failed before reading the calls: wrong secret, down, too many.\n // Every call fails with what the backend said, and none is sent again:\n // they may have run, and an action run twice is worse than one reported.\n const said = parsed && typeof (parsed as HostCallReply).error === 'string' ? (parsed as HostCallReply).error : text.slice(0, 200)\n const failure = new Error(\n `Host call ${label} was not answered as a batch (${status}${said ? `: ${said}` : ''}). ` +\n 'A backend answers { \"calls\": [...] } line by line or as { \"replies\": [...] }: ' +\n 'https://docs.rsc-kit.dev/hosts/your-own-backend/calls#batches',\n )\n\n for (const call of calls) call.reject(failure)\n }\n\n function enqueue(name: string, args: unknown[], headers: Record<string, string>): Promise<Settled> {\n return new Promise<Settled>((resolve, reject) => {\n const key = JSON.stringify(headers)\n let bucket = buckets.get(key)\n\n if (!bucket) {\n bucket = { headers, calls: [] }\n buckets.set(key, bucket)\n\n const mine = bucket\n\n nextTick(() => {\n if (buckets.get(key) === mine) buckets.delete(key)\n\n void flush(mine)\n })\n }\n\n bucket.calls.push({ name, args, resolve, reject })\n\n if (bucket.calls.length >= BATCH_LIMIT) {\n buckets.delete(key)\n\n void flush(bucket)\n }\n })\n }\n\n return async function hostCall(name: string, ...args: unknown[]): Promise<unknown> {\n const headers = await forwardedHeaders()\n // A check rather than a run: the backend validates the fields named and\n // stops - success is a null result, a refusal the 422 it always was.\n // Alone, never in a batch: the envelope has no room for it, and a check\n // is one call by definition.\n const validate = checkedCall(name)\n const settled = validate ? await single(name, args, headers, validate) : await enqueue(name, args, headers)\n\n return interpretReply(name, settled, onRevalidate)\n }\n}\n\n/**\n * What a reply means, in the caller's own async context.\n *\n * Deliberately not done where the response arrives: a batch is answered in\n * a timer, outside every caller's request scope, and `redirect()` and\n * `revalidate()` both write to that scope. Interpreting here, after the\n * caller's await resumed, puts each reply back inside the render it belongs\n * to.\n */\nexport function interpretReply(\n name: string,\n { status, reply, text, setCookies }: Settled,\n onRevalidate?: (targets: string[]) => void,\n): unknown {\n // First, whatever the outcome: a login that then redirects still logged\n // the visitor in. In the caller's context, where the page's response is.\n // Dropped as nobody: a cookie on a page kept for everyone is handed to\n // everyone - and its Set-Cookie alone would make the page private.\n if (setCookies?.length && !renderingAsNobody()) passSetCookies(setCookies)\n\n // Refusing the input is not the call failing — it is the call answering.\n //\n // Thrown rather than returned, so a handler stops where it is instead of\n // carrying on with data the host rejected. createActionClient catches this\n // on the way out and returns { validationErrors }, which is the shape\n // useForm reads: React serialises a REJECTED server action opaquely, so a\n // validation error that stays thrown reaches the browser as \"an error\n // occurred\" with every field it named gone.\n //\n // Checked before `error`, so a host that sends both is read as a refusal\n // rather than as a failure with no fields.\n //\n // One error for both places a call is made. In an action, the mark is\n // what returns the fields to the form. In a page's render there is no\n // form: refusalStatus makes the page answer 422 rather than 500, and the\n // message says which call refused which fields, where \"Validation failed\"\n // read like an action had run.\n if (reply?.validationErrors) {\n const refused = new ActionValidationError(reply.validationErrors)\n const fields = Object.keys(reply.validationErrors).map((field) => field || '(the input as a whole)')\n\n refused.message = `Host call ${JSON.stringify(name)} refused its input: ${fields.join(', ')}`\n ;(refused as ActionValidationError & { refusalStatus?: number }).refusalStatus = 422\n\n throw refused\n }\n\n // Raised as the engine's own redirect, so it travels the path every other\n // redirect travels — a real 3xx above a Suspense boundary, the digest\n // below one — rather than becoming an error the page has to interpret.\n //\n // What it revalidated is marked first: a backend that switched the team\n // and redirected - Rsc::revalidate('all') then redirect() in PHP - goes\n // to a page whose layout reads the team, and the redirect carries the\n // revalidation to the client only if it was marked before the throw.\n if (reply?.redirect) {\n markRevalidated(reply.revalidate, onRevalidate)\n redirect(reply.redirect as never, reply.redirectStatus ?? 307)\n }\n\n if (reply?.unauthenticated) {\n throw new ServerAuthenticationError(reply.error ?? 'Unauthenticated.')\n }\n\n if (reply?.unauthorized) {\n throw new ServerAuthorizationError(reply.error ?? 'This action is unauthorized.')\n }\n\n // The backend says there is no such thing - Go's Refuse(404), Laravel's\n // abort(404), a record this caller cannot see. Raised as the engine's\n // own notFound(), so the page answers with not-found.tsx and a 404,\n // exactly as a component calling notFound() would; as an error it\n // reached the page as \"something went wrong\". The backend's message rides\n // on it for an action, which has no not-found page and shows the message.\n if (reply?.refusalStatus === 404) throw new NotFoundSignal(reply.error ?? 'Not found')\n\n // A status is what makes a reply a refusal rather than a failure: the\n // backend's refuse(), Go's Refuse, Laravel's abort(). Its message was\n // written for the person asking - Laravel shows an HttpException's in its\n // own production JSON - so it is raised as one, with or without data, and\n // onError never replaces it. Only refusals carried data at first, and\n // Refuse(503, \"busy\") reached the form as \"Something went wrong.\".\n if (reply?.error !== undefined && (reply.refusalStatus !== undefined || reply.refusalData !== undefined)) {\n throw new ActionRefusal(reply.error, reply.refusalData, reply.refusalStatus ?? 409)\n }\n\n if (reply?.error !== undefined) {\n const failure = new Error(`Host call ${JSON.stringify(name)} failed: ${reply.error}`)\n\n if (reply.debug) withBackendTrace(failure, reply.debug)\n\n throw failure\n }\n\n if (status >= 400) {\n throw new Error(\n `Host call ${JSON.stringify(name)} failed: ${status}`.trim() +\n (text ? ` — ${text.slice(0, 200)}` : ''),\n )\n }\n\n if (reply === null) {\n throw new Error(\n `Host call ${JSON.stringify(name)} returned a body that is not JSON: ${text.slice(0, 200)}`,\n )\n }\n\n markRevalidated(reply.revalidate, onRevalidate)\n\n return reply.result ?? null\n}\n\nfunction markRevalidated(targets: string[] | undefined, onRevalidate?: (targets: string[]) => void): void {\n if (!targets?.length) return\n if (onRevalidate) onRevalidate(targets)\n // Named by the host over the wire - Rsc::revalidate('orders') in PHP -\n // so nothing here can check it; the renderer refuses an unknown name.\n else for (const target of targets) revalidate(target as RevalidateTarget)\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Where a backend function is written, for the editor to go to. */
|
|
2
|
+
export interface HostSource {
|
|
3
|
+
/** Relative to the manifest, with forward slashes. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** 1-based. */
|
|
6
|
+
line: number;
|
|
7
|
+
/** What the backend calls it: App\Rsc\LoginPage::props. */
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A manifest without where its functions are, for asking whether the backend
|
|
12
|
+
* changed. Their lines move with every edit above them, and a server that
|
|
13
|
+
* restarted for that would restart on every save in the backend.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withoutSources(text: string | null): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* The source map of the overloads in `types`, or null when none of them has a
|
|
18
|
+
* source. `at` answers for a function's name, its file relative to the map.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hostSourceMap(types: string, file: string, global: string, at: (name: string) => {
|
|
21
|
+
file: string;
|
|
22
|
+
line: number;
|
|
23
|
+
} | undefined): string | null;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Where the backend's functions are written, for an editor to go to.
|
|
2
|
+
//
|
|
3
|
+
// The manifest says it as `sources`, by function name, and the build turns it
|
|
4
|
+
// into a source map of the rpc() declaration. Nothing the app runs reads it.
|
|
5
|
+
/**
|
|
6
|
+
* A manifest without where its functions are, for asking whether the backend
|
|
7
|
+
* changed. Their lines move with every edit above them, and a server that
|
|
8
|
+
* restarted for that would restart on every save in the backend.
|
|
9
|
+
*/
|
|
10
|
+
export function withoutSources(text) {
|
|
11
|
+
if (text === null)
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
const { sources: _, ...rest } = JSON.parse(text);
|
|
15
|
+
return JSON.stringify(rest);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The source map of the overloads in `types`, or null when none of them has a
|
|
23
|
+
* source. `at` answers for a function's name, its file relative to the map.
|
|
24
|
+
*/
|
|
25
|
+
export function hostSourceMap(types, file, global, at) {
|
|
26
|
+
const lead = "declare function ";
|
|
27
|
+
const sources = [];
|
|
28
|
+
let mappings = "";
|
|
29
|
+
// Every field is written as its distance from the last one.
|
|
30
|
+
let source = 0;
|
|
31
|
+
let line = 0;
|
|
32
|
+
for (const [i, text] of types.split("\n").entries()) {
|
|
33
|
+
if (i > 0)
|
|
34
|
+
mappings += ";";
|
|
35
|
+
const name = text.startsWith(lead + global + "<") ? /\(name: ("(?:[^"\\]|\\.)*")/.exec(text)?.[1] : undefined;
|
|
36
|
+
const to = name === undefined ? undefined : at(JSON.parse(name));
|
|
37
|
+
if (!to)
|
|
38
|
+
continue;
|
|
39
|
+
let index = sources.indexOf(to.file);
|
|
40
|
+
if (index < 0)
|
|
41
|
+
index = sources.push(to.file) - 1;
|
|
42
|
+
// Where the overload's own name starts, then where it ends: without the
|
|
43
|
+
// second, the rest of the line would be in the backend's file too.
|
|
44
|
+
mappings += vlq(lead.length) + vlq(index - source) + vlq(to.line - 1 - line) + vlq(0);
|
|
45
|
+
mappings += "," + vlq(global.length);
|
|
46
|
+
source = index;
|
|
47
|
+
line = to.line - 1;
|
|
48
|
+
}
|
|
49
|
+
if (sources.length === 0)
|
|
50
|
+
return null;
|
|
51
|
+
return JSON.stringify({ version: 3, file, sourceRoot: "", sources, names: [], mappings }) + "\n";
|
|
52
|
+
}
|
|
53
|
+
/** A number as a source map writes it. */
|
|
54
|
+
function vlq(value) {
|
|
55
|
+
const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
56
|
+
let rest = value < 0 ? (-value << 1) | 1 : value << 1;
|
|
57
|
+
let out = "";
|
|
58
|
+
do {
|
|
59
|
+
const digit = rest & 31;
|
|
60
|
+
rest >>>= 5;
|
|
61
|
+
out += digits[rest > 0 ? digit | 32 : digit];
|
|
62
|
+
} while (rest > 0);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=hostSources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostSources.js","sourceRoot":"","sources":["../src/hostSources.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAY7E;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAmB;IAChD,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAE/B,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,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C","sourcesContent":["// Where the backend's functions are written, for an editor to go to.\n//\n// The manifest says it as `sources`, by function name, and the build turns it\n// into a source map of the rpc() declaration. Nothing the app runs reads it.\n\n/** Where a backend function is written, for the editor to go to. */\nexport interface HostSource {\n /** Relative to the manifest, with forward slashes. */\n file: string;\n /** 1-based. */\n line: number;\n /** What the backend calls it: App\\Rsc\\LoginPage::props. */\n name?: string;\n}\n\n/**\n * A manifest without where its functions are, for asking whether the backend\n * changed. Their lines move with every edit above them, and a server that\n * restarted for that would restart on every save in the backend.\n */\nexport function withoutSources(text: string | null): string | null {\n if (text === null) return null;\n\n try {\n const { sources: _, ...rest } = JSON.parse(text) as Record<string, unknown>;\n\n return JSON.stringify(rest);\n } catch {\n return text;\n }\n}\n\n/**\n * The source map of the overloads in `types`, or null when none of them has a\n * source. `at` answers for a function's name, its file relative to the map.\n */\nexport function hostSourceMap(\n types: string,\n file: string,\n global: string,\n at: (name: string) => { file: string; line: number } | undefined,\n): string | null {\n const lead = \"declare function \";\n const sources: string[] = [];\n let mappings = \"\";\n // Every field is written as its distance from the last one.\n let source = 0;\n let line = 0;\n\n for (const [i, text] of types.split(\"\\n\").entries()) {\n if (i > 0) mappings += \";\";\n\n const name = text.startsWith(lead + global + \"<\") ? /\\(name: (\"(?:[^\"\\\\]|\\\\.)*\")/.exec(text)?.[1] : undefined;\n const to = name === undefined ? undefined : at(JSON.parse(name) as string);\n\n if (!to) continue;\n\n let index = sources.indexOf(to.file);\n\n if (index < 0) index = sources.push(to.file) - 1;\n\n // Where the overload's own name starts, then where it ends: without the\n // second, the rest of the line would be in the backend's file too.\n mappings += vlq(lead.length) + vlq(index - source) + vlq(to.line - 1 - line) + vlq(0);\n mappings += \",\" + vlq(global.length);\n source = index;\n line = to.line - 1;\n }\n\n if (sources.length === 0) return null;\n\n return JSON.stringify({ version: 3, file, sourceRoot: \"\", sources, names: [], mappings }) + \"\\n\";\n}\n\n/** A number as a source map writes it. */\nfunction vlq(value: number): string {\n const digits = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let rest = value < 0 ? (-value << 1) | 1 : value << 1;\n let out = \"\";\n\n do {\n const digit = rest & 31;\n rest >>>= 5;\n out += digits[rest > 0 ? digit | 32 : digit];\n } while (rest > 0);\n\n return out;\n}\n"]}
|
package/dist/prerender.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface PrerenderEngine {
|
|
|
28
28
|
}[], loadings?: string[], parallelSlots?: Record<string, string>, pageKey?: string,
|
|
29
29
|
/** How long to render before taking what has flushed. Defaults to the full budget. */
|
|
30
30
|
budgetMs?: number,
|
|
31
|
-
/** Whether
|
|
31
|
+
/** Whether rpc() is answered for whoever asked. False at build, which has the build's own answers (buildScope.ts). */
|
|
32
32
|
canReachHost?: boolean,
|
|
33
33
|
/**
|
|
34
34
|
* Called once, when the render has stopped producing anything and is only
|
|
@@ -73,11 +73,12 @@ export interface PrerenderEngine {
|
|
|
73
73
|
props: Record<string, unknown>;
|
|
74
74
|
}[], loadings?: string[], parallelSlots?: Record<string, string>, from?: number, pageKey?: string, bootstrap?: boolean,
|
|
75
75
|
/**
|
|
76
|
-
* Whether
|
|
76
|
+
* Whether rpc() is answered for whoever asked.
|
|
77
77
|
*
|
|
78
|
-
* False during a build,
|
|
79
|
-
*
|
|
80
|
-
*
|
|
78
|
+
* False during a build, which asks the backend itself (buildScope.ts): a
|
|
79
|
+
* call that needs a visitor, or any call when there is no backend to ask,
|
|
80
|
+
* suspends and is reported, instead of resolving to undefined and being
|
|
81
|
+
* stored holding it.
|
|
81
82
|
*/
|
|
82
83
|
canReachHost?: boolean): Promise<{
|
|
83
84
|
body: string;
|
|
@@ -147,6 +148,16 @@ export interface PrerenderOptions {
|
|
|
147
148
|
/** Called as each url is decided, for build output. */
|
|
148
149
|
onResult?: (result: PrerenderResult) => void;
|
|
149
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* What to do about routes that threw while the build rendered them, by what
|
|
153
|
+
* they threw. One answer used to be printed for all of them - make what the
|
|
154
|
+
* page needs reachable from the build - and an app missing a "use client" was
|
|
155
|
+
* sent to look at whether its backend was running.
|
|
156
|
+
*/
|
|
157
|
+
export declare function renderFailureAdvice(failures: readonly {
|
|
158
|
+
url: string;
|
|
159
|
+
reason: string | null;
|
|
160
|
+
}[]): string;
|
|
150
161
|
/**
|
|
151
162
|
* The build's refusal to store a route it cannot answer ahead of time.
|
|
152
163
|
*
|
|
@@ -258,6 +269,8 @@ export declare function notes(results: {
|
|
|
258
269
|
type?: string;
|
|
259
270
|
reason?: string | null;
|
|
260
271
|
}[]): string;
|
|
272
|
+
/** What a stored page holds of the backend's, for its line in the build. */
|
|
273
|
+
export declare function storedAnswers(calls: string[]): string;
|
|
261
274
|
/**
|
|
262
275
|
* The one-line tally under the legend, in the legend's own words.
|
|
263
276
|
*/
|
package/dist/prerender.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { withRedirect } from "./redirect.js";
|
|
18
18
|
import { withCache } from "./cache.js";
|
|
19
19
|
import { requestFallbacks, requestReadBy, requestReadWhere, requestWasRead, withRequest, } from "./request.js";
|
|
20
|
+
import { buildAnswerer, withBuildCalls } from "./buildScope.js";
|
|
20
21
|
import { watchNondeterminism, whileRendering } from "./nondeterminism.js";
|
|
21
22
|
/** What a prerenderer needs from the built bundle, beyond serving a request. */
|
|
22
23
|
/**
|
|
@@ -105,6 +106,54 @@ export function withWorkerRegistration(html) {
|
|
|
105
106
|
? html
|
|
106
107
|
: html.slice(0, at) + WORKER_REGISTRATION + html.slice(at);
|
|
107
108
|
}
|
|
109
|
+
/** What React says when a server component hands the browser something it cannot send. */
|
|
110
|
+
const UNSENDABLE = /Functions cannot be passed directly to Client Components|Event handlers cannot be passed to Client Component props|Client Functions cannot be passed|Classes or other objects with methods|Only plain objects(?:, and a few built-ins,)? can be passed to Client Components/;
|
|
111
|
+
/** What a runtime says when the other end was not there. */
|
|
112
|
+
const UNREACHABLE = /ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|ECONNRESET|Unable to connect|fetch failed|getaddrinfo|connection (?:refused|terminated|timed out)/i;
|
|
113
|
+
/** A backend that failed a call the build made, or went away during one. */
|
|
114
|
+
const HOST_CALL = /Host call "|rpc\("[^"]*"\) failed: |The backend's build process /;
|
|
115
|
+
/**
|
|
116
|
+
* What to do about routes that threw while the build rendered them, by what
|
|
117
|
+
* they threw. One answer used to be printed for all of them - make what the
|
|
118
|
+
* page needs reachable from the build - and an app missing a "use client" was
|
|
119
|
+
* sent to look at whether its backend was running.
|
|
120
|
+
*/
|
|
121
|
+
export function renderFailureAdvice(failures) {
|
|
122
|
+
const of = (kind) => failures.filter((f) => kind(f.reason ?? ""));
|
|
123
|
+
const unsendable = of((reason) => UNSENDABLE.test(reason));
|
|
124
|
+
const backend = of((reason) => HOST_CALL.test(reason));
|
|
125
|
+
const unreachable = of((reason) => !UNSENDABLE.test(reason) && !HOST_CALL.test(reason) && UNREACHABLE.test(reason));
|
|
126
|
+
const other = of((reason) => !UNSENDABLE.test(reason) && !HOST_CALL.test(reason) && !UNREACHABLE.test(reason));
|
|
127
|
+
const names = (routes) => routes.map((f) => f.url).join(", ");
|
|
128
|
+
const advice = [];
|
|
129
|
+
if (unsendable.length > 0) {
|
|
130
|
+
advice.push(`${names(unsendable)}: a server component passed a client component something the browser\n` +
|
|
131
|
+
"can't be sent: a function, or an object that isn't plain data. The error above names\n" +
|
|
132
|
+
"the prop. If it belongs in the browser - an event handler, or the function inside a\n" +
|
|
133
|
+
'<Form> - put "use client" at the top of the file that writes it. If it runs on the\n' +
|
|
134
|
+
'server, make it a "use server" action. An object: pass its fields instead.');
|
|
135
|
+
}
|
|
136
|
+
if (backend.length > 0) {
|
|
137
|
+
advice.push(`${names(backend)}: the backend failed a call the build made. The build asks it what rpc()\n` +
|
|
138
|
+
"answers, so data that is the same for everyone is stored with the page. Give the build\n" +
|
|
139
|
+
"what the backend needs - its database, its environment. Or put `await connection()`\n" +
|
|
140
|
+
"before the call: that part renders per request, and the rest of the page is still\n" +
|
|
141
|
+
"stored. `hostManifest: { calls: false }` in rscKit({}) stops the build asking at all.");
|
|
142
|
+
}
|
|
143
|
+
if (unreachable.length > 0) {
|
|
144
|
+
advice.push(`${names(unreachable)}: the build couldn't reach something the page reads. Prerendering runs your\n` +
|
|
145
|
+
"app, so a database or an API it calls has to be running and reachable while you build.\n" +
|
|
146
|
+
"Or put `await connection()` before the read: that part renders per request, and the\n" +
|
|
147
|
+
"rest of the page is still stored.");
|
|
148
|
+
}
|
|
149
|
+
if (other.length > 0) {
|
|
150
|
+
advice.push(`${names(other)}: the page threw the error above while it rendered, and would for a visitor too\n` +
|
|
151
|
+
"unless it needs something only a running server has. If it does, put\n" +
|
|
152
|
+
"`await connection()` before that read: that part renders per request, and the rest\n" +
|
|
153
|
+
"of the page is still stored.");
|
|
154
|
+
}
|
|
155
|
+
return advice.join("\n\n");
|
|
156
|
+
}
|
|
108
157
|
/**
|
|
109
158
|
* The build's refusal to store a route it cannot answer ahead of time.
|
|
110
159
|
*
|
|
@@ -133,13 +182,15 @@ export class NotPrerenderable extends Error {
|
|
|
133
182
|
if (threw.length > 0) {
|
|
134
183
|
advice.push("These failed while rendering:\n\n" +
|
|
135
184
|
threw.map((r) => ` ${r.url} — ${r.reason}`).join("\n") +
|
|
136
|
-
"\n\
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
185
|
+
"\n\n" +
|
|
186
|
+
renderFailureAdvice(threw) +
|
|
187
|
+
// The host call is the one read a build with no backend to ask never
|
|
188
|
+
// has to make. When it has one, the calls are the reads.
|
|
189
|
+
(!buildAnswerer() && threw.some((r) => UNREACHABLE.test(r.reason ?? "") && !UNSENDABLE.test(r.reason ?? ""))
|
|
190
|
+
? "\n\nReaching for data through the host — `await rpc(...)` — avoids this\n" +
|
|
191
|
+
"entirely: the build stubs that call, so the page freezes a shell\n" +
|
|
192
|
+
"without the data being available."
|
|
193
|
+
: ""));
|
|
143
194
|
}
|
|
144
195
|
super("Some routes could not be prerendered.\n\n" + advice.join("\n\n") + "\n");
|
|
145
196
|
this.name = "NotPrerenderable";
|
|
@@ -266,13 +317,24 @@ export function notes(results) {
|
|
|
266
317
|
return parts.join("\n\n");
|
|
267
318
|
}
|
|
268
319
|
function rpcNote() {
|
|
269
|
-
|
|
270
|
-
"
|
|
271
|
-
|
|
320
|
+
if (buildAnswerer()) {
|
|
321
|
+
return (" The build asked the backend what rpc() answers. What is the same for everyone is\n" +
|
|
322
|
+
" stored; a call that read the visitor - named in brackets - streams, so whoever\n" +
|
|
323
|
+
" asks is answered for themselves.\n" +
|
|
324
|
+
"\n" +
|
|
325
|
+
" A stored answer is kept until the next build. If it should be read per request\n" +
|
|
326
|
+
" instead, say so with await connection(), or export const revalidate = 60.");
|
|
327
|
+
}
|
|
328
|
+
return (" This build has no backend to ask. rpc() suspends instead of answering, so a page\n" +
|
|
329
|
+
" that reads through one ships a shell and finishes for whoever asks.\n" +
|
|
272
330
|
"\n" +
|
|
273
|
-
"
|
|
274
|
-
"
|
|
275
|
-
"
|
|
331
|
+
" With hostManifest, and a backend that answers build calls, the data that is the\n" +
|
|
332
|
+
" same for everyone is stored instead. If a page should be per request whatever the\n" +
|
|
333
|
+
" build can ask, say so with await connection().");
|
|
334
|
+
}
|
|
335
|
+
/** What a stored page holds of the backend's, for its line in the build. */
|
|
336
|
+
export function storedAnswers(calls) {
|
|
337
|
+
return `${calls.join(", ")} answered at build time, and stored`;
|
|
276
338
|
}
|
|
277
339
|
/**
|
|
278
340
|
* The one-line tally under the legend, in the legend's own words.
|
|
@@ -431,7 +493,22 @@ export async function prerender(options) {
|
|
|
431
493
|
working.give();
|
|
432
494
|
}
|
|
433
495
|
};
|
|
434
|
-
runs.push(
|
|
496
|
+
runs.push(withBuildCalls(async (made) => {
|
|
497
|
+
const result = await prerenderOne(route, params, url, release);
|
|
498
|
+
const { answered, failed } = made();
|
|
499
|
+
// Whether or not the page caught it. A page that catches a failed
|
|
500
|
+
// call and renders "unavailable" is right for a visitor whose
|
|
501
|
+
// backend is down, and wrong to store for all of them.
|
|
502
|
+
if (failed.length && result.type !== "error" && result.type !== "blocked") {
|
|
503
|
+
return { ...result, type: "blocked", reason: `could not be rendered at build time: ${failed[0]}` };
|
|
504
|
+
}
|
|
505
|
+
// What the backend answered is in what was stored, until the next
|
|
506
|
+
// build. Said, so the line shows what a page will keep.
|
|
507
|
+
if (answered.length && (result.type === "frozen" || result.type === "shell")) {
|
|
508
|
+
result.note = [result.note, storedAnswers(answered)].filter(Boolean).join("; ");
|
|
509
|
+
}
|
|
510
|
+
return result;
|
|
511
|
+
})
|
|
435
512
|
.then((result) => {
|
|
436
513
|
results[index] = result;
|
|
437
514
|
options.onResult?.(result);
|
|
@@ -690,7 +767,9 @@ export async function prerender(options) {
|
|
|
690
767
|
? readBy
|
|
691
768
|
: ["the request"]).join(", ")
|
|
692
769
|
: shell.usedDynamicApis
|
|
693
|
-
?
|
|
770
|
+
? shell.dynamicBecause?.length
|
|
771
|
+
? "waits on " + shell.dynamicBecause.join(", ")
|
|
772
|
+
: "reaches for the host"
|
|
694
773
|
: "blocks") +
|
|
695
774
|
" before anything can paint." +
|
|
696
775
|
(readWhere.some((w) => w.includes(" awaited by "))
|
|
@@ -748,7 +827,7 @@ export async function prerender(options) {
|
|
|
748
827
|
// it otherwise, and nothing says so — the page comes out whole apart from
|
|
749
828
|
// the missing region.
|
|
750
829
|
route.loadings, route.slots, 0, url, true,
|
|
751
|
-
//
|
|
830
|
+
// No visitor, so a host call is answered by the build or must suspend
|
|
752
831
|
// rather than resolve. Without this they found no host at all and the
|
|
753
832
|
// page was frozen holding whatever undefined rendered to — a document
|
|
754
833
|
// that looks right, hydrates against an undefined prop, and blanks.
|