@real-router/preact 0.11.1 → 0.13.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 +140 -14
- package/dist/cjs/index.d.ts +21 -6
- 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 +169 -0
- package/dist/cjs/ssr.d.ts.map +1 -0
- package/dist/cjs/ssr.js +2 -0
- package/dist/cjs/ssr.js.map +1 -0
- package/dist/cjs/useRoute-B3rj5MXo.js +2 -0
- package/dist/cjs/useRoute-B3rj5MXo.js.map +1 -0
- package/dist/esm/index.d.mts +21 -6
- 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 +169 -0
- package/dist/esm/ssr.d.mts.map +1 -0
- package/dist/esm/ssr.mjs +2 -0
- package/dist/esm/ssr.mjs.map +1 -0
- package/dist/esm/useRoute-BSPVVbLz.mjs +2 -0
- package/dist/esm/useRoute-BSPVVbLz.mjs.map +1 -0
- package/package.json +23 -6
- package/src/RouterProvider.tsx +15 -2
- package/src/components/Await.tsx +99 -0
- package/src/components/ClientOnly.tsx +25 -0
- package/src/components/HttpStatusCode.tsx +82 -0
- package/src/components/HttpStatusProvider.tsx +22 -0
- package/src/components/Link.tsx +52 -39
- package/src/components/RouteView/RouteView.tsx +12 -8
- package/src/components/RouteView/helpers.tsx +20 -19
- package/src/components/RouterErrorBoundary.tsx +28 -3
- package/src/components/ServerOnly.tsx +26 -0
- package/src/components/Streamed.tsx +24 -0
- package/src/context.ts +17 -0
- package/src/hooks/useDeferred.tsx +26 -0
- package/src/hooks/useIsActiveRoute.tsx +21 -13
- package/src/hooks/useNavigator.tsx +5 -12
- package/src/hooks/useRoute.tsx +7 -8
- package/src/hooks/useRouteNode.tsx +11 -7
- package/src/hooks/useRouter.tsx +5 -12
- package/src/ssr.ts +39 -0
- package/src/types.ts +2 -2
- package/src/useSyncExternalStore.ts +20 -0
- package/src/utils/createHttpStatusSink.ts +27 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render-scoped HTTP status sink. Created per request on the server, passed to
|
|
3
|
+
* `<HttpStatusProvider sink={...}>`, and read after `renderToString` (or the
|
|
4
|
+
* Preact streaming helper) to apply the value to the HTTP response.
|
|
5
|
+
*
|
|
6
|
+
* Last write wins: if the rendered tree mounts more than one
|
|
7
|
+
* `<HttpStatusCode />`, the value reflects the last component that ran during
|
|
8
|
+
* the render pass.
|
|
9
|
+
*
|
|
10
|
+
* No-op on the client — `<HttpStatusCode />` reads the optional context and
|
|
11
|
+
* skips the write when no provider is mounted, so the same component tree can
|
|
12
|
+
* be hydrated without changing behaviour.
|
|
13
|
+
*
|
|
14
|
+
* Constraints:
|
|
15
|
+
* - **Per-request only.** Don't share a sink across requests; the rendered
|
|
16
|
+
* tree mutates `code` in place. Module-level singletons leak status
|
|
17
|
+
* between concurrent requests.
|
|
18
|
+
* - **Don't `Object.freeze` the sink.** The component writes to `.code`;
|
|
19
|
+
* freezing makes the assignment throw under ESM strict mode.
|
|
20
|
+
*/
|
|
21
|
+
export interface HttpStatusSink {
|
|
22
|
+
code: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createHttpStatusSink(): HttpStatusSink {
|
|
26
|
+
return { code: undefined };
|
|
27
|
+
}
|