@real-router/vue 0.25.3 → 0.25.5

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.
@@ -1,5 +1,4 @@
1
1
  import { PropType } from "vue";
2
- //#region src/utils/createHttpStatusSink.d.ts
3
2
  /**
4
3
  * Render-scoped HTTP status sink. Created per request on the server, passed to
5
4
  * `<HttpStatusProvider :sink="...">`, and read after `renderToString` /
@@ -28,20 +27,14 @@ interface HttpStatusSink {
28
27
  code: number | undefined;
29
28
  }
30
29
  export declare function createHttpStatusSink(): HttpStatusSink;
31
- //#endregion
32
- //#region src/components/ClientOnly.d.ts
33
30
  export declare const ClientOnly: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
34
31
  [key: string]: any;
35
32
  }>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
36
33
  type ClientOnlyProps = InstanceType<typeof ClientOnly>["$props"];
37
- //#endregion
38
- //#region src/components/ServerOnly.d.ts
39
34
  export declare const ServerOnly: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
40
35
  [key: string]: any;
41
36
  }>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
42
37
  type ServerOnlyProps = InstanceType<typeof ServerOnly>["$props"];
43
- //#endregion
44
- //#region src/components/Await.d.ts
45
38
  /**
46
39
  * Reads `useDeferred(name)` and hands the resolved value to the `default`
47
40
  * scoped slot via Vue's native `async setup()` Suspense pattern. Wrap in
@@ -87,8 +80,6 @@ export declare const Await: import("vue").DefineComponent<import("vue").ExtractP
87
80
  };
88
81
  }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
89
82
  type AwaitProps = InstanceType<typeof Await>["$props"];
90
- //#endregion
91
- //#region src/components/Streamed.d.ts
92
83
  /**
93
84
  * Cross-adapter alias for Vue's native `<Suspense>`. Symmetric naming with
94
85
  * the React/Preact/Solid/Svelte/Angular `<Streamed>` components.
@@ -106,8 +97,6 @@ export declare const Streamed: import("vue").DefineComponent<{}, () => import("v
106
97
  [key: string]: any;
107
98
  }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
108
99
  type StreamedProps = InstanceType<typeof Streamed>["$props"];
109
- //#endregion
110
- //#region src/components/HttpStatusCode.d.ts
111
100
  /**
112
101
  * Render-time HTTP status declaration. Mount inside a route component (typical
113
102
  * use case: a glob `*` route's NotFound page) when the status is decided by
@@ -169,8 +158,6 @@ export declare const HttpStatusCode: import("vue").DefineComponent<import("vue")
169
158
  };
170
159
  }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
171
160
  type HttpStatusCodeProps = InstanceType<typeof HttpStatusCode>["$props"];
172
- //#endregion
173
- //#region src/components/HttpStatusProvider.d.ts
174
161
  export declare const HttpStatusProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
175
162
  sink: {
176
163
  type: PropType<HttpStatusSink>;
@@ -185,8 +172,6 @@ export declare const HttpStatusProvider: import("vue").DefineComponent<import("v
185
172
  };
186
173
  }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
187
174
  type HttpStatusProviderProps = InstanceType<typeof HttpStatusProvider>["$props"];
188
- //#endregion
189
- //#region src/composables/useDeferred.d.ts
190
175
  /**
191
176
  * Read a deferred promise published by `defer({ deferred: { <key>: Promise } })`
192
177
  * inside an SSR data loader. Returns the Promise for use inside `async setup()`
@@ -207,6 +192,5 @@ type HttpStatusProviderProps = InstanceType<typeof HttpStatusProvider>["$props"]
207
192
  * silent runtime error.
208
193
  */
209
194
  export declare function useDeferred<T = unknown>(key: string): Promise<T>;
210
- //#endregion
211
195
  export type { AwaitProps, ClientOnlyProps, HttpStatusCodeProps, HttpStatusProviderProps, HttpStatusSink, ServerOnlyProps, StreamedProps };
212
196
  //# sourceMappingURL=ssr.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.d.mts","names":[],"sources":["../../src/utils/createHttpStatusSink.ts","../../src/components/ClientOnly.ts","../../src/components/ServerOnly.ts","../../src/components/Await.ts","../../src/components/Streamed.ts","../../src/components/HttpStatusCode.ts","../../src/components/HttpStatusProvider.ts","../../src/composables/useDeferred.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;UAwBiB;EACf;;wBAGc,wBAAwB;;;qBC1B3B,0BAAU,wCAAA,oBAAA,4BAAA;;4CAWrB,qCAAA,iDAAA,aAAA,eAAA,oDAAA;KAEU,kBAAkB,oBAAoB;;;qBCbrC,0BAAU,wCAAA,oBAAA,4BAAA;;4CAWrB,qCAAA,iDAAA,aAAA,eAAA,oDAAA;KAEU,kBAAkB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBCkBrC,qBAAK,8BAAA;;;;;;;;;;;;;;MAWhB,oDAAA;KAEU,aAAa,oBAAoB;;;;;;;;;;;;;;;;qBC/BhC,wBAAQ,wCAAA,oBAAA,4BAAA;;8BAanB,qCAAA,iDAAA,aAAA,eAAA,oDAAA;KAEU,gBAAgB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBC0BnC,8BAAc,8BAAA;;;;;;0CAjDA,qCAAA,iDAAA,aAAA,uBAAA;;;;;;MA+EzB,oDAAA;KAEU,sBAAsB,oBAAoB;;;qBCjFzC,kCAAkB,8BAAA;;IAGH,MAAA,SAAS;;;;;;;IAAT,MAAA,SAAS;;;MAOnC,oDAAA;KAEU,0BAA0B,oBAC7B;;;;;;;;;;;;;;;;;;;;;;wBCUO,YAAY,aAAa,cAAc,QAAQ"}
1
+ {"version":3,"file":"ssr.d.mts","names":[],"sources":["../../src/utils/createHttpStatusSink.ts","../../src/components/ClientOnly.ts","../../src/components/ServerOnly.ts","../../src/components/Await.ts","../../src/components/Streamed.ts","../../src/components/HttpStatusCode.ts","../../src/components/HttpStatusProvider.ts","../../src/composables/useDeferred.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;UAwBiB;EACf;;wBAGc,wBAAwB;qBC1B3B,0BAAU,wCAAA,oBAAA,4BAAA;;4CAWrB,qCAAA,iDAAA,aAAA,eAAA,oDAAA;KAEU,kBAAkB,oBAAoB;qBCbrC,0BAAU,wCAAA,oBAAA,4BAAA;;4CAWrB,qCAAA,iDAAA,aAAA,eAAA,oDAAA;KAEU,kBAAkB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBCkBrC,qBAAK,8BAAA;;;;;;;;;;;;;;MAWhB,oDAAA;KAEU,aAAa,oBAAoB;;;;;;;;;;;;;;qBC/BhC,wBAAQ,wCAAA,oBAAA,4BAAA;;8BAanB,qCAAA,iDAAA,aAAA,eAAA,oDAAA;KAEU,gBAAgB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBC0BnC,8BAAc,8BAAA;;;;;;0CAjDA,qCAAA,iDAAA,aAAA,uBAAA;;;;;;MA+EzB,oDAAA;KAEU,sBAAsB,oBAAoB;qBCjFzC,kCAAkB,8BAAA;;IAGH,MAAA,SAAS;;;;;;;IAAT,MAAA,SAAS;;;MAOnC,oDAAA;KAEU,0BAA0B,oBAC7B;;;;;;;;;;;;;;;;;;;;wBCUO,YAAY,aAAa,cAAc,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.mjs","names":["HTTP_STATUS_KEY","ClientOnly","defineComponent","mounted","ref","onMounted","slots","ServerOnly","NEVER_PROMISE","useDeferred","useRoute","route","key","Await","value","props","Streamed","h","Suspense","renderNull","HttpStatusCode","sink","inject","HttpStatusProvider","provide","createHttpStatusSink"],"sources":["../../src/components/ClientOnly.ts","../../src/components/ServerOnly.ts","../../src/composables/useDeferred.ts","../../src/components/Await.ts","../../src/components/Streamed.ts","../../src/components/HttpStatusCode.ts","../../src/components/HttpStatusProvider.ts","../../src/utils/createHttpStatusSink.ts"],"sourcesContent":["import { defineComponent, onMounted, ref } from \"vue\";\n\nexport const ClientOnly = defineComponent({\n name: \"ClientOnly\",\n setup(_, { slots }) {\n const mounted = ref(false);\n\n onMounted(() => {\n mounted.value = true;\n });\n\n return () => (mounted.value ? slots.default?.() : slots.fallback?.());\n },\n});\n\nexport type ClientOnlyProps = InstanceType<typeof ClientOnly>[\"$props\"];\n","import { defineComponent, onMounted, ref } from \"vue\";\n\nexport const ServerOnly = defineComponent({\n name: \"ServerOnly\",\n setup(_, { slots }) {\n const mounted = ref(false);\n\n onMounted(() => {\n mounted.value = true;\n });\n\n return () => (mounted.value ? slots.fallback?.() : slots.default?.());\n },\n});\n\nexport type ServerOnlyProps = InstanceType<typeof ServerOnly>[\"$props\"];\n","import { useRoute } from \"./useRoute\";\n\ninterface DeferredContext {\n ssrDataDeferred?: Record<string, Promise<unknown>>;\n}\n\nconst NEVER_PROMISE = new Promise<never>(() => {\n // Intentionally never resolves — surfaces a forever-pending Suspense boundary\n // when a key is requested that the loader never declared.\n});\n\n/**\n * Read a deferred promise published by `defer({ deferred: { <key>: Promise } })`\n * inside an SSR data loader. Returns the Promise for use inside `async setup()`\n * (Vue's native Suspense pattern) or paired with `<Await name=\"key\">`.\n *\n * ```ts\n * // Vue async setup pattern\n * export default defineComponent({\n * async setup() {\n * const reviews = await useDeferred<Review[]>(\"reviews\");\n * return () => h(\"div\", reviews.map(...));\n * },\n * });\n * ```\n *\n * Returns a forever-pending promise when the key is missing — surfaces\n * loader/consumer key drift as a visible Suspense fallback rather than a\n * silent runtime error.\n */\nexport function useDeferred<T = unknown>(key: string): Promise<T> {\n const { route } = useRoute();\n const context = route.value.context as DeferredContext;\n const deferred = context.ssrDataDeferred;\n\n return (deferred?.[key] ?? NEVER_PROMISE) as Promise<T>;\n}\n","import { defineComponent } from \"vue\";\n\nimport { useDeferred } from \"../composables/useDeferred\";\n\n/**\n * Reads `useDeferred(name)` and hands the resolved value to the `default`\n * scoped slot via Vue's native `async setup()` Suspense pattern. Wrap in\n * `<Streamed>` (or Vue's `<Suspense>`).\n *\n * ```vue-html\n * <Streamed>\n * <Await name=\"reviews\" v-slot=\"{ value }\">\n * <ReviewList :items=\"value\" />\n * </Await>\n * <template #fallback>\n * <Spinner />\n * </template>\n * </Streamed>\n * ```\n *\n * Or with the render function:\n *\n * ```ts\n * h(Await, { name: \"reviews\" }, {\n * default: ({ value }: { value: Review[] }) => h(ReviewList, { items: value }),\n * });\n * ```\n *\n * Implementation: `async setup()` awaits the deferred promise. Vue's\n * `<Suspense>` boundary catches the pending promise and shows the fallback\n * until resolution. Rejection bubbles to the nearest `onErrorCaptured`\n * handler.\n */\nexport const Await = defineComponent({\n name: \"Await\",\n props: {\n /** Deferred key declared in the loader's `defer({ deferred: { <name>: ... } })`. */\n name: { type: String, required: true },\n },\n async setup(props, { slots }) {\n const value = await useDeferred(props.name);\n\n return () => slots.default?.({ value });\n },\n});\n\nexport type AwaitProps = InstanceType<typeof Await>[\"$props\"];\n","import { defineComponent, h, Suspense } from \"vue\";\n\n/**\n * Cross-adapter alias for Vue's native `<Suspense>`. Symmetric naming with\n * the React/Preact/Solid/Svelte/Angular `<Streamed>` components.\n *\n * Slots:\n * - `default` — content (may contain `<Await>` or `async setup()` children).\n * - `fallback` — shown while any descendant suspends.\n *\n * Vue's `<Suspense>` is **blocking** under SSR (no out-of-order placeholder\n * resolution) — render of HTML after `<Streamed>` waits for every\n * `async setup()` inside. This matches Vue 3's stable streaming behaviour\n * (vs React 19 / Solid which support OOO resolution).\n */\nexport const Streamed = defineComponent({\n name: \"Streamed\",\n setup(_, { slots }) {\n return () =>\n h(\n Suspense,\n {},\n {\n default: () => slots.default?.(),\n fallback: () => slots.fallback?.(),\n },\n );\n },\n});\n\nexport type StreamedProps = InstanceType<typeof Streamed>[\"$props\"];\n","import { defineComponent, inject } from \"vue\";\n\nimport { HTTP_STATUS_KEY } from \"../context\";\n\n// Module-scope render function — returns null since the component emits no DOM.\n// Hoisted to satisfy `unicorn/consistent-function-scoping` and to avoid\n// re-creating the closure on every component instantiation.\nconst renderNull = (): null => null;\n\n/**\n * Render-time HTTP status declaration. Mount inside a route component (typical\n * use case: a glob `*` route's NotFound page) when the status is decided by\n * the rendered tree rather than a loader.\n *\n * Writes `code` to the nearest `<HttpStatusProvider>`'s sink during `setup()`\n * and renders nothing. With no provider mounted (the standard client-side\n * case) the component is a silent no-op — same component tree hydrates\n * without touching the DOM or warning about mismatches.\n *\n * Loader-driven errors (`LoaderNotFound` → 404, `LoaderRedirect` → 30x) keep\n * working as before; this component covers render-time decisions only.\n *\n * Last write wins when several `<HttpStatusCode />` instances mount in the\n * same render pass — sink reflects the last component that ran.\n *\n * ```vue-html\n * <HttpStatusProvider :sink=\"sink\">\n * <RouterProvider :router=\"router\">\n * <App />\n * </RouterProvider>\n * </HttpStatusProvider>\n *\n * <!-- inside NotFound.vue -->\n * <HttpStatusCode :code=\"404\" />\n * ```\n *\n * **`renderToWebStream` (streaming SSR):** Vue 3 `<Suspense>` is\n * chunked-blocking — Vue waits for every `async setup()` inside a boundary\n * before emitting the chunks past it. So in practice `<HttpStatusCode />`\n * inside a `<Suspense>` boundary still writes to the sink before the\n * response headers flush. Still, prefer mounting in the shell to avoid\n * coupling the contract to that particular Vue 3 streaming behaviour. With\n * `renderToString` there is no ordering concern at all.\n *\n * **Hydration symmetry:** `<HttpStatusProvider>` wraps a render slot, so\n * Vue emits a fragment marker pair (`<!--[-->` / `<!--]-->`) around its\n * children server-side. Mount the same `<HttpStatusProvider>` on the\n * client (with a throwaway sink) to keep the marker count balanced — see\n * the `ssr/` example's `entry-client.ts`. Otherwise hydration logs\n * \"Hydration completed but contains mismatches\".\n *\n * **Valid `code` range:** Node's `res.end()` throws `Invalid status code`\n * on `NaN`, `0`, negative values, or values `> 999` — this surfaces as a\n * 5xx / dropped connection, not silent corruption. Pass a real HTTP status\n * integer (commonly 4xx/5xx; 100-999 is what Node accepts).\n */\nexport const HttpStatusCode = defineComponent({\n name: \"HttpStatusCode\",\n props: {\n /** HTTP status to apply to the response. Common values: 404, 410, 451, 503. */\n code: { type: Number, required: true },\n },\n setup(props) {\n const sink = inject(HTTP_STATUS_KEY, null);\n\n if (sink) {\n // Dev-only validation: Node's `res.end()` throws `Invalid status code`\n // on NaN / 0 / negative / non-integer / >999. Surface the bad value at\n // the source so the consumer can fix the routing logic, instead of\n // waiting for the server to crash mid-response. Production builds (Vite,\n // esbuild, tsdown all replace `process.env.NODE_ENV !== \"production\"`\n // with `false`) strip the check.\n if (\n process.env.NODE_ENV !== \"production\" &&\n (!Number.isInteger(props.code) || props.code < 100 || props.code > 999)\n ) {\n console.error(\n `[real-router] <HttpStatusCode :code=\"${String(props.code)}\" /> received an invalid HTTP status code. Node's res.end() rejects values that are not an integer in [100, 999] — pass a real HTTP status (commonly 4xx/5xx).`,\n );\n }\n\n sink.code = props.code;\n }\n\n return renderNull;\n },\n});\n\nexport type HttpStatusCodeProps = InstanceType<typeof HttpStatusCode>[\"$props\"];\n","import { defineComponent, provide } from \"vue\";\n\nimport { HTTP_STATUS_KEY } from \"../context\";\n\nimport type { HttpStatusSink } from \"../utils/createHttpStatusSink\";\nimport type { PropType } from \"vue\";\n\nexport const HttpStatusProvider = defineComponent({\n name: \"HttpStatusProvider\",\n props: {\n sink: { type: Object as PropType<HttpStatusSink>, required: true },\n },\n setup(props, { slots }) {\n provide(HTTP_STATUS_KEY, props.sink);\n\n return () => slots.default?.();\n },\n});\n\nexport type HttpStatusProviderProps = InstanceType<\n typeof HttpStatusProvider\n>[\"$props\"];\n","/**\n * Render-scoped HTTP status sink. Created per request on the server, passed to\n * `<HttpStatusProvider :sink=\"...\">`, and read after `renderToString` /\n * `renderToWebStream` to apply the value to the HTTP response.\n *\n * Last write wins: if the rendered tree mounts more than one\n * `<HttpStatusCode />`, the value reflects the last component that ran during\n * the render pass.\n *\n * No-op on the client — `<HttpStatusCode />` reads the optional injected sink\n * and skips the write when no provider is mounted, so the same component tree\n * can be hydrated without changing behaviour.\n *\n * Constraints:\n * - **Per-request only.** Don't share a sink across requests; the rendered\n * tree mutates `code` in place. Module-level singletons leak status\n * between concurrent requests.\n * - **Don't `Object.freeze` the sink.** The component writes to `.code`;\n * freezing makes the assignment throw under ESM strict mode.\n * - **Hydration symmetry:** mount `<HttpStatusProvider>` on both server and\n * client (with a throwaway client sink). Vue emits `<!--[-->` / `<!--]-->`\n * fragment markers around the provider's slot; an extra provider on one\n * side trips Vue with \"Hydration completed but contains mismatches\".\n */\nexport interface HttpStatusSink {\n code: number | undefined;\n}\n\nexport function createHttpStatusSink(): HttpStatusSink {\n return { code: undefined };\n}\n"],"mappings":"0JAEA,MAAaC,EAAaC,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAMC,EAAUC,EAAI,EAAK,EAMzB,OAJAC,MAAgB,CACd,EAAQ,MAAQ,EAClB,CAAC,MAEaF,EAAQ,MAAQG,EAAM,UAAU,EAAIA,EAAM,WAAW,CACrE,CACF,CAAC,ECXYC,EAAaL,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAMC,EAAUC,EAAI,EAAK,EAMzB,OAJAC,MAAgB,CACd,EAAQ,MAAQ,EAClB,CAAC,MAEaF,EAAQ,MAAQG,EAAM,WAAW,EAAIA,EAAM,UAAU,CACrE,CACF,CAAC,ECPKE,EAAgB,IAAI,YAAqB,CAG/C,CAAC,EAqBD,SAAgBC,EAAyB,EAAyB,CAChE,GAAM,CAAE,SAAUC,E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ref","onMounted","slots","ServerOnly","NEVER_PROMISE","useDeferred","useRoute","route","key","Await","value","props","Streamed","h","Suspense","renderNull","HttpStatusCode","sink","inject","HttpStatusProvider","provide","createHttpStatusSink"],"sources":["../../src/components/ClientOnly.ts","../../src/components/ServerOnly.ts","../../src/composables/useDeferred.ts","../../src/components/Await.ts","../../src/components/Streamed.ts","../../src/components/HttpStatusCode.ts","../../src/components/HttpStatusProvider.ts","../../src/utils/createHttpStatusSink.ts"],"sourcesContent":["import { defineComponent, onMounted, ref } from \"vue\";\n\nexport const ClientOnly = defineComponent({\n name: \"ClientOnly\",\n setup(_, { slots }) {\n const mounted = ref(false);\n\n onMounted(() => {\n mounted.value = true;\n });\n\n return () => (mounted.value ? slots.default?.() : slots.fallback?.());\n },\n});\n\nexport type ClientOnlyProps = InstanceType<typeof ClientOnly>[\"$props\"];\n","import { defineComponent, onMounted, ref } from \"vue\";\n\nexport const ServerOnly = defineComponent({\n name: \"ServerOnly\",\n setup(_, { slots }) {\n const mounted = ref(false);\n\n onMounted(() => {\n mounted.value = true;\n });\n\n return () => (mounted.value ? slots.fallback?.() : slots.default?.());\n },\n});\n\nexport type ServerOnlyProps = InstanceType<typeof ServerOnly>[\"$props\"];\n","import { useRoute } from \"./useRoute\";\n\ninterface DeferredContext {\n ssrDataDeferred?: Record<string, Promise<unknown>>;\n}\n\nconst NEVER_PROMISE = new Promise<never>(() => {\n // Intentionally never resolves — surfaces a forever-pending Suspense boundary\n // when a key is requested that the loader never declared.\n});\n\n/**\n * Read a deferred promise published by `defer({ deferred: { <key>: Promise } })`\n * inside an SSR data loader. Returns the Promise for use inside `async setup()`\n * (Vue's native Suspense pattern) or paired with `<Await name=\"key\">`.\n *\n * ```ts\n * // Vue async setup pattern\n * export default defineComponent({\n * async setup() {\n * const reviews = await useDeferred<Review[]>(\"reviews\");\n * return () => h(\"div\", reviews.map(...));\n * },\n * });\n * ```\n *\n * Returns a forever-pending promise when the key is missing — surfaces\n * loader/consumer key drift as a visible Suspense fallback rather than a\n * silent runtime error.\n */\nexport function useDeferred<T = unknown>(key: string): Promise<T> {\n const { route } = useRoute();\n const context = route.value.context as DeferredContext;\n const deferred = context.ssrDataDeferred;\n\n return (deferred?.[key] ?? NEVER_PROMISE) as Promise<T>;\n}\n","import { defineComponent } from \"vue\";\n\nimport { useDeferred } from \"../composables/useDeferred\";\n\n/**\n * Reads `useDeferred(name)` and hands the resolved value to the `default`\n * scoped slot via Vue's native `async setup()` Suspense pattern. Wrap in\n * `<Streamed>` (or Vue's `<Suspense>`).\n *\n * ```vue-html\n * <Streamed>\n * <Await name=\"reviews\" v-slot=\"{ value }\">\n * <ReviewList :items=\"value\" />\n * </Await>\n * <template #fallback>\n * <Spinner />\n * </template>\n * </Streamed>\n * ```\n *\n * Or with the render function:\n *\n * ```ts\n * h(Await, { name: \"reviews\" }, {\n * default: ({ value }: { value: Review[] }) => h(ReviewList, { items: value }),\n * });\n * ```\n *\n * Implementation: `async setup()` awaits the deferred promise. Vue's\n * `<Suspense>` boundary catches the pending promise and shows the fallback\n * until resolution. Rejection bubbles to the nearest `onErrorCaptured`\n * handler.\n */\nexport const Await = defineComponent({\n name: \"Await\",\n props: {\n /** Deferred key declared in the loader's `defer({ deferred: { <name>: ... } })`. */\n name: { type: String, required: true },\n },\n async setup(props, { slots }) {\n const value = await useDeferred(props.name);\n\n return () => slots.default?.({ value });\n },\n});\n\nexport type AwaitProps = InstanceType<typeof Await>[\"$props\"];\n","import { defineComponent, h, Suspense } from \"vue\";\n\n/**\n * Cross-adapter alias for Vue's native `<Suspense>`. Symmetric naming with\n * the React/Preact/Solid/Svelte/Angular `<Streamed>` components.\n *\n * Slots:\n * - `default` — content (may contain `<Await>` or `async setup()` children).\n * - `fallback` — shown while any descendant suspends.\n *\n * Vue's `<Suspense>` is **blocking** under SSR (no out-of-order placeholder\n * resolution) — render of HTML after `<Streamed>` waits for every\n * `async setup()` inside. This matches Vue 3's stable streaming behaviour\n * (vs React 19 / Solid which support OOO resolution).\n */\nexport const Streamed = defineComponent({\n name: \"Streamed\",\n setup(_, { slots }) {\n return () =>\n h(\n Suspense,\n {},\n {\n default: () => slots.default?.(),\n fallback: () => slots.fallback?.(),\n },\n );\n },\n});\n\nexport type StreamedProps = InstanceType<typeof Streamed>[\"$props\"];\n","import { defineComponent, inject } from \"vue\";\n\nimport { HTTP_STATUS_KEY } from \"../context\";\n\n// Module-scope render function — returns null since the component emits no DOM.\n// Hoisted to satisfy `unicorn/consistent-function-scoping` and to avoid\n// re-creating the closure on every component instantiation.\nconst renderNull = (): null => null;\n\n/**\n * Render-time HTTP status declaration. Mount inside a route component (typical\n * use case: a glob `*` route's NotFound page) when the status is decided by\n * the rendered tree rather than a loader.\n *\n * Writes `code` to the nearest `<HttpStatusProvider>`'s sink during `setup()`\n * and renders nothing. With no provider mounted (the standard client-side\n * case) the component is a silent no-op — same component tree hydrates\n * without touching the DOM or warning about mismatches.\n *\n * Loader-driven errors (`LoaderNotFound` → 404, `LoaderRedirect` → 30x) keep\n * working as before; this component covers render-time decisions only.\n *\n * Last write wins when several `<HttpStatusCode />` instances mount in the\n * same render pass — sink reflects the last component that ran.\n *\n * ```vue-html\n * <HttpStatusProvider :sink=\"sink\">\n * <RouterProvider :router=\"router\">\n * <App />\n * </RouterProvider>\n * </HttpStatusProvider>\n *\n * <!-- inside NotFound.vue -->\n * <HttpStatusCode :code=\"404\" />\n * ```\n *\n * **`renderToWebStream` (streaming SSR):** Vue 3 `<Suspense>` is\n * chunked-blocking — Vue waits for every `async setup()` inside a boundary\n * before emitting the chunks past it. So in practice `<HttpStatusCode />`\n * inside a `<Suspense>` boundary still writes to the sink before the\n * response headers flush. Still, prefer mounting in the shell to avoid\n * coupling the contract to that particular Vue 3 streaming behaviour. With\n * `renderToString` there is no ordering concern at all.\n *\n * **Hydration symmetry:** `<HttpStatusProvider>` wraps a render slot, so\n * Vue emits a fragment marker pair (`<!--[-->` / `<!--]-->`) around its\n * children server-side. Mount the same `<HttpStatusProvider>` on the\n * client (with a throwaway sink) to keep the marker count balanced — see\n * the `ssr/` example's `entry-client.ts`. Otherwise hydration logs\n * \"Hydration completed but contains mismatches\".\n *\n * **Valid `code` range:** Node's `res.end()` throws `Invalid status code`\n * on `NaN`, `0`, negative values, or values `> 999` — this surfaces as a\n * 5xx / dropped connection, not silent corruption. Pass a real HTTP status\n * integer (commonly 4xx/5xx; 100-999 is what Node accepts).\n */\nexport const HttpStatusCode = defineComponent({\n name: \"HttpStatusCode\",\n props: {\n /** HTTP status to apply to the response. Common values: 404, 410, 451, 503. */\n code: { type: Number, required: true },\n },\n setup(props) {\n const sink = inject(HTTP_STATUS_KEY, null);\n\n if (sink) {\n // Dev-only validation: Node's `res.end()` throws `Invalid status code`\n // on NaN / 0 / negative / non-integer / >999. Surface the bad value at\n // the source so the consumer can fix the routing logic, instead of\n // waiting for the server to crash mid-response. Production builds (Vite,\n // esbuild, tsdown all replace `process.env.NODE_ENV !== \"production\"`\n // with `false`) strip the check.\n if (\n process.env.NODE_ENV !== \"production\" &&\n (!Number.isInteger(props.code) || props.code < 100 || props.code > 999)\n ) {\n console.error(\n `[real-router] <HttpStatusCode :code=\"${String(props.code)}\" /> received an invalid HTTP status code. Node's res.end() rejects values that are not an integer in [100, 999] — pass a real HTTP status (commonly 4xx/5xx).`,\n );\n }\n\n sink.code = props.code;\n }\n\n return renderNull;\n },\n});\n\nexport type HttpStatusCodeProps = InstanceType<typeof HttpStatusCode>[\"$props\"];\n","import { defineComponent, provide } from \"vue\";\n\nimport { HTTP_STATUS_KEY } from \"../context\";\n\nimport type { HttpStatusSink } from \"../utils/createHttpStatusSink\";\nimport type { PropType } from \"vue\";\n\nexport const HttpStatusProvider = defineComponent({\n name: \"HttpStatusProvider\",\n props: {\n sink: { type: Object as PropType<HttpStatusSink>, required: true },\n },\n setup(props, { slots }) {\n provide(HTTP_STATUS_KEY, props.sink);\n\n return () => slots.default?.();\n },\n});\n\nexport type HttpStatusProviderProps = InstanceType<\n typeof HttpStatusProvider\n>[\"$props\"];\n","/**\n * Render-scoped HTTP status sink. Created per request on the server, passed to\n * `<HttpStatusProvider :sink=\"...\">`, and read after `renderToString` /\n * `renderToWebStream` to apply the value to the HTTP response.\n *\n * Last write wins: if the rendered tree mounts more than one\n * `<HttpStatusCode />`, the value reflects the last component that ran during\n * the render pass.\n *\n * No-op on the client — `<HttpStatusCode />` reads the optional injected sink\n * and skips the write when no provider is mounted, so the same component tree\n * can be hydrated without changing behaviour.\n *\n * Constraints:\n * - **Per-request only.** Don't share a sink across requests; the rendered\n * tree mutates `code` in place. Module-level singletons leak status\n * between concurrent requests.\n * - **Don't `Object.freeze` the sink.** The component writes to `.code`;\n * freezing makes the assignment throw under ESM strict mode.\n * - **Hydration symmetry:** mount `<HttpStatusProvider>` on both server and\n * client (with a throwaway client sink). Vue emits `<!--[-->` / `<!--]-->`\n * fragment markers around the provider's slot; an extra provider on one\n * side trips Vue with \"Hydration completed but contains mismatches\".\n */\nexport interface HttpStatusSink {\n code: number | undefined;\n}\n\nexport function createHttpStatusSink(): HttpStatusSink {\n return { code: undefined };\n}\n"],"mappings":"A,0JAEA,MAAaC,EAAaC,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAMC,EAAUC,EAAI,EAAK,EAMzB,OAJAC,MAAgB,CACd,EAAQ,MAAQ,EAClB,CAAC,MAEaF,EAAQ,MAAQG,EAAM,UAAU,EAAIA,EAAM,WAAW,CACrE,CACF,CAAC,ECXYC,EAAaL,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAMC,EAAUC,EAAI,EAAK,EAMzB,OAJAC,MAAgB,CACd,EAAQ,MAAQ,EAClB,CAAC,MAEaF,EAAQ,MAAQG,EAAM,WAAW,EAAIA,EAAM,UAAU,CACrE,CACF,CAAC,ECPKE,EAAgB,IAAI,YAAqB,CAG/C,CAAC,EAqBD,SAAgBC,EAAyB,EAAyB,CAChE,GAAM,CAAE,SAAUC,EAAS,EAI3B,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","HTTP_STATUS_KEY","useRoute","routeContext","inject"],"sources":["../../src/context.ts","../../src/composables/useRoute.ts"],"sourcesContent":["import type { RouteContext as RouteContextType } from \"./types\";\nimport type { HttpStatusSink } from \"./utils/createHttpStatusSink\";\nimport type { Router, Navigator } from \"@real-router/core\";\nimport type { InjectionKey } from \"vue\";\n\nexport const RouterKey: InjectionKey<Router> = Symbol(\"RouterKey\");\n\nexport const NavigatorKey: InjectionKey<Navigator> = Symbol(\"NavigatorKey\");\n\nexport const RouteKey: InjectionKey<RouteContextType> = Symbol(\"RouteKey\");\n\nexport const HTTP_STATUS_KEY: InjectionKey<HttpStatusSink> =\n Symbol(\"HttpStatusSink\");\n","import { inject } from \"vue\";\n\nimport { RouteKey } from \"../context\";\n\nimport type { RouteContext } from \"../types\";\nimport type { Params, State } from \"@real-router/core\";\nimport type { Ref } from \"vue\";\n\n/**\n * Return shape for `useRoute()` — `RouteContext<P>` with `route` narrowed\n * to the non-nullable variant. The composable throws when `route.value`\n * would be `undefined`, so consumers can read `.value.params.x` without a\n * nullable guard. Extracted from inline duplication at two call sites.\n */\nexport type UseRouteReturn<P extends Params = Params> = Omit<\n RouteContext<P>,\n \"route\"\n> & { route: Readonly<Ref<State<P>>> };\n\nexport const useRoute = <P extends Params = Params>(): UseRouteReturn<P> => {\n const routeContext = inject(RouteKey);\n\n if (!routeContext) {\n throw new Error(\"useRoute must be used within a RouterProvider\");\n }\n\n if (!routeContext.route.value) {\n throw new Error(\n \"useRoute called with no active route. Did you forget to await router.start() before rendering, or is the router stopped/disposed?\",\n );\n }\n\n return routeContext as UseRouteReturn<P>;\n};\n"],"mappings":"6BAKA,MAAaA,EAAkC,OAAO,WAAW,EAEpDC,EAAwC,OAAO,cAAc,EAE7DC,EAA2C,OAAO,UAAU,EAE5DC,EACX,OAAO,gBAAgB,ECOZC,MAA+D,CAC1E,IAAMC,EAAeC,EAAOJ,CAAQ,EAEpC,GAAI,CAACG,EACH,MAAU,MAAM,+CAA+C,EAGjE,GAAI,CAACA,EAAa,MAAM,MACtB,MAAU,MACR,mIACF,EAGF,OAAOA,CACT"}
1
+ {"version":3,"file":"useRoute-BBfRYSpV.mjs","names":["RouterKey","NavigatorKey","RouteKey","HTTP_STATUS_KEY","useRoute","routeContext","inject"],"sources":["../../src/context.ts","../../src/composables/useRoute.ts"],"sourcesContent":["import type { RouteContext as RouteContextType } from \"./types\";\nimport type { HttpStatusSink } from \"./utils/createHttpStatusSink\";\nimport type { Router, Navigator } from \"@real-router/core\";\nimport type { InjectionKey } from \"vue\";\n\nexport const RouterKey: InjectionKey<Router> = Symbol(\"RouterKey\");\n\nexport const NavigatorKey: InjectionKey<Navigator> = Symbol(\"NavigatorKey\");\n\nexport const RouteKey: InjectionKey<RouteContextType> = Symbol(\"RouteKey\");\n\nexport const HTTP_STATUS_KEY: InjectionKey<HttpStatusSink> =\n Symbol(\"HttpStatusSink\");\n","import { inject } from \"vue\";\n\nimport { RouteKey } from \"../context\";\n\nimport type { RouteContext } from \"../types\";\nimport type { Params, State } from \"@real-router/core\";\nimport type { Ref } from \"vue\";\n\n/**\n * Return shape for `useRoute()` — `RouteContext<P>` with `route` narrowed\n * to the non-nullable variant. The composable throws when `route.value`\n * would be `undefined`, so consumers can read `.value.params.x` without a\n * nullable guard. Extracted from inline duplication at two call sites.\n */\nexport type UseRouteReturn<P extends Params = Params> = Omit<\n RouteContext<P>,\n \"route\"\n> & { route: Readonly<Ref<State<P>>> };\n\nexport const useRoute = <P extends Params = Params>(): UseRouteReturn<P> => {\n const routeContext = inject(RouteKey);\n\n if (!routeContext) {\n throw new Error(\"useRoute must be used within a RouterProvider\");\n }\n\n if (!routeContext.route.value) {\n throw new Error(\n \"useRoute called with no active route. Did you forget to await router.start() before rendering, or is the router stopped/disposed?\",\n );\n }\n\n return routeContext as UseRouteReturn<P>;\n};\n"],"mappings":"A,6BAKA,MAAaA,EAAkC,OAAO,WAAW,EAEpDC,EAAwC,OAAO,cAAc,EAE7DC,EAA2C,OAAO,UAAU,EAE5DC,EACX,OAAO,gBAAgB,ECOZC,MAA+D,CAC1E,IAAMC,EAAeC,EAAOJ,CAAQ,EAEpC,GAAI,CAACG,EACH,MAAU,MAAM,+CAA+C,EAGjE,GAAI,CAACA,EAAa,MAAM,MACtB,MAAU,MACR,mIACF,EAGF,OAAOA,CACT,E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/vue",
3
- "version": "0.25.3",
3
+ "version": "0.25.5",
4
4
  "type": "commonjs",
5
5
  "description": "Vue 3 integration for Real-Router",
6
6
  "main": "./dist/cjs/index.js",
@@ -69,14 +69,14 @@
69
69
  "@real-router/sources": "^0.15.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@real-router/browser-plugin": "^0.26.2",
73
- "@real-router/core": "^0.148.1",
72
+ "@real-router/browser-plugin": "^0.27.0",
73
+ "@real-router/core": "^0.154.0",
74
74
  "@testing-library/jest-dom": "~7.0.1",
75
75
  "@vue/test-utils": "2.5.1",
76
76
  "vue": "~3.5.39"
77
77
  },
78
78
  "peerDependencies": {
79
- "@real-router/core": ">=0.148.1",
79
+ "@real-router/core": ">=0.154.0",
80
80
  "vue": ">=3.3.0"
81
81
  },
82
82
  "scripts": {