@real-router/vue 0.13.0 → 0.15.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/README.md +29 -3
- package/dist/cjs/createHttpStatusSink-XDu5aGhc.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +95 -30
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/ssr.d.ts +17 -18
- package/dist/cjs/ssr.d.ts.map +1 -1
- package/dist/cjs/ssr.js.map +1 -1
- package/dist/cjs/useRoute-BT3SkdOc.js.map +1 -1
- package/dist/esm/createHttpStatusSink-DduXvbGr.d.mts.map +1 -1
- package/dist/esm/index.d.mts +95 -30
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/ssr.d.mts +17 -18
- package/dist/esm/ssr.d.mts.map +1 -1
- package/dist/esm/ssr.mjs.map +1 -1
- package/dist/esm/useRoute-2ocUdDHc.mjs.map +1 -1
- package/package.json +4 -4
- package/src/RouterProvider.ts +28 -1
- package/src/components/Link.ts +1 -1
package/dist/esm/ssr.d.mts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { n as createHttpStatusSink, t as HttpStatusSink } from "./createHttpStatusSink-DduXvbGr.mjs";
|
|
2
|
-
import * as _$vue from "vue";
|
|
3
2
|
import { PropType } from "vue";
|
|
4
3
|
|
|
5
4
|
//#region src/components/ClientOnly.d.ts
|
|
6
|
-
declare const ClientOnly:
|
|
5
|
+
declare const ClientOnly: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
7
6
|
[key: string]: any;
|
|
8
|
-
}>[] | undefined, {}, {}, {},
|
|
7
|
+
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
9
8
|
type ClientOnlyProps = InstanceType<typeof ClientOnly>["$props"];
|
|
10
9
|
//#endregion
|
|
11
10
|
//#region src/components/ServerOnly.d.ts
|
|
12
|
-
declare const ServerOnly:
|
|
11
|
+
declare const ServerOnly: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
13
12
|
[key: string]: any;
|
|
14
|
-
}>[] | undefined, {}, {}, {},
|
|
13
|
+
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
15
14
|
type ServerOnlyProps = InstanceType<typeof ServerOnly>["$props"];
|
|
16
15
|
//#endregion
|
|
17
16
|
//#region src/components/Await.d.ts
|
|
@@ -44,19 +43,19 @@ type ServerOnlyProps = InstanceType<typeof ServerOnly>["$props"];
|
|
|
44
43
|
* until resolution. Rejection bubbles to the nearest `onErrorCaptured`
|
|
45
44
|
* handler.
|
|
46
45
|
*/
|
|
47
|
-
declare const Await:
|
|
46
|
+
declare const Await: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
48
47
|
/** Deferred key declared in the loader's `defer({ deferred: { <name>: ... } })`. */name: {
|
|
49
48
|
type: StringConstructor;
|
|
50
49
|
required: true;
|
|
51
50
|
};
|
|
52
|
-
}>, () =>
|
|
51
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
53
52
|
[key: string]: any;
|
|
54
|
-
}>[] | undefined, {}, {}, {},
|
|
53
|
+
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
55
54
|
/** Deferred key declared in the loader's `defer({ deferred: { <name>: ... } })`. */name: {
|
|
56
55
|
type: StringConstructor;
|
|
57
56
|
required: true;
|
|
58
57
|
};
|
|
59
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
58
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
60
59
|
type AwaitProps = InstanceType<typeof Await>["$props"];
|
|
61
60
|
//#endregion
|
|
62
61
|
//#region src/components/Streamed.d.ts
|
|
@@ -73,9 +72,9 @@ type AwaitProps = InstanceType<typeof Await>["$props"];
|
|
|
73
72
|
* `async setup()` inside. This matches Vue 3's stable streaming behaviour
|
|
74
73
|
* (vs React 19 / Solid which support OOO resolution).
|
|
75
74
|
*/
|
|
76
|
-
declare const Streamed:
|
|
75
|
+
declare const Streamed: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
77
76
|
[key: string]: any;
|
|
78
|
-
}>, {}, {}, {},
|
|
77
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
79
78
|
type StreamedProps = InstanceType<typeof Streamed>["$props"];
|
|
80
79
|
//#endregion
|
|
81
80
|
//#region src/components/HttpStatusCode.d.ts
|
|
@@ -126,33 +125,33 @@ type StreamedProps = InstanceType<typeof Streamed>["$props"];
|
|
|
126
125
|
* 5xx / dropped connection, not silent corruption. Pass a real HTTP status
|
|
127
126
|
* integer (commonly 4xx/5xx; 100-999 is what Node accepts).
|
|
128
127
|
*/
|
|
129
|
-
declare const HttpStatusCode:
|
|
128
|
+
declare const HttpStatusCode: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
130
129
|
/** HTTP status to apply to the response. Common values: 404, 410, 451, 503. */code: {
|
|
131
130
|
type: NumberConstructor;
|
|
132
131
|
required: true;
|
|
133
132
|
};
|
|
134
|
-
}>, () => null, {}, {}, {},
|
|
133
|
+
}>, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
135
134
|
/** HTTP status to apply to the response. Common values: 404, 410, 451, 503. */code: {
|
|
136
135
|
type: NumberConstructor;
|
|
137
136
|
required: true;
|
|
138
137
|
};
|
|
139
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
138
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
140
139
|
type HttpStatusCodeProps = InstanceType<typeof HttpStatusCode>["$props"];
|
|
141
140
|
//#endregion
|
|
142
141
|
//#region src/components/HttpStatusProvider.d.ts
|
|
143
|
-
declare const HttpStatusProvider:
|
|
142
|
+
declare const HttpStatusProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
144
143
|
sink: {
|
|
145
144
|
type: PropType<HttpStatusSink>;
|
|
146
145
|
required: true;
|
|
147
146
|
};
|
|
148
|
-
}>, () =>
|
|
147
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
149
148
|
[key: string]: any;
|
|
150
|
-
}>[] | undefined, {}, {}, {},
|
|
149
|
+
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
151
150
|
sink: {
|
|
152
151
|
type: PropType<HttpStatusSink>;
|
|
153
152
|
required: true;
|
|
154
153
|
};
|
|
155
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
154
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
156
155
|
type HttpStatusProviderProps = InstanceType<typeof HttpStatusProvider>["$props"];
|
|
157
156
|
//#endregion
|
|
158
157
|
//#region src/composables/useDeferred.d.ts
|
package/dist/esm/ssr.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.d.mts","names":[],"sources":["../../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":"
|
|
1
|
+
{"version":3,"file":"ssr.d.mts","names":[],"sources":["../../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":";;;;cAEa,UAAA,gBAAU,eAAA,yBAAA,KAAA,eAAA,YAAA,gBAAA,eAAA;EAAA;+IAWrB,QAAA,OAAA,QAAA;KAEU,eAAA,GAAkB,YAAY,QAAQ,UAAA;;;cCbrC,UAAA,gBAAU,eAAA,yBAAA,KAAA,eAAA,YAAA,gBAAA,eAAA;EAAA;+IAWrB,QAAA,OAAA,QAAA;KAEU,eAAA,GAAkB,YAAY,QAAQ,UAAA;;;;;;;ADblD;;;;;;;;;;;;;;;;;AAaA;;;;AAA4D;;;;cEkB/C,KAAA,gBAAK,eAAA,eAAA,gBAAA;EDpBhB;;;;;;;;;;;;KCiCU,UAAA,GAAa,YAAY,QAAQ,KAAA;;;;;;;AF5C7C;;;;;;;;;cGaa,QAAA,gBAAQ,eAAA,yBAAA,KAAA,eAAA,YAAA,gBAAA,eAAA;EAAA;iIAanB,QAAA,OAAA,QAAA;KAEU,aAAA,GAAgB,YAAY,QAAQ,QAAA;;;;;;;AH5BhD;;;;;;;;;;;;;;;;;AAaA;;;;AAA4D;;;;ACb5D;;;;;;;;;;;;;;;;;AAaA;cGyCa,cAAA,gBAAc,eAAA,eAAA,gBAAA;;;;;0CAjDA,qBAAA,gBAAA,qBAAA,4BAAA,WAAA,EAAA,QAAA,eAAA,gBAAA;EF0Bd;;;;;KEwCD,mBAAA,GAAsB,YAAY,QAAQ,cAAA;;;cClEzC,kBAAA,gBAAkB,eAAA,eAAA,gBAAA;;UAGH,QAAA,CAAS,cAAA;;;;;;;UAAT,QAAA,CAAS,cAAA;;;;KASzB,uBAAA,GAA0B,YAAY,QACzC,kBAAA;;;;;;;ALlBT;;;;;;;;;;;;;;;iBM4BgB,WAAA,aAAA,CAAyB,GAAA,WAAc,OAAO,CAAC,CAAA"}
|
package/dist/esm/ssr.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.mjs","names":[],"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 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,MAAa,EAAa,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAM,EAAU,EAAI,GAAM,CAM1B,OAJA,MAAgB,CACd,EAAQ,MAAQ,IAChB,KAEY,EAAQ,MAAQ,EAAM,WAAW,CAAG,EAAM,YAAY,EAEvE,CAAC,CCXW,EAAa,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAM,EAAU,EAAI,GAAM,CAM1B,OAJA,MAAgB,CACd,EAAQ,MAAQ,IAChB,KAEY,EAAQ,MAAQ,EAAM,YAAY,CAAG,EAAM,WAAW,EAEvE,CAAC,CCPI,EAAgB,IAAI,YAAqB,GAG7C,CAqBF,SAAgB,EAAyB,EAAyB,CAChE,GAAM,CAAE,SAAU,GAAU,CAI5B,OAHgB,EAAM,MAAM,QACH,kBAEN,IAAQ,ECF7B,MAAa,EAAQ,EAAgB,CACnC,KAAM,QACN,MAAO,CAEL,KAAM,CAAE,KAAM,OAAQ,SAAU,GAAM,CACvC,CACD,MAAM,MAAM,EAAO,CAAE,SAAS,CAC5B,IAAM,EAAQ,MAAM,EAAY,EAAM,KAAK,CAE3C,UAAa,EAAM,UAAU,CAAE,QAAO,CAAC,EAE1C,CAAC,CC7BW,EAAW,EAAgB,CACtC,KAAM,WACN,MAAM,EAAG,CAAE,SAAS,CAClB,UACE,EACE,EACA,EAAE,CACF,CACE,YAAe,EAAM,WAAW,CAChC,aAAgB,EAAM,YAAY,CACnC,CACF,EAEN,CAAC,CCrBI,MAAyB,KAiDlB,EAAiB,EAAgB,CAC5C,KAAM,iBACN,MAAO,CAEL,KAAM,CAAE,KAAM,OAAQ,SAAU,GAAM,CACvC,CACD,MAAM,EAAO,CACX,IAAM,EAAO,EAAO,EAAiB,KAAK,CAM1C,OAJI,IACF,EAAK,KAAO,EAAM,MAGb,GAEV,CAAC,CChEW,EAAqB,EAAgB,CAChD,KAAM,qBACN,MAAO,CACL,KAAM,CAAE,KAAM,OAAoC,SAAU,GAAM,CACnE,CACD,MAAM,EAAO,CAAE,SAAS,CAGtB,OAFA,EAAQ,EAAiB,EAAM,KAAK,KAEvB,EAAM,WAAW,EAEjC,CAAC,CCWF,SAAgB,GAAuC,CACrD,MAAO,CAAE,KAAM,IAAA,GAAW"}
|
|
1
|
+
{"version":3,"file":"ssr.mjs","names":[],"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 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,MAAa,EAAa,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAM,EAAU,EAAI,EAAK,EAMzB,OAJA,MAAgB,CACd,EAAQ,MAAQ,EAClB,CAAC,MAEa,EAAQ,MAAQ,EAAM,UAAU,EAAI,EAAM,WAAW,CACrE,CACF,CAAC,ECXY,EAAa,EAAgB,CACxC,KAAM,aACN,MAAM,EAAG,CAAE,SAAS,CAClB,IAAM,EAAU,EAAI,EAAK,EAMzB,OAJA,MAAgB,CACd,EAAQ,MAAQ,EAClB,CAAC,MAEa,EAAQ,MAAQ,EAAM,WAAW,EAAI,EAAM,UAAU,CACrE,CACF,CAAC,ECPK,EAAgB,IAAI,YAAqB,CAG/C,CAAC,EAqBD,SAAgB,EAAyB,EAAyB,CAChE,GAAM,CAAE,SAAU,EAAS,EAI3B,OAHgB,EAAM,MAAM,QACH,kBAEN,IAAQ,CAC7B,CCHA,MAAa,EAAQ,EAAgB,CACnC,KAAM,QACN,MAAO,CAEL,KAAM,CAAE,KAAM,OAAQ,SAAU,EAAK,CACvC,EACA,MAAM,MAAM,EAAO,CAAE,SAAS,CAC5B,IAAM,EAAQ,MAAM,EAAY,EAAM,IAAI,EAE1C,UAAa,EAAM,UAAU,CAAE,OAAM,CAAC,CACxC,CACF,CAAC,EC7BY,EAAW,EAAgB,CACtC,KAAM,WACN,MAAM,EAAG,CAAE,SAAS,CAClB,UACE,EACE,EACA,CAAC,EACD,CACE,YAAe,EAAM,UAAU,EAC/B,aAAgB,EAAM,WAAW,CACnC,CACF,CACJ,CACF,CAAC,ECrBK,MAAyB,KAiDlB,EAAiB,EAAgB,CAC5C,KAAM,iBACN,MAAO,CAEL,KAAM,CAAE,KAAM,OAAQ,SAAU,EAAK,CACvC,EACA,MAAM,EAAO,CACX,IAAM,EAAO,EAAO,EAAiB,IAAI,EAMzC,OAJI,IACF,EAAK,KAAO,EAAM,MAGb,CACT,CACF,CAAC,EChEY,EAAqB,EAAgB,CAChD,KAAM,qBACN,MAAO,CACL,KAAM,CAAE,KAAM,OAAoC,SAAU,EAAK,CACnE,EACA,MAAM,EAAO,CAAE,SAAS,CAGtB,OAFA,EAAQ,EAAiB,EAAM,IAAI,MAEtB,EAAM,UAAU,CAC/B,CACF,CAAC,ECWD,SAAgB,GAAuC,CACrD,MAAO,CAAE,KAAM,IAAA,EAAU,CAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRoute-2ocUdDHc.mjs","names":[],"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,MAAa,EAAkC,OAAO,
|
|
1
|
+
{"version":3,"file":"useRoute-2ocUdDHc.mjs","names":[],"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,MAAa,EAAkC,OAAO,WAAW,EAEpD,EAAwC,OAAO,cAAc,EAE7D,EAA2C,OAAO,UAAU,EAE5D,EACX,OAAO,gBAAgB,ECOZ,MAA+D,CAC1E,IAAM,EAAe,EAAO,CAAQ,EAEpC,GAAI,CAAC,EACH,MAAU,MAAM,+CAA+C,EAGjE,GAAI,CAAC,EAAa,MAAM,MACtB,MAAU,MACR,mIACF,EAGF,OAAO,CACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "Vue 3 integration for Real-Router",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"license": "MIT",
|
|
67
67
|
"sideEffects": false,
|
|
68
68
|
"dependencies": {
|
|
69
|
+
"@real-router/core": "^0.54.6",
|
|
69
70
|
"@real-router/route-utils": "^0.2.2",
|
|
70
|
-
"@real-router/sources": "^0.8.
|
|
71
|
-
"@real-router/core": "^0.53.0"
|
|
71
|
+
"@real-router/sources": "^0.8.3"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@testing-library/jest-dom": "6.9.1",
|
|
75
75
|
"@vue/test-utils": "2.4.6",
|
|
76
76
|
"vue": "3.5.13",
|
|
77
|
-
"@real-router/browser-plugin": "^0.17.
|
|
77
|
+
"@real-router/browser-plugin": "^0.17.4"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"vue": ">=3.3.0"
|
package/src/RouterProvider.ts
CHANGED
|
@@ -5,11 +5,12 @@ import { pushDirectiveRouter } from "./directives/vLink";
|
|
|
5
5
|
import {
|
|
6
6
|
createRouteAnnouncer,
|
|
7
7
|
createScrollRestoration,
|
|
8
|
+
createScrollSpy,
|
|
8
9
|
createViewTransitions,
|
|
9
10
|
} from "./dom-utils";
|
|
10
11
|
import { setupRouteProvision } from "./setupRouteProvision";
|
|
11
12
|
|
|
12
|
-
import type { ScrollRestorationOptions } from "./dom-utils";
|
|
13
|
+
import type { ScrollRestorationOptions, ScrollSpyOptions } from "./dom-utils";
|
|
13
14
|
import type { Router } from "@real-router/core";
|
|
14
15
|
import type { PropType } from "vue";
|
|
15
16
|
|
|
@@ -62,6 +63,9 @@ export const RouterProvider = defineComponent({
|
|
|
62
63
|
scrollRestoration: {
|
|
63
64
|
type: Object as PropType<ScrollRestorationOptions>,
|
|
64
65
|
},
|
|
66
|
+
scrollSpy: {
|
|
67
|
+
type: Object as PropType<ScrollSpyOptions>,
|
|
68
|
+
},
|
|
65
69
|
viewTransitions: {
|
|
66
70
|
type: Boolean,
|
|
67
71
|
default: false,
|
|
@@ -106,6 +110,29 @@ export const RouterProvider = defineComponent({
|
|
|
106
110
|
},
|
|
107
111
|
);
|
|
108
112
|
|
|
113
|
+
// Reactive scrollSpy: watch by primitives, omit scrollContainer getter
|
|
114
|
+
// identity for the same reason scrollRestoration does.
|
|
115
|
+
watchToggleableUtility(
|
|
116
|
+
() =>
|
|
117
|
+
[
|
|
118
|
+
props.router,
|
|
119
|
+
props.scrollSpy !== undefined && props.scrollSpy.selector !== "",
|
|
120
|
+
props.scrollSpy?.selector,
|
|
121
|
+
props.scrollSpy?.rootMargin,
|
|
122
|
+
] as const,
|
|
123
|
+
([router, enabled, selector, rootMargin]) => {
|
|
124
|
+
if (!enabled || !selector) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return createScrollSpy(router, {
|
|
129
|
+
selector,
|
|
130
|
+
rootMargin,
|
|
131
|
+
scrollContainer: props.scrollSpy?.scrollContainer,
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
);
|
|
135
|
+
|
|
109
136
|
// Reactive viewTransitions: toggling prop creates/destroys the utility.
|
|
110
137
|
watchToggleableUtility(
|
|
111
138
|
() => [props.router, props.viewTransitions] as const,
|
package/src/components/Link.ts
CHANGED
|
@@ -206,7 +206,7 @@ export const Link = defineComponent({
|
|
|
206
206
|
// Spread + delete avoids the per-key copy loop on every render — one
|
|
207
207
|
// allocation + one property deletion instead of N iterations across
|
|
208
208
|
// data-*, aria-*, role, etc. Hot-path optimisation for Link-heavy pages.
|
|
209
|
-
const restAttributes = { ...attrs }
|
|
209
|
+
const restAttributes = { ...attrs };
|
|
210
210
|
|
|
211
211
|
delete restAttributes.onClick;
|
|
212
212
|
|