@timber-js/app 0.2.0-alpha.186 → 0.2.0-alpha.187
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/_chunks/{actions-C-Rw9vPc.js → actions-35jnMdeJ.js} +4 -3
- package/dist/_chunks/{actions-C-Rw9vPc.js.map → actions-35jnMdeJ.js.map} +1 -1
- package/dist/_chunks/als-registry-C6kcfprT.js +41 -0
- package/dist/_chunks/als-registry-C6kcfprT.js.map +1 -0
- package/dist/_chunks/{als-slots-mFweg276.js → als-slots-BEEIPKYm.js} +3 -4
- package/dist/_chunks/{als-slots-mFweg276.js.map → als-slots-BEEIPKYm.js.map} +1 -1
- package/dist/_chunks/{cache-api-Cd0VZ_Pd.js → cache-api-DjNrIWRR.js} +7 -13
- package/dist/_chunks/cache-api-DjNrIWRR.js.map +1 -0
- package/dist/_chunks/cli-check-CpmN7Nh-.js +256 -0
- package/dist/_chunks/cli-check-CpmN7Nh-.js.map +1 -0
- package/dist/_chunks/cli-schema-sync-CGMp_Psg.js +298 -0
- package/dist/_chunks/cli-schema-sync-CGMp_Psg.js.map +1 -0
- package/dist/_chunks/{cloudflare-Cs0uZXea.js → cloudflare-CGP6BZKO.js} +4 -3
- package/dist/_chunks/{cloudflare-Cs0uZXea.js.map → cloudflare-CGP6BZKO.js.map} +1 -1
- package/dist/_chunks/convention-lint-kXsgc_-7.js +784 -0
- package/dist/_chunks/convention-lint-kXsgc_-7.js.map +1 -0
- package/dist/_chunks/{error-boundary-DpYRI_I1.js → error-boundary-D-ODYX41.js} +25 -2
- package/dist/_chunks/error-boundary-D-ODYX41.js.map +1 -0
- package/dist/_chunks/file-cache-DmX7OqZP.js +454 -0
- package/dist/_chunks/file-cache-DmX7OqZP.js.map +1 -0
- package/dist/_chunks/{logger-N7e5auP0.js → logger-D8xJZXIN.js} +27 -40
- package/dist/_chunks/logger-D8xJZXIN.js.map +1 -0
- package/dist/_chunks/mdx-file-C005ay-P.js +25 -0
- package/dist/_chunks/mdx-file-C005ay-P.js.map +1 -0
- package/dist/_chunks/{plugin-context-DEGLSJs3.js → plugin-context-rCinWLiE.js} +7 -2
- package/dist/_chunks/{plugin-context-DEGLSJs3.js.map → plugin-context-rCinWLiE.js.map} +1 -1
- package/dist/_chunks/purge-store-Byr8XOjU.js +14 -0
- package/dist/_chunks/purge-store-Byr8XOjU.js.map +1 -0
- package/dist/_chunks/{resolve-schema-Dz3fcFUo.js → resolve-schema-5ma5pp1b.js} +2 -2
- package/dist/_chunks/{resolve-schema-Dz3fcFUo.js.map → resolve-schema-5ma5pp1b.js.map} +1 -1
- package/dist/_chunks/rsc-media-type-DRqE_lD_.js +46 -0
- package/dist/_chunks/rsc-media-type-DRqE_lD_.js.map +1 -0
- package/dist/_chunks/{cli-schema-sync-CKgHC2MB.js → scanner-C8b0Gcw3.js} +5 -298
- package/dist/_chunks/scanner-C8b0Gcw3.js.map +1 -0
- package/dist/_chunks/schema-bridge-Cc2Gngu1.js +199 -0
- package/dist/_chunks/schema-bridge-Cc2Gngu1.js.map +1 -0
- package/dist/_chunks/segment-classify-C539Pa2O.js.map +1 -1
- package/dist/_chunks/{param-value-C8TNYchQ.js → segment-context-CjOlyB8Y.js} +33 -2
- package/dist/_chunks/segment-context-CjOlyB8Y.js.map +1 -0
- package/dist/_chunks/{use-query-states-DFvWd-EA.js → use-query-states-BbU5Ge1V.js} +74 -26
- package/dist/_chunks/use-query-states-BbU5Ge1V.js.map +1 -0
- package/dist/_chunks/{navigation-root-B29qg0_T.js → use-segment-params-C4r4BD9T.js} +129 -5
- package/dist/_chunks/use-segment-params-C4r4BD9T.js.map +1 -0
- package/dist/_chunks/walkers-RzN6AFjr.js +141 -0
- package/dist/_chunks/walkers-RzN6AFjr.js.map +1 -0
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/compress-module.d.ts +12 -0
- package/dist/adapters/compress-module.d.ts.map +1 -1
- package/dist/adapters/nitro.js +54 -2
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cdn/cloudflare-purge.js +30 -0
- package/dist/cdn/cloudflare-purge.js.map +1 -0
- package/dist/cdn/fastly-purge.js +33 -0
- package/dist/cdn/fastly-purge.js.map +1 -0
- package/dist/cdn/index.js +94 -0
- package/dist/cdn/index.js.map +1 -0
- package/dist/cdn/workers-cache-purge.js +35 -0
- package/dist/cdn/workers-cache-purge.js.map +1 -0
- package/dist/cli-check.d.ts +153 -0
- package/dist/cli-check.d.ts.map +1 -0
- package/dist/cli.d.ts +34 -8
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +46 -21
- package/dist/cli.js.map +1 -1
- package/dist/client/browser-entry/action-dispatch.d.ts.map +1 -1
- package/dist/client/browser-entry/index.d.ts +1 -1
- package/dist/client/browser-entry/index.d.ts.map +1 -1
- package/dist/client/error-boundary.d.ts +6 -0
- package/dist/client/error-boundary.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +27 -33
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.js +21 -14
- package/dist/client/internal.js.map +1 -1
- package/dist/client/link.d.ts +1 -7
- package/dist/client/link.d.ts.map +1 -1
- package/dist/client/navigation-commit.d.ts +16 -0
- package/dist/client/navigation-commit.d.ts.map +1 -1
- package/dist/client/router-pipeline.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/rsc-fetch.d.ts +9 -1
- package/dist/client/rsc-fetch.d.ts.map +1 -1
- package/dist/client/segment-cache.d.ts +8 -0
- package/dist/client/segment-cache.d.ts.map +1 -1
- package/dist/client/use-query-states.d.ts +9 -3
- package/dist/client/use-query-states.d.ts.map +1 -1
- package/dist/codec.js +1 -1
- package/dist/cookies/define-cookie.d.ts.map +1 -1
- package/dist/cookies/index.js +2 -2
- package/dist/cookies/index.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +142 -477
- package/dist/index.js.map +1 -1
- package/dist/params/index.js +1 -1
- package/dist/plugin-context.d.ts +15 -0
- package/dist/plugin-context.d.ts.map +1 -1
- package/dist/plugins/routing.d.ts +0 -9
- package/dist/plugins/routing.d.ts.map +1 -1
- package/dist/plugins/shims.d.ts.map +1 -1
- package/dist/plugins/static-build.d.ts +24 -0
- package/dist/plugins/static-build.d.ts.map +1 -1
- package/dist/routing/codegen-shared.d.ts +3 -44
- package/dist/routing/codegen-shared.d.ts.map +1 -1
- package/dist/routing/codegen-types.d.ts +10 -31
- package/dist/routing/codegen-types.d.ts.map +1 -1
- package/dist/routing/codegen-write.d.ts +51 -0
- package/dist/routing/codegen-write.d.ts.map +1 -0
- package/dist/routing/codegen.d.ts.map +1 -1
- package/dist/routing/convention-lint.d.ts +18 -4
- package/dist/routing/convention-lint.d.ts.map +1 -1
- package/dist/routing/export-detect.d.ts +16 -0
- package/dist/routing/export-detect.d.ts.map +1 -1
- package/dist/routing/index.js +3 -2
- package/dist/routing/link-codegen.d.ts +19 -4
- package/dist/routing/link-codegen.d.ts.map +1 -1
- package/dist/routing/manifest-codegen.d.ts +1 -7
- package/dist/routing/manifest-codegen.d.ts.map +1 -1
- package/dist/routing/types.d.ts +0 -6
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/schema-bridge.d.ts +60 -9
- package/dist/schema-bridge.d.ts.map +1 -1
- package/dist/search-params/define.d.ts +62 -8
- package/dist/search-params/define.d.ts.map +1 -1
- package/dist/search-params/index.d.ts +0 -1
- package/dist/search-params/index.d.ts.map +1 -1
- package/dist/search-params/index.js +66 -29
- package/dist/search-params/index.js.map +1 -1
- package/dist/search-params/parse-total.d.ts +70 -0
- package/dist/search-params/parse-total.d.ts.map +1 -0
- package/dist/search-params/wrappers.d.ts +26 -3
- package/dist/search-params/wrappers.d.ts.map +1 -1
- package/dist/server/access-gate.d.ts +19 -8
- package/dist/server/access-gate.d.ts.map +1 -1
- package/dist/server/action-handler.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +16 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/compress.d.ts.map +1 -1
- package/dist/server/deny-boundary.d.ts +148 -15
- package/dist/server/deny-boundary.d.ts.map +1 -1
- package/dist/server/deny-renderer.d.ts +2 -2
- package/dist/server/deny-renderer.d.ts.map +1 -1
- package/dist/server/error-boundary-wrapper.d.ts +85 -15
- package/dist/server/error-boundary-wrapper.d.ts.map +1 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/internal.d.ts +3 -1
- package/dist/server/internal.d.ts.map +1 -1
- package/dist/server/internal.js +343 -230
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-collector.d.ts +52 -0
- package/dist/server/metadata-collector.d.ts.map +1 -0
- package/dist/server/param-coercion.d.ts +12 -5
- package/dist/server/param-coercion.d.ts.map +1 -1
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline-outcome.d.ts.map +1 -1
- package/dist/server/pipeline-phases.d.ts.map +1 -1
- package/dist/server/primitives.d.ts +23 -0
- package/dist/server/primitives.d.ts.map +1 -1
- package/dist/server/route-element-builder.d.ts +1 -12
- package/dist/server/route-element-builder.d.ts.map +1 -1
- package/dist/server/rsc-cache-key-guard.d.ts.map +1 -1
- package/dist/server/rsc-entry/deny-fallback.d.ts.map +1 -1
- package/dist/server/rsc-entry/error-renderer.d.ts +1 -1
- package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/helpers.d.ts +0 -7
- package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts +0 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/revalidate-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-payload.d.ts +1 -3
- package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +12 -0
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts +0 -2
- package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
- package/dist/server/slot-resolver.d.ts.map +1 -1
- package/dist/server/ssr-bridge-types.d.ts +11 -0
- package/dist/server/ssr-bridge-types.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts +0 -1
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/static-generator.d.ts.map +1 -1
- package/dist/server/status-code-resolver.d.ts +8 -1
- package/dist/server/status-code-resolver.d.ts.map +1 -1
- package/dist/server/tree-builder.d.ts +28 -36
- package/dist/server/tree-builder.d.ts.map +1 -1
- package/dist/server/types.d.ts +12 -7
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/utils/element-type.d.ts +40 -0
- package/dist/server/utils/element-type.d.ts.map +1 -0
- package/dist/shared/rsc-media-type.d.ts +40 -0
- package/dist/shared/rsc-media-type.d.ts.map +1 -0
- package/docs/api/30-api-server.mdx +1 -1
- package/docs/api/33-api-search-params.mdx +38 -16
- package/docs/api/35-api-typescript.mdx +3 -3
- package/docs/api/36-cli.mdx +34 -7
- package/docs/learn/00-introduction.mdx +1 -1
- package/docs/learn/02-pages-and-layouts.mdx +1 -1
- package/docs/learn/05-typed-params.mdx +8 -8
- package/docs/learn/07-typed-routes.mdx +12 -7
- package/docs/learn/11-error-handling.mdx +16 -0
- package/docs/more/01-advanced-routing.mdx +1 -1
- package/docs/more/03-coming-from-nextjs.mdx +2 -2
- package/docs/more/50-ai-agent-instructions.mdx +6 -4
- package/package.json +8 -5
- package/src/adapters/cloudflare.ts +4 -1
- package/src/adapters/compress-module.ts +79 -1
- package/src/cli-check.ts +458 -0
- package/src/cli.ts +59 -24
- package/src/client/browser-entry/action-dispatch.ts +2 -1
- package/src/client/browser-entry/index.ts +0 -5
- package/src/client/error-boundary.tsx +65 -1
- package/src/client/index.ts +14 -3
- package/src/client/link.tsx +65 -64
- package/src/client/navigation-commit.ts +27 -4
- package/src/client/params-context.ts +4 -4
- package/src/client/router-pipeline.ts +4 -0
- package/src/client/router.ts +1 -0
- package/src/client/rsc-fetch.ts +14 -4
- package/src/client/segment-cache.ts +8 -0
- package/src/client/use-query-states.ts +102 -39
- package/src/cookies/define-cookie.ts +6 -1
- package/src/index.ts +20 -3
- package/src/plugin-context.ts +26 -0
- package/src/plugins/routing.ts +84 -146
- package/src/plugins/shims.ts +0 -1
- package/src/plugins/static-build.ts +78 -24
- package/src/routing/codegen-shared.ts +3 -79
- package/src/routing/codegen-types.ts +10 -31
- package/src/routing/codegen-write.ts +139 -0
- package/src/routing/codegen.ts +56 -182
- package/src/routing/convention-lint.ts +139 -40
- package/src/routing/export-detect.ts +151 -7
- package/src/routing/link-codegen.ts +32 -65
- package/src/routing/manifest-codegen.ts +1 -59
- package/src/routing/scanner.ts +3 -3
- package/src/routing/types.ts +0 -6
- package/src/schema-bridge.ts +180 -58
- package/src/search-params/define.ts +102 -37
- package/src/search-params/index.ts +0 -1
- package/src/search-params/parse-total.ts +78 -0
- package/src/search-params/wrappers.ts +60 -11
- package/src/server/access-gate.tsx +60 -40
- package/src/server/action-handler.ts +1 -4
- package/src/server/als-registry.ts +16 -0
- package/src/server/compress.ts +9 -1
- package/src/server/deny-boundary.ts +269 -41
- package/src/server/deny-renderer.ts +32 -21
- package/src/server/error-boundary-wrapper.ts +166 -79
- package/src/server/index.ts +1 -3
- package/src/server/internal.ts +2 -2
- package/src/server/metadata-collector.ts +115 -0
- package/src/server/param-coercion.ts +13 -61
- package/src/server/pipeline-helpers.ts +2 -2
- package/src/server/pipeline-outcome.ts +2 -1
- package/src/server/pipeline-phases.ts +9 -9
- package/src/server/primitives.ts +25 -0
- package/src/server/route-element-builder.ts +167 -170
- package/src/server/rsc-cache-key-guard.ts +2 -8
- package/src/server/rsc-entry/deny-fallback.ts +3 -2
- package/src/server/rsc-entry/error-renderer.ts +31 -11
- package/src/server/rsc-entry/helpers.ts +2 -12
- package/src/server/rsc-entry/index.ts +0 -5
- package/src/server/rsc-entry/render-route.ts +14 -11
- package/src/server/rsc-entry/revalidate-renderer.ts +2 -1
- package/src/server/rsc-entry/rsc-payload.ts +104 -20
- package/src/server/rsc-entry/rsc-stream.ts +25 -2
- package/src/server/rsc-entry/ssr-renderer.ts +28 -16
- package/src/server/slot-resolver.ts +10 -2
- package/src/server/ssr-bridge-types.ts +12 -0
- package/src/server/ssr-entry.ts +8 -6
- package/src/server/static-generator.ts +3 -2
- package/src/server/status-code-resolver.ts +28 -11
- package/src/server/tree-builder.ts +35 -218
- package/src/server/types.ts +12 -7
- package/src/server/utils/element-type.ts +72 -0
- package/src/shared/rsc-media-type.ts +43 -0
- package/dist/_chunks/cache-api-Cd0VZ_Pd.js.map +0 -1
- package/dist/_chunks/cli-schema-sync-CKgHC2MB.js.map +0 -1
- package/dist/_chunks/error-boundary-DpYRI_I1.js.map +0 -1
- package/dist/_chunks/logger-N7e5auP0.js.map +0 -1
- package/dist/_chunks/navigation-root-B29qg0_T.js.map +0 -1
- package/dist/_chunks/param-value-C8TNYchQ.js.map +0 -1
- package/dist/_chunks/registry-DbJPKoBp.js +0 -20
- package/dist/_chunks/registry-DbJPKoBp.js.map +0 -1
- package/dist/_chunks/schema-bridge-DT_Tn0Xf.js +0 -119
- package/dist/_chunks/schema-bridge-DT_Tn0Xf.js.map +0 -1
- package/dist/_chunks/segment-context-ZDnXDkbz.js +0 -34
- package/dist/_chunks/segment-context-ZDnXDkbz.js.map +0 -1
- package/dist/_chunks/use-query-states-DFvWd-EA.js.map +0 -1
- package/dist/_chunks/use-segment-params-ClyUNq4d.js +0 -128
- package/dist/_chunks/use-segment-params-ClyUNq4d.js.map +0 -1
- package/dist/_chunks/walkers-BhhwI9TD.js +0 -936
- package/dist/_chunks/walkers-BhhwI9TD.js.map +0 -1
- package/dist/search-params/registry.d.ts +0 -20
- package/dist/search-params/registry.d.ts.map +0 -1
- package/dist/segment-params/define.d.ts +0 -83
- package/dist/segment-params/define.d.ts.map +0 -1
- package/dist/segment-params/index.d.ts +0 -3
- package/dist/segment-params/index.d.ts.map +0 -1
- package/dist/segment-params/index.js +0 -70
- package/dist/segment-params/index.js.map +0 -1
- package/src/search-params/registry.ts +0 -31
- package/src/segment-params/define.ts +0 -226
- package/src/segment-params/index.ts +0 -9
package/dist/server/types.d.ts
CHANGED
|
@@ -24,21 +24,26 @@ export interface MiddlewareContext {
|
|
|
24
24
|
* `req` is the original incoming Request; `headers` is the response-headers
|
|
25
25
|
* container the framework will apply to the final Response.
|
|
26
26
|
*
|
|
27
|
-
* Segment params and query parameters are NOT on this context — they are
|
|
28
|
-
*
|
|
27
|
+
* Segment params and query parameters are NOT on this context — they are read
|
|
28
|
+
* the same way pages read them:
|
|
29
29
|
*
|
|
30
30
|
* ```ts
|
|
31
|
-
* // app/
|
|
32
|
-
* export
|
|
31
|
+
* // app/schema.ts — every dynamic segment's codec, keyed by bracket name
|
|
32
|
+
* export default defineSchema({ segmentParams: { '[id]': z.coerce.number() } });
|
|
33
|
+
*
|
|
33
34
|
* // app/api/users/[id]/route.ts
|
|
34
|
-
* import {
|
|
35
|
+
* import { getSegmentParams } from '@timber-js/app/server';
|
|
36
|
+
* import { SEGMENT_PATH } from './$segment';
|
|
35
37
|
* export async function GET() {
|
|
36
|
-
* const { id } =
|
|
38
|
+
* const { id } = getSegmentParams(SEGMENT_PATH); // typed number — 404 on bad input
|
|
37
39
|
* }
|
|
38
40
|
* ```
|
|
39
41
|
*
|
|
42
|
+
* For query parameters, import a `defineSearchParams` definition and call
|
|
43
|
+
* `.get()` on it.
|
|
44
|
+
*
|
|
40
45
|
* See design/07-routing.md §"RouteContext", design/23-search-params.md,
|
|
41
|
-
* design/
|
|
46
|
+
* design/41-global-params.md.
|
|
42
47
|
*/
|
|
43
48
|
export interface RouteContext {
|
|
44
49
|
req: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,gBAAgB,EAAE,GAClB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,OAAO,CAAC;IACb,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IACjD,wEAAwE;IACxE,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;CAC1C;AAED
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,gBAAgB,EAAE,GAClB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,OAAO,CAAC;IACb,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,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E,OAAO,GACP,OAAO,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component-type validation for values loaded from route modules.
|
|
3
|
+
*
|
|
4
|
+
* Route modules are loaded dynamically, so their `default` export is
|
|
5
|
+
* `unknown`. Every construction site that wants to pass one to
|
|
6
|
+
* `createElement` narrows it through `isValidElementType` first.
|
|
7
|
+
*/
|
|
8
|
+
import type { ReactNode } from 'react';
|
|
9
|
+
/**
|
|
10
|
+
* A React component reference loaded from a route module's default export.
|
|
11
|
+
*
|
|
12
|
+
* Loaded modules' `default` is typed as `unknown` (modules are dynamic), so
|
|
13
|
+
* call sites narrow it through `isValidElementType` (below) before treating
|
|
14
|
+
* it as a component. The signature is a callable returning `ReactNode` —
|
|
15
|
+
* TypeScript's view of every valid React component shape, including exotic
|
|
16
|
+
* components (`memo`, `forwardRef`, `lazy`) which the type system treats as
|
|
17
|
+
* callable even though their runtime values are objects with `$$typeof`
|
|
18
|
+
* markers rather than functions.
|
|
19
|
+
*/
|
|
20
|
+
export type LoadedComponent = (...args: unknown[]) => ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Validate that a loaded module's `default` export is something React
|
|
23
|
+
* accepts as the first argument to `createElement` — i.e. a valid component
|
|
24
|
+
* type. React doesn't export `isValidElementType` (only `isValidElement`,
|
|
25
|
+
* which checks for *elements*, not *component types*), so this mirrors
|
|
26
|
+
* React's internal check:
|
|
27
|
+
*
|
|
28
|
+
* - functions → function or class components
|
|
29
|
+
* - objects with a `$$typeof` matching one of React's known component
|
|
30
|
+
* markers → exotic components (`memo`, `forwardRef`, `lazy`, context,
|
|
31
|
+
* suspense, client references via `@vitejs/plugin-rsc`)
|
|
32
|
+
*
|
|
33
|
+
* Strings (HTML tag names) are valid for `createElement` but never appear
|
|
34
|
+
* as a route module's default export, so they're not recognized here.
|
|
35
|
+
*
|
|
36
|
+
* Anything else (numbers, plain config objects, JSON, etc.) is rejected so
|
|
37
|
+
* the boundary wrapper is skipped rather than crashing inside React.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isValidElementType(value: unknown): value is LoadedComponent;
|
|
40
|
+
//# sourceMappingURL=element-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-type.d.ts","sourceRoot":"","sources":["../../../src/server/utils/element-type.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,SAAS,CAAC;AA2BhE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAK3E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The RSC Flight media type, and the request predicate over it.
|
|
3
|
+
*
|
|
4
|
+
* One module owns the string because two independently-written spellings of
|
|
5
|
+
* "is this an RSC request?" must agree, and the consequence of them
|
|
6
|
+
* disagreeing is cache poisoning rather than a visible bug. The Cloudflare
|
|
7
|
+
* adapter's `isRsc` decides what may enter the edge cache; the origin's
|
|
8
|
+
* pipeline decides which headers may vary the response. TIM-1269 made the
|
|
9
|
+
* adapter's `VARY_HONORED` allowlist exempt `Accept` *because* `isRsc`
|
|
10
|
+
* excludes Flight responses from the cache, and exempt the `X-Timber-*`
|
|
11
|
+
* headers *because* the origin reads them only behind its own RSC check. If
|
|
12
|
+
* one predicate is ever tightened (a real media-type parse, a
|
|
13
|
+
* parameter-aware match) and the other is not, the adapter can classify a
|
|
14
|
+
* request as a document while the origin treats it as RSC, and store a
|
|
15
|
+
* Flight payload under the document's key — the class
|
|
16
|
+
* `design/48-payload-addressing.md` exists to prevent.
|
|
17
|
+
*
|
|
18
|
+
* `tests/rsc-media-type-single-source.test.ts` fails if the literal reappears
|
|
19
|
+
* in executable source outside this file.
|
|
20
|
+
*
|
|
21
|
+
* Isomorphic: zero imports, so `adapters/cloudflare.ts` — which Node's native
|
|
22
|
+
* ESM loader evaluates before Vite's resolver exists — can load it and
|
|
23
|
+
* interpolate the value into the generated worker. Same precedent as
|
|
24
|
+
* `shared/rsc-cache-key.ts`.
|
|
25
|
+
*
|
|
26
|
+
* See design/19-client-navigation.md, design/25-production-deployments.md
|
|
27
|
+
* §"`Vary` and the Workers Cache API".
|
|
28
|
+
*/
|
|
29
|
+
/** Media type of a React Flight payload. */
|
|
30
|
+
export declare const RSC_CONTENT_TYPE = "text/x-component";
|
|
31
|
+
/**
|
|
32
|
+
* Is this request asking for an RSC payload rather than a full document?
|
|
33
|
+
*
|
|
34
|
+
* Substring containment, deliberately: `Accept` is a list, and a client may
|
|
35
|
+
* send `text/x-component;charset=utf-8` or list it alongside other types.
|
|
36
|
+
* Tightening this to a real media-type parse is a behaviour change that has
|
|
37
|
+
* to move the adapter's generated `isRsc` in the same commit — see above.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isRscRequest(req: Request): boolean;
|
|
40
|
+
//# sourceMappingURL=rsc-media-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rsc-media-type.d.ts","sourceRoot":"","sources":["../../src/shared/rsc-media-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAElD"}
|
|
@@ -161,7 +161,7 @@ interface RouteContext {
|
|
|
161
161
|
}
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
Segment params and query params are **not** on `RouteContext`. Read them
|
|
164
|
+
Segment params and query params are **not** on `RouteContext`. Read them the same way pages do — `getSegmentParams(SEGMENT_PATH)` (importing `SEGMENT_PATH` from the route's `./$segment` module) and `searchParams.get()` on an imported definition. For the raw query string, use `new URL(ctx.req.url).searchParams`.
|
|
165
165
|
|
|
166
166
|
### `MiddlewareContext`
|
|
167
167
|
|
|
@@ -45,9 +45,8 @@ Note: `z.coerce.*` schemas declare input `unknown`, so a coerce schema without `
|
|
|
45
45
|
| `.useQueryStates(opts?)` | Client hook — read and update typed search params |
|
|
46
46
|
| `.extend(codecs)` | Add additional params |
|
|
47
47
|
| `.pick(...keys)` | Create a subset |
|
|
48
|
-
| `.serialize(values)` | Convert typed values to URL search string |
|
|
49
48
|
| `.href(base, values)` | Build a full URL with params |
|
|
50
|
-
| `.
|
|
49
|
+
| `.buildSearchParams(values)` | Serialize to a query string — pass to `<Link searchParams>` |
|
|
51
50
|
| `.codecs` | Read-only codec map |
|
|
52
51
|
| `.urlKeys` | Read-only URL key alias map |
|
|
53
52
|
|
|
@@ -110,31 +109,52 @@ The codec protocol shared across search params, segment params, and cookies. See
|
|
|
110
109
|
interface SearchParamCodec<T> {
|
|
111
110
|
parse(value: string | string[] | undefined): T;
|
|
112
111
|
serialize(value: T): string | null;
|
|
112
|
+
urlKey?: string;
|
|
113
|
+
// optional total entry point — preferred over parse when present
|
|
114
|
+
parseServerSide?(value: string | string[] | undefined): T;
|
|
113
115
|
}
|
|
114
116
|
```
|
|
115
117
|
|
|
118
|
+
`parse` receives the **raw** URL value — `string | string[] | undefined` — because a param may be absent (`/products`) or repeated (`?q=a&q=b`). A codec must handle all three.
|
|
119
|
+
|
|
120
|
+
If handling all three in `parse` is awkward — as it is for a nuqs parser, whose `parse` is written for a present scalar — publish `parseServerSide` instead. Timber calls it wherever it invokes the codec, and its return type is the field's type: a codec that answers `null` for an absent param is a `SearchParamCodec<T | null>`.
|
|
121
|
+
|
|
116
122
|
Compatible codecs:
|
|
117
123
|
|
|
118
|
-
- **Zod/Valibot/ArkType schemas** — auto-detected via Standard Schema
|
|
119
|
-
- **nuqs parsers** — `parseAsInteger`, `parseAsString`, `parseAsBoolean`
|
|
124
|
+
- **Zod/Valibot/ArkType schemas** — auto-detected via Standard Schema. Total over absent and repeated input, so this is the safe default.
|
|
120
125
|
- **Custom** — any object implementing the interface
|
|
126
|
+
- **nuqs parsers** — total through timber, with one exception. See below.
|
|
127
|
+
|
|
128
|
+
## Parsers come from nuqs
|
|
129
|
+
|
|
130
|
+
Timber does not ship or re-export `parseAs*` parsers. Import them from [nuqs](https://nuqs.47ng.com/), which is a peer dependency; timber ships the wrappers (`withDefault`, `withUrlKey`) and the schema bridge.
|
|
131
|
+
|
|
132
|
+
nuqs checks whether a param is present before calling `parse`, so a parser's `parse` assumes a present scalar. Timber calls the parser's `parseServerSide` instead — nuqs's own adapter for the raw URL value — so every **single**-value parser is total:
|
|
133
|
+
|
|
134
|
+
| Raw value | Result |
|
|
135
|
+
| --------------------- | ------------------------------------------------------------- |
|
|
136
|
+
| absent (`/products`) | `null`, or the parser's own default if it declares one |
|
|
137
|
+
| repeated (`?v=a&v=b`) | the **first** value, matching `URLSearchParams.get()` |
|
|
138
|
+
| present | whatever the parser returns; if it **throws**, `null` |
|
|
121
139
|
|
|
122
|
-
|
|
140
|
+
So `?page=1&page=2` gives `1`, `parseAsBoolean` on a missing `?debug=` gives `null` rather than an HTTP 500, and `parseAsString` on `?q=a&q=b` gives `'a'` rather than an array its type forbids.
|
|
123
141
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
142
|
+
A present value is not validated for you — each parser decides. `parseAsBoolean` on `?v=maybe` is `false`, and `parseAsInteger` on `?v=12abc` is `12`. Use a schema when you need the value rejected rather than coerced.
|
|
143
|
+
|
|
144
|
+
The exception is `parseAsNativeArrayOf`, nuqs's *multi*-value parser for repeated keys. It is **not usable in `defineSearchParams`**: its `parse` is declared over `readonly string[]`, so the field is a compile error, and forcing it through leaves the client hook reading it as empty. Use an array schema for repeated keys. Tracked as TIM-1355.
|
|
145
|
+
|
|
146
|
+
Two consequences worth knowing:
|
|
147
|
+
|
|
148
|
+
- **`parseAsArrayOf` reads one key, not repeated keys.** It is a comma-separated list inside a single value, so `?tags=a,b` gives `['a','b']` but `?tags=a&tags=b` gives `['a']`. For repeated keys use an array schema — `tags: z.array(z.string()).default([])` reads both `?tags=a` and `?tags=a&tags=b`.
|
|
149
|
+
- **`parseAsJson` requires a validator argument** — `parseAsJson(z.object({ … }).parse)`. Called bare it does not type-check, and at runtime returns `null` for every value.
|
|
150
|
+
|
|
151
|
+
A field typed by a bare parser is nullable (`parseAsString` → `string | null`). Use `withDefault()` — timber's or the parser's own — to make it non-nullable.
|
|
132
152
|
|
|
133
153
|
## Codec Wrappers
|
|
134
154
|
|
|
135
155
|
### `withDefault(codec, value)`
|
|
136
156
|
|
|
137
|
-
Wrap a codec to
|
|
157
|
+
Wrap a codec to supply a value whenever the inner codec produces none — `null` or `undefined`. The field is non-nullable.
|
|
138
158
|
|
|
139
159
|
```ts
|
|
140
160
|
import { withDefault } from '@timber-js/app/search-params';
|
|
@@ -142,13 +162,15 @@ import { parseAsInteger } from 'nuqs';
|
|
|
142
162
|
const page = withDefault(parseAsInteger, 1); // number (never null)
|
|
143
163
|
```
|
|
144
164
|
|
|
165
|
+
A **present** value is left alone, including a falsy one: `?page=0` is `0`, and `?q=` is `''`, not the default.
|
|
166
|
+
|
|
145
167
|
### `withUrlKey(codec, key)`
|
|
146
168
|
|
|
147
169
|
Attach a URL key alias to a codec.
|
|
148
170
|
|
|
149
171
|
```ts
|
|
150
172
|
import { withUrlKey } from '@timber-js/app/search-params';
|
|
151
|
-
import {
|
|
152
|
-
const query = withUrlKey(
|
|
173
|
+
import { z } from 'zod/v4';
|
|
174
|
+
const query = withUrlKey(z.string().nullable().default(null), 'q');
|
|
153
175
|
// ?q=shoes → { query: 'shoes' }
|
|
154
176
|
```
|
|
@@ -107,10 +107,10 @@ Without `SEGMENT_PATH`, params are `Partial<AllSegmentParams>` — all optional.
|
|
|
107
107
|
|
|
108
108
|
## Typed Search Params
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Search params are typed by the definition you create and import — there is no convention file:
|
|
111
111
|
|
|
112
112
|
```ts
|
|
113
|
-
// app/products/params.ts
|
|
113
|
+
// app/products/search-params.ts — any module you like
|
|
114
114
|
import { defineSearchParams } from '@timber-js/app/search-params';
|
|
115
115
|
import { z } from 'zod/v4';
|
|
116
116
|
|
|
@@ -135,7 +135,7 @@ export async function GET(ctx: RouteContext) {
|
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
Query params are read via `searchParams.get()` on an imported definition — the same accessor pages use. Segment params come from `getSegmentParams(SEGMENT_PATH)`. For the raw query string, use `new URL(ctx.req.url).searchParams`.
|
|
139
139
|
|
|
140
140
|
### `MiddlewareContext`
|
|
141
141
|
|
package/docs/api/36-cli.mdx
CHANGED
|
@@ -9,7 +9,7 @@ slug: 'cli'
|
|
|
9
9
|
timber.js provides four commands. All are thin wrappers around Vite with timber-specific behavior.
|
|
10
10
|
|
|
11
11
|
```tsx
|
|
12
|
-
timber < command > [--config<path>];
|
|
12
|
+
timber < command > [--config<path>][--project<path>];
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Commands
|
|
@@ -40,7 +40,7 @@ To override the default, use any of the following (highest precedence first):
|
|
|
40
40
|
1. `server.port` in `vite.config.ts`
|
|
41
41
|
2. `PORT=4000 timber dev` — the `PORT` environment variable
|
|
42
42
|
|
|
43
|
-
> **Note:** `timber dev --port 4000` is an error, not a silent no-op.
|
|
43
|
+
> **Note:** `timber dev --port 4000` is an error, not a silent no-op. `timber dev` accepts only `--config` — use `PORT` or `server.port` to change the port.
|
|
44
44
|
|
|
45
45
|
When you set the port explicitly, timber **does not** auto-bump — a conflict produces an `EADDRINUSE` error so you find out immediately rather than connecting to the wrong port. This same behavior applies to `timber preview` and the production Node preview server.
|
|
46
46
|
|
|
@@ -84,13 +84,39 @@ Always run `timber build` before `timber preview`.
|
|
|
84
84
|
|
|
85
85
|
### `timber check`
|
|
86
86
|
|
|
87
|
-
Validate
|
|
87
|
+
Validate routes and types without producing build output.
|
|
88
88
|
|
|
89
89
|
```bash
|
|
90
90
|
timber check
|
|
91
|
+
timber check --config ./custom-vite.config.ts --project ./tsconfig.build.json
|
|
91
92
|
```
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
Two passes, in order:
|
|
95
|
+
|
|
96
|
+
1. **Routes.** Resolves your project through Vite exactly as `timber build` does — same root, app directory and `pageExtensions`, same `production` mode and `NODE_ENV`, and including config passed inline to `timber()` in `vite.config.ts`. A config that branches on `mode` or reads `.env.production` therefore resolves the same way under both commands. It then scans, runs the route convention linter, and regenerates the route types (`.timber/timber-routes.d.ts`, `.timber/segment-types.d.ts`, `timber-env.d.ts`). Convention *errors* — the proven-fatal misconfigurations that also fail `timber build`, such as an `error.tsx` that is a server component — fail the command. Warnings print and do not.
|
|
97
|
+
2. **Types.** `tsgo --noEmit`, run from the root the route pass resolved — so it type-checks the same project whose routes were just validated, and finds the declarations that pass just wrote. A relative `--project` is interpreted from the directory you ran the command in.
|
|
98
|
+
|
|
99
|
+
Codegen runs first on purpose: the generated declarations are what type `<Link href>`, `useSegmentParams()`, and `MiddlewareContext`. On a fresh clone that has never run `timber dev` or `timber build` they do not exist yet, so a bare type check would report errors about correct code.
|
|
100
|
+
|
|
101
|
+
Your `tsconfig.json` must pull in `timber-env.d.ts` — that file is what references the generated route map. If your `include` lists only source directories, add it:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"include": ["app", "*.config.ts", "timber-env.d.ts"]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`timber check` warns when the generated types are not part of the resolved program, because the type check would otherwise pass while measuring `<Link href>` against an empty placeholder. Projects created with `create-timber-app` are configured correctly.
|
|
110
|
+
|
|
111
|
+
`timber check` requires **`@typescript/native-preview`** (which provides `tsgo`). It is an optional peer dependency — install it as a dev dependency:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pnpm add -D @typescript/native-preview
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
If it is missing, `timber check` fails with that instruction. It never passes by skipping the type check.
|
|
118
|
+
|
|
119
|
+
Useful in CI pipelines and pre-commit hooks to catch type and routing errors without a full build.
|
|
94
120
|
|
|
95
121
|
### `timber init`
|
|
96
122
|
|
|
@@ -108,11 +134,12 @@ The generated `AGENTS.md` includes project structure, key imports, common patter
|
|
|
108
134
|
|
|
109
135
|
| Flag | Short | Description |
|
|
110
136
|
| ----------------- | ----- | --------------------------------------------------------------------------------------------------------- |
|
|
111
|
-
| `--config <path>`
|
|
137
|
+
| `--config <path>` | `-c` | Path to a custom Vite config file. Means the same thing for every command, `check` included. |
|
|
138
|
+
| `--project <path>` | | `timber check` only — the `tsconfig.json` to type-check. |
|
|
112
139
|
|
|
113
|
-
> **Note:**
|
|
140
|
+
> **Note:** `timber check` resolves your app through Vite, so `--config` names the Vite config there too, exactly as it does for `dev` and `build`. The tsconfig has its own flag, `--project`, spelled the way `tsc` and `tsgo` spell it. `check` needs a Vite config that lists the timber plugin and fails with an actionable message if it cannot find one.
|
|
114
141
|
|
|
115
|
-
|
|
142
|
+
Those are the only flags. Any other produces an error rather than being silently ignored, with a hint at the supported alternative (e.g. `--port` points you to the `PORT` env var or `server.port` in `vite.config.ts`). Passing `--project` to a command with no type pass is an error too, pointing you at `--config`.
|
|
116
143
|
|
|
117
144
|
## Package Manager Scripts
|
|
118
145
|
|
|
@@ -69,7 +69,7 @@ const [sp, setSearchParams] = searchParams.useQueryStates();
|
|
|
69
69
|
All routing in timber is fully typed and integrated. So you can write a `<Link>` as:
|
|
70
70
|
|
|
71
71
|
```tsx
|
|
72
|
-
<Link href="/blog/[slug]" segmentParams={{ slug: 'a-post' }}
|
|
72
|
+
<Link href="/blog/[slug]" segmentParams={{ slug: 'a-post' }}>Page</Link>
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
Or just normal `<a>` tags work too.
|
|
@@ -94,7 +94,7 @@ Each directory is called a **segment** and can contain these files:
|
|
|
94
94
|
| `layout.tsx` | Persistent UI shell — wraps children, survives navigation |
|
|
95
95
|
| `access.ts` | Authorization gate — runs before the layout renders |
|
|
96
96
|
| `middleware.ts` | Pre-render hook for headers, redirects, and cache warming |
|
|
97
|
-
| `
|
|
97
|
+
| _(none)_ | Segment param codecs live in `app/schema.ts`; search params in any module you import — see [Typed Params](/docs/typed-params) |
|
|
98
98
|
| `error.tsx` | Error boundary catching failures in this subtree |
|
|
99
99
|
| `404.tsx` | Denial page for 404 status code (must be a client component) |
|
|
100
100
|
|
|
@@ -112,9 +112,9 @@ const params = getSegmentParams();
|
|
|
112
112
|
|
|
113
113
|
## Search Params
|
|
114
114
|
|
|
115
|
-
Declare typed search params with `defineSearchParams
|
|
115
|
+
Declare typed search params with `defineSearchParams` in any module, then import it where you need it. Unlike segment params, there is no convention file and nothing is scanned:
|
|
116
116
|
|
|
117
|
-
```ts title="app/products/params.ts" id="search-params"
|
|
117
|
+
```ts title="app/products/search-params.ts" id="search-params"
|
|
118
118
|
import { defineSearchParams, withDefault } from '@timber-js/app/search-params';
|
|
119
119
|
import { parseAsInteger } from 'nuqs';
|
|
120
120
|
import { z } from 'zod/v4';
|
|
@@ -129,7 +129,7 @@ export const searchParams = defineSearchParams({
|
|
|
129
129
|
### Server Usage
|
|
130
130
|
|
|
131
131
|
```tsx title="app/products/page.tsx" use="search-params"
|
|
132
|
-
import { searchParams } from './params';
|
|
132
|
+
import { searchParams } from './search-params';
|
|
133
133
|
|
|
134
134
|
export default async function ProductsPage() {
|
|
135
135
|
const { page, sort, q } = searchParams.get();
|
|
@@ -142,7 +142,7 @@ export default async function ProductsPage() {
|
|
|
142
142
|
|
|
143
143
|
```tsx title="app/products/filters.tsx" use="search-params"
|
|
144
144
|
'use client';
|
|
145
|
-
import { searchParams } from './params';
|
|
145
|
+
import { searchParams } from './search-params';
|
|
146
146
|
|
|
147
147
|
export function ProductFilters() {
|
|
148
148
|
const [params, setParams] = searchParams.useQueryStates();
|
|
@@ -231,7 +231,7 @@ For segment params, use the `codec` namespace:
|
|
|
231
231
|
| `codec.catchAll(inner)` | `T[]` | Wraps scalar codec for catch-all segments |
|
|
232
232
|
| `codec.optionalCatchAll(inner)` | `T[] \| undefined` | Wraps scalar codec for optional catch-all segments |
|
|
233
233
|
|
|
234
|
-
Use `withDefault()` to get a non-nullable type for search params. [nuqs](https://nuqs.47ng.com/) parsers
|
|
234
|
+
Use `withDefault()` to get a non-nullable type for search params. [nuqs](https://nuqs.47ng.com/) parsers all work as codecs: an absent param is `null` and a repeated one takes the first value. Note that `parseAsArrayOf` reads a comma-separated list from a single key — for repeated keys (`?ids=1&ids=2`) use an array schema, e.g. `z.array(z.string()).default([])`. */}
|
|
235
235
|
|
|
236
236
|
## Composition
|
|
237
237
|
|
|
@@ -247,7 +247,7 @@ export const pagination = {
|
|
|
247
247
|
};
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
-
```ts title="app/products/params.ts"
|
|
250
|
+
```ts title="app/products/search-params.ts"
|
|
251
251
|
import { defineSearchParams } from '@timber-js/app/search-params';
|
|
252
252
|
import { pagination } from '@/lib/search-params/pagination';
|
|
253
253
|
import { z } from 'zod/v4';
|
|
@@ -264,10 +264,10 @@ Map a property name to a different URL key with `withUrlKey`:
|
|
|
264
264
|
|
|
265
265
|
```ts
|
|
266
266
|
import { defineSearchParams, withUrlKey } from '@timber-js/app/search-params';
|
|
267
|
-
import {
|
|
267
|
+
import { z } from 'zod/v4';
|
|
268
268
|
|
|
269
269
|
export const searchParams = defineSearchParams({
|
|
270
|
-
query: withUrlKey(
|
|
270
|
+
query: withUrlKey(z.string().nullable().default(null), 'q'),
|
|
271
271
|
});
|
|
272
272
|
// ?q=shoes → { query: 'shoes' }
|
|
273
273
|
```
|
|
@@ -84,23 +84,23 @@ Add `rootDirs` so TypeScript can resolve `$segment` imports:
|
|
|
84
84
|
|
|
85
85
|
## Typed Search Params
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
Define search params with `defineSearchParams()` in any module and import it — there is no convention file. Search params are then fully typed throughout the stack:
|
|
88
88
|
|
|
89
|
-
```ts title="app/products/params.ts"
|
|
89
|
+
```ts title="app/products/search-params.ts"
|
|
90
90
|
import { defineSearchParams, withDefault, withUrlKey } from '@timber-js/app/search-params';
|
|
91
|
-
import { parseAsInteger,
|
|
91
|
+
import { parseAsInteger, parseAsStringEnum } from 'nuqs';
|
|
92
92
|
import { z } from 'zod/v4';
|
|
93
93
|
|
|
94
94
|
export const searchParams = defineSearchParams({
|
|
95
95
|
page: withDefault(parseAsInteger, 1),
|
|
96
|
-
q: withUrlKey(
|
|
96
|
+
q: withUrlKey(z.string().nullable().default(null), 'search'),
|
|
97
97
|
category: z.string().nullable().default(null),
|
|
98
98
|
sort: withDefault(parseAsStringEnum(['price-asc', 'price-desc', 'newest']), 'newest'),
|
|
99
99
|
});
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
```tsx title="app/products/page.tsx"
|
|
103
|
-
import { searchParams } from './params';
|
|
103
|
+
import { searchParams } from './search-params';
|
|
104
104
|
|
|
105
105
|
export default async function ProductsPage() {
|
|
106
106
|
const { page, q, category, sort } = await searchParams.get();
|
|
@@ -108,16 +108,21 @@ export default async function ProductsPage() {
|
|
|
108
108
|
}
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
`<Link>`
|
|
111
|
+
Pass them to `<Link>` by building them from the definition. `buildSearchParams` type-checks the values and applies the definition's codecs and URL-key aliases:
|
|
112
112
|
|
|
113
113
|
```tsx
|
|
114
|
+
import { searchParams } from './search-params';
|
|
115
|
+
|
|
114
116
|
<Link
|
|
115
117
|
href="/products/[id]"
|
|
116
118
|
segmentParams={{ id }}
|
|
117
|
-
searchParams={{ sort: 'newest', q: 'boots' }}
|
|
119
|
+
searchParams={searchParams.buildSearchParams({ sort: 'newest', q: 'boots' })}
|
|
118
120
|
/>
|
|
121
|
+
// → /products/42?sort=newest&search=boots (q is aliased to search)
|
|
119
122
|
```
|
|
120
123
|
|
|
124
|
+
A plain object also works as an untyped escape hatch for one-off params with no definition — but it skips codecs and aliases, so do not use it for keys a definition owns.
|
|
125
|
+
|
|
121
126
|
See [Typed Params](/docs/typed-params) for the full search params API.
|
|
122
127
|
|
|
123
128
|
## Codegen
|
|
@@ -73,6 +73,18 @@ Priority order (innermost to outermost):
|
|
|
73
73
|
3. `error.tsx` — catches anything unmatched
|
|
74
74
|
4. Parent segments → framework default
|
|
75
75
|
|
|
76
|
+
Component status files (`.tsx`, `.jsx`, `.ts`, `.js`) and `error.tsx` **must start with `'use client'`**:
|
|
77
|
+
|
|
78
|
+
```tsx title="app/404.tsx"
|
|
79
|
+
'use client';
|
|
80
|
+
|
|
81
|
+
export default function NotFound({ status }: { status: number }) {
|
|
82
|
+
return <h1>Page not found</h1>;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
timber hands these components to its error boundary — a client component — as a prop, so a server component there cannot cross the RSC boundary. It is not a degraded error page: every page under that segment fails to render. The build catches it and names the file, so you will not discover it as a serialization error on a page you did not touch. MDX status files (`404.mdx`) are the exception — they are server components, rendered ahead of time.
|
|
87
|
+
|
|
76
88
|
If nothing in the chain matches, timber renders a built-in status page: a plain document with the status code and its reason phrase, and nothing else — no request URL, no error message. It is what a static build writes to `404.html` when your app has no not-found page, so a static deploy always ships one. Add a root `app/404.tsx` (or `4xx.tsx` / `error.tsx`) to replace it.
|
|
77
89
|
|
|
78
90
|
## `error.tsx`
|
|
@@ -101,6 +113,10 @@ export default function DashboardError({
|
|
|
101
113
|
|
|
102
114
|
Error boundaries wrap page content inside layouts — the layout shell (nav, sidebar) stays visible when an error fires.
|
|
103
115
|
|
|
116
|
+
A status page renders inside the layouts **above and including the segment it lives in**, and none below it. A root `404.tsx` serving a `deny(404)` from `app/docs/[slug]/page.tsx` renders inside the root layout only — `docs/layout.tsx` and `[slug]/layout.tsx` do not appear, because the file that matched lives above them. Co-locate the status file with the segment whose chrome you want kept: move that `404.tsx` to `app/docs/` and the docs layout comes with it.
|
|
117
|
+
|
|
118
|
+
One exception: **the segment that denied never contributes its own layout**, even when it owns the matched status file. If its `access.ts` denied, that layout sits behind the failed auth check, so running it would let it fetch and serialize data the request was not allowed to see. If the layout itself called `deny()`, it threw instead of returning its chrome, so there is nothing to render. A `deny()` from a page is unaffected — the page's own layout still renders.
|
|
119
|
+
|
|
104
120
|
When a `deny()` has no matching status-code file, it falls through to the nearest `error.tsx`. The component still receives a real `error` (its message is `Access denied with status <N>`), and additionally receives `status` and `dangerouslyPassData` so you can render denial-specific UI:
|
|
105
121
|
|
|
106
122
|
```tsx title="app/error.tsx"
|
|
@@ -67,7 +67,7 @@ This is useful for CDN-cacheable file-extension routes (e.g. image generation en
|
|
|
67
67
|
- One param per segment — `[foo]-[bar]` is not supported
|
|
68
68
|
- Affixes cannot be used with catch-all (`[...slug].png`) or optional catch-all segments
|
|
69
69
|
- Matching is greedy: `[id].png` matching `a.png.png` yields `id = "a.png"`
|
|
70
|
-
- `
|
|
70
|
+
- `app/schema.ts` codecs use the bare bracket form (`[id]`), not the full segment pattern
|
|
71
71
|
|
|
72
72
|
**Priority:** static → affixed dynamic → bare dynamic → catch-all → optional catch-all. A static `foo.png` always wins over `[id].png`.
|
|
73
73
|
|
|
@@ -64,9 +64,9 @@ app/
|
|
|
64
64
|
|
|
65
65
|
**Next.js:** `useSearchParams()` hook returns a `URLSearchParams` object.
|
|
66
66
|
|
|
67
|
-
**timber:** Typed search params via `defineSearchParams` in
|
|
67
|
+
**timber:** Typed search params via `defineSearchParams` in any module you import. Server reads via `.get()`, client reads/writes via `.useQueryStates()`. Segment params are defined globally in `app/schema.ts` via `defineSchema()`, accessed with `getSegmentParams(SEGMENT_PATH)` using the `$segment` module.
|
|
68
68
|
|
|
69
|
-
```ts title="app/products/params.ts"
|
|
69
|
+
```ts title="app/products/search-params.ts"
|
|
70
70
|
import { defineSearchParams } from '@timber-js/app/search-params';
|
|
71
71
|
import { z } from 'zod/v4';
|
|
72
72
|
|
|
@@ -59,7 +59,7 @@ These are the things you will get wrong if you assume Next.js behavior.
|
|
|
59
59
|
| Middleware | Single global `middleware.ts` with matchers | Per-segment `middleware.ts` files + global `proxy.ts`. One-arg signature: `middleware(ctx)`. |
|
|
60
60
|
| `notFound()` | `notFound()` from `next/navigation` | `deny(404)` from `@timber-js/app/server`. Sends a real HTTP 404. |
|
|
61
61
|
| `redirect()` | `redirect()` from `next/navigation` | `redirect()` from `@timber-js/app/server`. Same concept, different import. |
|
|
62
|
-
| Search params | Untyped `useSearchParams()` | Typed `defineSearchParams()` with Zod schemas in
|
|
62
|
+
| Search params | Untyped `useSearchParams()` | Typed `defineSearchParams()` with Zod schemas, in any module you import. |
|
|
63
63
|
| Auth pattern | In middleware or components | `access.ts` per segment with slot degradation. |
|
|
64
64
|
| Forms | `useFormState` / `useFormStatus` | `createActionClient` + `useActionState` returns a 4-tuple. Forms work without JS. |
|
|
65
65
|
|
|
@@ -71,7 +71,7 @@ These are the things you will get wrong if you assume Next.js behavior.
|
|
|
71
71
|
| `Link`, `useRouter`, `usePathname`, `useActionState` | `@timber-js/app/client` |
|
|
72
72
|
| `cache`, `CacheHandler` | `@timber-js/app/cache` |
|
|
73
73
|
| `defineSearchParams` | `@timber-js/app/search-params` |
|
|
74
|
-
| `defineSchema`, `
|
|
74
|
+
| `defineSchema`, `InferCodecType` | `@timber-js/app/params` |
|
|
75
75
|
| Content collection data | `content-collections` |
|
|
76
76
|
| `Metadata` type | `@timber-js/app/server` |
|
|
77
77
|
|
|
@@ -90,7 +90,7 @@ app/ # Route tree — file-system routing
|
|
|
90
90
|
access.ts # Per-segment authorization
|
|
91
91
|
denied.tsx # Rendered when access.ts denies
|
|
92
92
|
error.tsx # Error boundary for this segment
|
|
93
|
-
params.ts
|
|
93
|
+
search-params.ts # Search param definitions (ordinary module, not a convention)
|
|
94
94
|
schema.ts # Segment param schemas (from @timber-js/app/params)
|
|
95
95
|
content/ # Content collections (outside route tree)
|
|
96
96
|
timber.config.ts # Framework configuration
|
|
@@ -104,6 +104,8 @@ content-collections.ts # Collection definitions (optional)
|
|
|
104
104
|
|
|
105
105
|
2. **Adding `'use client'` to everything** — components are server components by default. Only add `'use client'` when you need browser APIs, event handlers, or React hooks like `useState`/`useEffect`.
|
|
106
106
|
|
|
107
|
+
The exception: `error.tsx`, `global-error.tsx`, and component status files (`404.tsx`, `4xx.tsx`, `503.tsx`, …) **always** need `'use client'`. timber passes them to a client error boundary as a prop, so a server component there breaks every page under that segment. The build rejects it and names the file. MDX status files (`404.mdx`) are exempt.
|
|
108
|
+
|
|
107
109
|
3. **Using `fetch()` and expecting caching** — timber never patches `fetch`. Wrap data-fetching functions in `cache.data()` from `@timber-js/app/cache` when you want caching.
|
|
108
110
|
|
|
109
111
|
4. **Creating `loading.tsx` files** — this convention does not exist. Use `<Suspense>` with an explicit fallback where you want streaming.
|
|
@@ -114,7 +116,7 @@ content-collections.ts # Collection definitions (optional)
|
|
|
114
116
|
|
|
115
117
|
7. **Putting all middleware in one file** — middleware is per-segment. Place `middleware.ts` at the route level that matches the concern. Use `proxy.ts` for global concerns.
|
|
116
118
|
|
|
117
|
-
8. **Assuming `useSearchParams()` exists** — use `defineSearchParams()` in
|
|
119
|
+
8. **Assuming `useSearchParams()` exists** — use `defineSearchParams()` in any module with Zod schemas, then access via `.get()` (server) or `.useQueryStates()` (client).
|
|
118
120
|
|
|
119
121
|
## Quick Patterns
|
|
120
122
|
|