@nifrajs/web 2.11.0 → 2.12.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/build-vite.d.ts.map +1 -1
- package/dist/build-vite.js +10 -0
- package/dist/build-vite.js.map +1 -1
- package/dist/build.d.ts +7 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +5 -2
- package/dist/build.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +12 -7
- package/dist/client.js.map +1 -1
- package/dist/conformance.d.ts +1 -1
- package/dist/conformance.d.ts.map +1 -1
- package/dist/deferred.d.ts +1 -1
- package/dist/deferred.d.ts.map +1 -1
- package/dist/deferred.js +14 -3
- package/dist/deferred.js.map +1 -1
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +16 -0
- package/dist/dev.js.map +1 -1
- package/dist/fonts-google.d.ts +2 -2
- package/dist/fonts-google.d.ts.map +1 -1
- package/dist/fonts-google.js +12 -3
- package/dist/fonts-google.js.map +1 -1
- package/dist/index.d.ts +65 -117
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -66
- package/dist/index.js.map +1 -1
- package/dist/isr.d.ts.map +1 -1
- package/dist/isr.js +4 -1
- package/dist/isr.js.map +1 -1
- package/dist/llms-txt.d.ts +3 -1
- package/dist/llms-txt.d.ts.map +1 -1
- package/dist/llms-txt.js +23 -20
- package/dist/llms-txt.js.map +1 -1
- package/dist/manifest.d.ts +5 -3
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js.map +1 -1
- package/dist/navigation.d.ts +9 -0
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +8 -1
- package/dist/navigation.js.map +1 -1
- package/dist/render-seam.d.ts +61 -0
- package/dist/render-seam.d.ts.map +1 -0
- package/dist/render-seam.js +22 -0
- package/dist/render-seam.js.map +1 -0
- package/package.json +2 -2
- package/src/build-vite.ts +11 -0
- package/src/build.ts +18 -1
- package/src/client.ts +13 -7
- package/src/conformance.ts +1 -1
- package/src/deferred.ts +14 -2
- package/src/dev.ts +14 -0
- package/src/fonts-google.ts +14 -5
- package/src/index.ts +137 -156
- package/src/isr.ts +4 -1
- package/src/llms-txt.ts +24 -20
- package/src/manifest.ts +5 -3
- package/src/navigation.ts +14 -1
- package/src/render-seam.ts +76 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic rendering protocol shared by the web runtime and every render adapter.
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally small and has no runtime dependencies. Keeping the protocol and the
|
|
5
|
+
* dev SSR-loader singleton here lets adapters and conformance tests depend on the seam directly
|
|
6
|
+
* without importing the document renderer through the root module. The singleton is stored on
|
|
7
|
+
* globalThis because the Bun and Vite dev pipelines can evaluate two copies in one process.
|
|
8
|
+
*/
|
|
9
|
+
import type { Submission } from "./router.ts"
|
|
10
|
+
|
|
11
|
+
/** The data handed to a route component. */
|
|
12
|
+
export interface RenderProps {
|
|
13
|
+
readonly data: unknown
|
|
14
|
+
/** Per-layout loader data, aligned index-for-index with the layout prefix of `chain`. */
|
|
15
|
+
readonly layoutData?: readonly unknown[]
|
|
16
|
+
readonly actionData?: unknown
|
|
17
|
+
/** True while a client navigation or submit is in flight (client-only; absent/false on SSR). */
|
|
18
|
+
readonly pending?: boolean
|
|
19
|
+
/** The path a client navigation is transitioning TO while `pending` (client-only; absent on SSR). */
|
|
20
|
+
readonly pendingPath?: string
|
|
21
|
+
/** The in-flight client submit, for optimistic UI (client-only; absent on SSR). */
|
|
22
|
+
readonly submission?: Submission
|
|
23
|
+
/** The matched route's decoded path params. */
|
|
24
|
+
readonly params?: Readonly<Record<string, string>>
|
|
25
|
+
/** The current URL's `pathname + search` (no hash). */
|
|
26
|
+
readonly path?: string
|
|
27
|
+
/** The route's typed, validated search params. */
|
|
28
|
+
readonly search?: Record<string, unknown>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The seam every render adapter implements. New adapters should prove these invariants with
|
|
33
|
+
* `assertRenderAdapterConformance`; framework-specific behavior remains locally tested.
|
|
34
|
+
*/
|
|
35
|
+
export interface RenderAdapter {
|
|
36
|
+
/**
|
|
37
|
+
* Render a route's layout `chain` (outermost layout → page) to a Web stream of HTML bytes,
|
|
38
|
+
* including the framework's hydration markers.
|
|
39
|
+
*/
|
|
40
|
+
renderToStream(
|
|
41
|
+
chain: readonly unknown[],
|
|
42
|
+
props: RenderProps,
|
|
43
|
+
): ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>
|
|
44
|
+
/** Render the chain to a complete HTML string when no content is deferred. */
|
|
45
|
+
renderToString?(chain: readonly unknown[], props: RenderProps): string | Promise<string>
|
|
46
|
+
/** Per-document bootstrap markup injected into `<head>` for client hydration. */
|
|
47
|
+
hydrationHead(nonce?: string): string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Loads a module through the dev server's module graph rather than the runtime's resolver. */
|
|
51
|
+
export type SsrModuleLoader = (id: string) => Promise<unknown>
|
|
52
|
+
|
|
53
|
+
const SSR_MODULE_LOADER_SLOT = Symbol.for("nifra.web.ssr-module-loader")
|
|
54
|
+
const loaderSlot = globalThis as { [SSR_MODULE_LOADER_SLOT]?: SsrModuleLoader | undefined }
|
|
55
|
+
|
|
56
|
+
/** Publish or clear the dev server's SSR module loader. */
|
|
57
|
+
export function setSsrModuleLoader(load: SsrModuleLoader | undefined): void {
|
|
58
|
+
loaderSlot[SSR_MODULE_LOADER_SLOT] = load
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Return the dev server's SSR module loader, when one owns SSR resolution. */
|
|
62
|
+
export function ssrModuleLoader(): SsrModuleLoader | undefined {
|
|
63
|
+
return loaderSlot[SSR_MODULE_LOADER_SLOT]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Global the server serializes loader data into; the client reads it to hydrate. */
|
|
67
|
+
export const DATA_GLOBAL = "__NIFRA_DATA__"
|
|
68
|
+
/** Per-layout loader data for hydration. */
|
|
69
|
+
export const LAYOUT_DATA_GLOBAL = "__NIFRA_LAYOUT_DATA__"
|
|
70
|
+
/** Global the server writes the matched route id into. */
|
|
71
|
+
export const ROUTE_GLOBAL = "__NIFRA_ROUTE__"
|
|
72
|
+
/** Global the server serializes an action's data return into (absent on GETs); the client reads it
|
|
73
|
+
* so hydration after a native form POST matches the server-rendered markup. */
|
|
74
|
+
export const ACTION_GLOBAL = "__NIFRA_ACTION__"
|
|
75
|
+
/** Marker attribute used to find a non-default hydration container. */
|
|
76
|
+
export const ROOT_ATTRIBUTE = "data-nifra-root"
|