@timber-js/app 0.2.0-alpha.195 → 0.2.0-alpha.197
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-CWYtq6ii.js → actions-BS-m5SLv.js} +3 -3
- package/dist/_chunks/{actions-CWYtq6ii.js.map → actions-BS-m5SLv.js.map} +1 -1
- package/dist/_chunks/als-registry-C6kcfprT.js.map +1 -1
- package/dist/_chunks/{build-manifest-DWppEdLB.js → build-manifest-DTmSGLRz.js} +51 -2
- package/dist/_chunks/build-manifest-DTmSGLRz.js.map +1 -0
- package/dist/_chunks/{cache-api-CQeYzA5g.js → cache-api-DqzgTEqk.js} +4 -49
- package/dist/_chunks/cache-api-DqzgTEqk.js.map +1 -0
- package/dist/_chunks/{chains-h7EO-u3n.js → chains-CZG7E5zg.js} +2 -2
- package/dist/_chunks/{chains-h7EO-u3n.js.map → chains-CZG7E5zg.js.map} +1 -1
- package/dist/_chunks/{cli-check-BVthpfLS.js → cli-check-bE3H5Bjr.js} +3 -3
- package/dist/_chunks/{cli-check-BVthpfLS.js.map → cli-check-bE3H5Bjr.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-3Wutm8pH.js → cli-schema-sync-DTy_-Msq.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-3Wutm8pH.js.map → cli-schema-sync-DTy_-Msq.js.map} +1 -1
- package/dist/_chunks/{cloudflare-BKJC3SC_.js → cloudflare-BFb__LYG.js} +2 -2
- package/dist/_chunks/{cloudflare-BKJC3SC_.js.map → cloudflare-BFb__LYG.js.map} +1 -1
- package/dist/_chunks/{convention-lint-DO10_pVl.js → convention-lint-n3RJLgww.js} +2 -2
- package/dist/_chunks/{convention-lint-DO10_pVl.js.map → convention-lint-n3RJLgww.js.map} +1 -1
- package/dist/_chunks/{error-boundary-D-lkwyaD.js → error-boundary-BvRCCmbN.js} +3 -3
- package/dist/_chunks/{error-boundary-D-lkwyaD.js.map → error-boundary-BvRCCmbN.js.map} +1 -1
- package/dist/_chunks/{href-validation-CMc5JRls.js → href-validation-BIrxavIy.js} +74 -2
- package/dist/_chunks/href-validation-BIrxavIy.js.map +1 -0
- package/dist/_chunks/{live-graph-Bx4HodF1.js → live-graph-BXDsdzBv.js} +3 -3
- package/dist/_chunks/{live-graph-Bx4HodF1.js.map → live-graph-BXDsdzBv.js.map} +1 -1
- package/dist/_chunks/{logger-pumCm3Il.js → logger-DDirEsn7.js} +3 -4
- package/dist/_chunks/{logger-pumCm3Il.js.map → logger-DDirEsn7.js.map} +1 -1
- package/dist/_chunks/navigation-root-B00jjGd5.js +233 -0
- package/dist/_chunks/navigation-root-B00jjGd5.js.map +1 -0
- package/dist/_chunks/{segment-context-CjOlyB8Y.js → param-value-C8TNYchQ.js} +2 -33
- package/dist/_chunks/param-value-C8TNYchQ.js.map +1 -0
- package/dist/_chunks/{poison-scan-BAxfTT5L.js → poison-scan-BoDLgbix.js} +2 -2
- package/dist/_chunks/{poison-scan-BAxfTT5L.js.map → poison-scan-BoDLgbix.js.map} +1 -1
- package/dist/_chunks/{router-ref-BzqbPwYC.js → router-ref-8gr8qsxN.js} +2 -2
- package/dist/_chunks/{router-ref-BzqbPwYC.js.map → router-ref-8gr8qsxN.js.map} +1 -1
- package/dist/_chunks/{rsc-cache-key-DD0fl_-s.js → rsc-cache-key-ClUiXQnK.js} +2 -2
- package/dist/_chunks/{rsc-cache-key-DD0fl_-s.js.map → rsc-cache-key-ClUiXQnK.js.map} +1 -1
- package/dist/_chunks/{scanner-BRIOmHE2.js → scanner-tdFPvDYi.js} +174 -7
- package/dist/_chunks/scanner-tdFPvDYi.js.map +1 -0
- package/dist/_chunks/segment-context-D9_89u34.js +34 -0
- package/dist/_chunks/segment-context-D9_89u34.js.map +1 -0
- package/dist/_chunks/singleflight-2lUWfcAk.js +54 -0
- package/dist/_chunks/singleflight-2lUWfcAk.js.map +1 -0
- package/dist/_chunks/{ssr-data-Ya2HJPFp.js → ssr-data-BQGhTPAK.js} +2 -17
- package/dist/_chunks/ssr-data-BQGhTPAK.js.map +1 -0
- package/dist/_chunks/{walkers-BU6z9xRV.js → walkers-DNX05dC0.js} +2 -2
- package/dist/_chunks/{walkers-BU6z9xRV.js.map → walkers-DNX05dC0.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/nitro.d.ts +1 -1
- package/dist/adapters/nitro.d.ts.map +1 -1
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/analyze/crawl-entry.js +2 -2
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cache/index.js +1 -1
- package/dist/cache/singleflight.d.ts +2 -0
- package/dist/cache/singleflight.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/client/browser-entry/hydrate.d.ts +21 -15
- package/dist/client/browser-entry/hydrate.d.ts.map +1 -1
- package/dist/client/browser-entry/index.d.ts +4 -3
- package/dist/client/browser-entry/index.d.ts.map +1 -1
- package/dist/client/browser-entry/post-hydration.d.ts.map +1 -1
- package/dist/client/browser-entry/router-init.d.ts +17 -1
- package/dist/client/browser-entry/router-init.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/global-context.d.ts +15 -0
- package/dist/client/global-context.d.ts.map +1 -0
- package/dist/client/index.js +139 -36
- package/dist/client/index.js.map +1 -1
- package/dist/client/internal.d.ts +0 -1
- package/dist/client/internal.d.ts.map +1 -1
- package/dist/client/internal.js +206 -55
- package/dist/client/internal.js.map +1 -1
- package/dist/client/link.d.ts.map +1 -1
- package/dist/client/location-search.d.ts +12 -0
- package/dist/client/location-search.d.ts.map +1 -0
- package/dist/client/navigation-api.d.ts.map +1 -1
- package/dist/client/navigation-commit.d.ts +18 -0
- package/dist/client/navigation-commit.d.ts.map +1 -1
- package/dist/client/navigation-context.d.ts +13 -11
- package/dist/client/navigation-context.d.ts.map +1 -1
- package/dist/client/navigation-root.d.ts +47 -108
- package/dist/client/navigation-root.d.ts.map +1 -1
- package/dist/client/navigation-transition.d.ts +136 -0
- package/dist/client/navigation-transition.d.ts.map +1 -0
- package/dist/client/nuqs-adapter.d.ts.map +1 -1
- package/dist/client/params-context.d.ts +4 -5
- package/dist/client/params-context.d.ts.map +1 -1
- package/dist/client/react-root.d.ts +44 -0
- package/dist/client/react-root.d.ts.map +1 -0
- package/dist/client/router-pipeline.d.ts +2 -2
- package/dist/client/router-pipeline.d.ts.map +1 -1
- package/dist/client/router-types.d.ts +12 -2
- package/dist/client/router-types.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/client/segment-cache.d.ts +39 -0
- package/dist/client/segment-cache.d.ts.map +1 -1
- package/dist/client/segment-context.d.ts.map +1 -1
- package/dist/client/segment-outlet.d.ts +25 -14
- package/dist/client/segment-outlet.d.ts.map +1 -1
- package/dist/client/segment-update-context.d.ts +3 -9
- package/dist/client/segment-update-context.d.ts.map +1 -1
- package/dist/client/slot-content-cache-context.d.ts +35 -0
- package/dist/client/slot-content-cache-context.d.ts.map +1 -0
- package/dist/client/ssr-data.d.ts +8 -2
- package/dist/client/ssr-data.d.ts.map +1 -1
- package/dist/client/state.d.ts +0 -15
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/use-pathname.d.ts +13 -11
- package/dist/client/use-pathname.d.ts.map +1 -1
- package/dist/client/use-search-params.d.ts +13 -13
- package/dist/client/use-search-params.d.ts.map +1 -1
- package/dist/client/use-segment-params.d.ts +18 -68
- package/dist/client/use-segment-params.d.ts.map +1 -1
- package/dist/config-types.d.ts +17 -0
- package/dist/config-types.d.ts.map +1 -1
- package/dist/config-validation.d.ts.map +1 -1
- package/dist/cookies/index.js +1 -1
- package/dist/dev-tools/holding-server.d.ts +15 -10
- package/dist/dev-tools/holding-server.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -43
- package/dist/index.js.map +1 -1
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/shims.d.ts.map +1 -1
- package/dist/plugins/static-build.d.ts +2 -2
- package/dist/plugins/static-build.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/routing/interception-overlap.d.ts +35 -0
- package/dist/routing/interception-overlap.d.ts.map +1 -0
- package/dist/routing/interception.d.ts.map +1 -1
- package/dist/rsc-runtime/ssr.d.ts +3 -1
- package/dist/rsc-runtime/ssr.d.ts.map +1 -1
- package/dist/server/als-registry.d.ts +6 -0
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/csp-nonce.d.ts +45 -0
- package/dist/server/csp-nonce.d.ts.map +1 -0
- package/dist/server/default-status-page.d.ts.map +1 -1
- package/dist/server/deny-renderer.d.ts.map +1 -1
- package/dist/server/flight-scripts.d.ts +5 -2
- package/dist/server/flight-scripts.d.ts.map +1 -1
- package/dist/server/html-injector-core.d.ts +17 -2
- package/dist/server/html-injector-core.d.ts.map +1 -1
- package/dist/server/html-injectors.d.ts +3 -2
- package/dist/server/html-injectors.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/internal.js +86 -37
- package/dist/server/internal.js.map +1 -1
- package/dist/server/metadata-render.d.ts.map +1 -1
- package/dist/server/node-stream-transforms.d.ts +3 -17
- package/dist/server/node-stream-transforms.d.ts.map +1 -1
- package/dist/server/nuqs-ssr-provider.d.ts +7 -3
- package/dist/server/nuqs-ssr-provider.d.ts.map +1 -1
- package/dist/server/pipeline-phases.d.ts.map +1 -1
- package/dist/server/prebuilt/key-discipline.d.ts +32 -3
- package/dist/server/prebuilt/key-discipline.d.ts.map +1 -1
- package/dist/server/primitives.d.ts.map +1 -1
- package/dist/server/render-utils.d.ts +4 -3
- package/dist/server/render-utils.d.ts.map +1 -1
- package/dist/server/rsc-entry/action-middleware-runner.d.ts.map +1 -1
- package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
- package/dist/server/ssr-bridge-types.d.ts +22 -2
- package/dist/server/ssr-bridge-types.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/ssr-render.d.ts +5 -1
- package/dist/server/ssr-render.d.ts.map +1 -1
- package/dist/server/ssr-wrappers.d.ts +59 -27
- package/dist/server/ssr-wrappers.d.ts.map +1 -1
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shims/navigation-rsc.d.ts +21 -0
- package/dist/shims/navigation-rsc.d.ts.map +1 -0
- package/docs/api/30-api-server.mdx +1 -0
- package/docs/api/35-api-typescript.mdx +4 -83
- package/docs/learn/03-fetching-data.mdx +1 -1
- package/docs/learn/{03b-access-control.mdx → 04-access-control.mdx} +2 -17
- package/docs/learn/05-the-flush-point.mdx +175 -0
- package/docs/learn/{05-typed-params.mdx → 06-typed-params.mdx} +1 -1
- package/docs/learn/07-typed-routes.mdx +25 -49
- package/docs/learn/{08-streaming.mdx → 09-streaming.mdx} +1 -7
- package/docs/learn/{10-middleware.mdx → 11-middleware.mdx} +1 -0
- package/package.json +3 -3
- package/src/adapters/nitro.ts +7 -7
- package/src/cache/singleflight.ts +5 -0
- package/src/client/browser-entry/hydrate.ts +54 -104
- package/src/client/browser-entry/index.ts +16 -6
- package/src/client/browser-entry/post-hydration.ts +3 -2
- package/src/client/browser-entry/router-init.ts +84 -33
- package/src/client/global-context.ts +31 -0
- package/src/client/internal.ts +1 -2
- package/src/client/link.tsx +25 -19
- package/src/client/location-search.ts +15 -0
- package/src/client/navigation-api.ts +4 -2
- package/src/client/navigation-commit.ts +48 -2
- package/src/client/navigation-context.ts +25 -37
- package/src/client/navigation-root.tsx +55 -411
- package/src/client/navigation-transition.ts +278 -0
- package/src/client/nuqs-adapter.tsx +4 -5
- package/src/client/params-context.ts +13 -18
- package/src/client/react-root.ts +72 -0
- package/src/client/router-lifecycle.ts +1 -1
- package/src/client/router-pipeline.ts +96 -22
- package/src/client/router-types.ts +12 -2
- package/src/client/router.ts +48 -36
- package/src/client/segment-cache.ts +70 -2
- package/src/client/segment-context.ts +7 -4
- package/src/client/segment-outlet.tsx +41 -86
- package/src/client/segment-update-context.ts +7 -26
- package/src/client/slot-content-cache-context.ts +43 -0
- package/src/client/ssr-data.ts +8 -2
- package/src/client/state.ts +0 -26
- package/src/client/use-pathname.ts +21 -31
- package/src/client/use-search-params.ts +31 -29
- package/src/client/use-segment-params.ts +27 -126
- package/src/config-types.ts +17 -0
- package/src/config-validation.ts +17 -0
- package/src/dev-tools/holding-server.ts +23 -12
- package/src/index.ts +26 -11
- package/src/plugins/dev-server.ts +9 -12
- package/src/plugins/entries.ts +3 -0
- package/src/plugins/shims.ts +8 -7
- package/src/plugins/static-build.ts +9 -5
- package/src/routing/interception-overlap.ts +141 -0
- package/src/routing/interception.ts +118 -5
- package/src/rsc-runtime/ssr.ts +3 -2
- package/src/server/als-registry.ts +6 -0
- package/src/server/csp-nonce.ts +70 -0
- package/src/server/default-status-page.ts +1 -0
- package/src/server/deny-renderer.ts +7 -3
- package/src/server/flight-scripts.ts +9 -4
- package/src/server/html-injector-core.ts +26 -9
- package/src/server/html-injectors.ts +8 -8
- package/src/server/metadata-render.ts +26 -4
- package/src/server/node-stream-transforms.ts +7 -20
- package/src/server/nuqs-ssr-provider.tsx +8 -7
- package/src/server/pipeline-phases.ts +5 -0
- package/src/server/prebuilt/key-discipline.ts +82 -13
- package/src/server/prebuilt-runtime.ts +2 -2
- package/src/server/primitives.ts +4 -4
- package/src/server/render-utils.ts +8 -4
- package/src/server/rsc-entry/action-middleware-runner.ts +7 -0
- package/src/server/rsc-entry/error-renderer.ts +5 -2
- package/src/server/rsc-entry/index.ts +8 -0
- package/src/server/rsc-entry/ssr-renderer.ts +11 -4
- package/src/server/ssr-bridge-types.ts +22 -2
- package/src/server/ssr-entry.ts +35 -28
- package/src/server/ssr-render.ts +13 -4
- package/src/server/ssr-wrappers.tsx +81 -61
- package/src/server/types.ts +10 -0
- package/src/shared/slot-params.ts +3 -4
- package/src/shims/navigation-rsc.ts +47 -0
- package/dist/_chunks/build-manifest-DWppEdLB.js.map +0 -1
- package/dist/_chunks/cache-api-CQeYzA5g.js.map +0 -1
- package/dist/_chunks/href-validation-CMc5JRls.js.map +0 -1
- package/dist/_chunks/scanner-BRIOmHE2.js.map +0 -1
- package/dist/_chunks/segment-context-CjOlyB8Y.js.map +0 -1
- package/dist/_chunks/slot-params-BCTmZkQB.js +0 -76
- package/dist/_chunks/slot-params-BCTmZkQB.js.map +0 -1
- package/dist/_chunks/ssr-data-Ya2HJPFp.js.map +0 -1
- package/dist/_chunks/use-segment-params-DzTBpkvj.js +0 -398
- package/dist/_chunks/use-segment-params-DzTBpkvj.js.map +0 -1
- package/docs/learn/04-loading-states.mdx +0 -67
- package/docs/learn/04b-the-flush-point.mdx +0 -115
- package/docs/learn/12-client-navigation.mdx +0 -176
- package/docs/learn/13-configuration.mdx +0 -166
- package/docs/more/01-advanced-routing.mdx +0 -344
- package/docs/more/02-advanced-forms.mdx +0 -137
- package/docs/more/03-coming-from-nextjs.mdx +0 -186
- package/docs/more/04-metadata-and-fonts.mdx +0 -193
- package/docs/more/04b-mdx.mdx +0 -229
- package/docs/more/05-content-collections.mdx +0 -90
- package/docs/more/06-instrumentation.mdx +0 -214
- package/docs/more/07-security.mdx +0 -129
- package/docs/more/08-developer-experience.mdx +0 -134
- package/docs/more/40-why-timber.mdx +0 -50
- package/docs/more/41-timber-vs-nextjs.mdx +0 -81
- package/docs/more/42-timber-vs-others.mdx +0 -68
- package/docs/more/50-ai-agent-instructions.mdx +0 -171
- /package/docs/learn/{06-forms-and-actions.mdx → 08-forms-and-actions.mdx} +0 -0
- /package/docs/learn/{09-caching.mdx → 10-caching.mdx} +0 -0
- /package/docs/learn/{11-error-handling.mdx → 12-error-handling.mdx} +0 -0
- /package/docs/learn/{14-deploying.mdx → 13-deploying.mdx} +0 -0
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Advanced Routing'
|
|
3
|
-
description: 'Route groups, parallel routes (slots), intercepting routes, catch-all segments, affixed dynamic segments, and API routes.'
|
|
4
|
-
slug: 'advanced-routing'
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Advanced Routing
|
|
8
|
-
|
|
9
|
-
This page covers routing patterns beyond the basics in [Pages and Layouts](/docs/pages-and-layouts). It assumes you understand `page.tsx`, `layout.tsx`, and nesting.
|
|
10
|
-
|
|
11
|
-
## Dynamic Segments
|
|
12
|
-
|
|
13
|
-
Wrap a directory name in brackets to capture a URL parameter:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
app/
|
|
17
|
-
products/
|
|
18
|
-
[id]/
|
|
19
|
-
page.tsx # /products/42, /products/abc
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Access the param with `getSegmentParams(SEGMENT_PATH)` using the `$segment` module — see [Typed Params](/docs/typed-params) for the full codec system.
|
|
23
|
-
|
|
24
|
-
## Catch-All Segments
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
app/docs/[...slug]/page.tsx # /docs/a, /docs/a/b, /docs/a/b/c
|
|
28
|
-
app/docs/[[...slug]]/page.tsx # Same, plus /docs (zero segments)
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
With optional catch-all segments (`[[...slug]]`), the param is `undefined` when no segments match — not an empty array:
|
|
32
|
-
|
|
33
|
-
| URL | `slug` value |
|
|
34
|
-
| ------------- | ----------------- |
|
|
35
|
-
| `/docs` | `undefined` |
|
|
36
|
-
| `/docs/intro` | `['intro']` |
|
|
37
|
-
| `/docs/a/b/c` | `['a', 'b', 'c']` |
|
|
38
|
-
|
|
39
|
-
### Not Supported: Optional Single Segments
|
|
40
|
-
|
|
41
|
-
timber does not support `[[foo]]` (optional single dynamic segment). Use `[[...foo]]` and check `slug?.[0]`, or create two separate pages:
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
app/blog/page.tsx # /blog (index)
|
|
45
|
-
app/blog/[year]/page.tsx # /blog/2024 (filtered)
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Affixed Dynamic Segments
|
|
49
|
-
|
|
50
|
-
Dynamic segments can have literal prefixes and/or suffixes:
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
app/
|
|
54
|
-
images/
|
|
55
|
-
[id].png/
|
|
56
|
-
route.ts # /images/123.png → id = "123"
|
|
57
|
-
user-[name]/
|
|
58
|
-
page.tsx # /user-alice → name = "alice"
|
|
59
|
-
img-[id].webp/
|
|
60
|
-
page.tsx # /img-photo.webp → id = "photo"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
This is useful for CDN-cacheable file-extension routes (e.g. image generation endpoints) and prefixed slugs. The literal parts must match exactly; the dynamic middle is extracted as the param value.
|
|
64
|
-
|
|
65
|
-
**Rules:**
|
|
66
|
-
- The param must be non-empty — `img-[id].png` does NOT match `img-.png`
|
|
67
|
-
- One param per segment — `[foo]-[bar]` is not supported
|
|
68
|
-
- Affixes cannot be used with catch-all (`[...slug].png`) or optional catch-all segments
|
|
69
|
-
- Matching is greedy: `[id].png` matching `a.png.png` yields `id = "a.png"`
|
|
70
|
-
- `app/schema.ts` codecs use the bare bracket form (`[id]`), not the full segment pattern
|
|
71
|
-
|
|
72
|
-
**Priority:** static → affixed dynamic → bare dynamic → catch-all → optional catch-all. A static `foo.png` always wins over `[id].png`.
|
|
73
|
-
|
|
74
|
-
`<Link>` interpolates affixed segments automatically:
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
<Link href="/images/[id].png" segmentParams={{ id: 'photo' }}>
|
|
78
|
-
{/* renders href="/images/photo.png" */}
|
|
79
|
-
</Link>
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Parallel Routes (Slots)
|
|
83
|
-
|
|
84
|
-
Directories prefixed with `@` are slots — they render simultaneously within a parent layout:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
app/
|
|
88
|
-
dashboard/
|
|
89
|
-
layout.tsx # Receives { children, sidebar }
|
|
90
|
-
page.tsx # Renders as children
|
|
91
|
-
@sidebar/
|
|
92
|
-
page.tsx # Renders as sidebar prop
|
|
93
|
-
default.tsx # Fallback when no match
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
```tsx title="app/dashboard/layout.tsx"
|
|
97
|
-
export default function DashboardLayout({
|
|
98
|
-
children,
|
|
99
|
-
sidebar,
|
|
100
|
-
}: {
|
|
101
|
-
children: React.ReactNode;
|
|
102
|
-
sidebar: React.ReactNode;
|
|
103
|
-
}) {
|
|
104
|
-
return (
|
|
105
|
-
<div className="flex">
|
|
106
|
-
<aside className="w-64">{sidebar}</aside>
|
|
107
|
-
<main className="flex-1">{children}</main>
|
|
108
|
-
</div>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Slots don't add URL depth. Each slot independently matches the current URL and can have its own `access.ts`, `error.tsx`, and layouts. If a slot's access check fails, the slot degrades gracefully — the rest of the page is unaffected (see [Access Control](/docs/access-control)).
|
|
114
|
-
|
|
115
|
-
**A slot cannot be nested inside another slot.** Slots are resolved for segments on the matched route chain, and a slot's own subtree is not on that chain — so a nested slot could never render, and the build rejects it:
|
|
116
|
-
|
|
117
|
-
```
|
|
118
|
-
app/dashboard/layout.tsx ← receives { children, sidebar }
|
|
119
|
-
app/dashboard/@sidebar/page.tsx ✓
|
|
120
|
-
app/dashboard/settings/layout.tsx ← receives { children, panel }
|
|
121
|
-
app/dashboard/settings/@panel/page.tsx ✓ a second slot deeper on the main chain
|
|
122
|
-
app/dashboard/@sidebar/@panel/page.tsx ✗ build error — nested inside @sidebar
|
|
123
|
-
app/dashboard/@sidebar/settings/@panel/... ✗ build error — same, further down
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
This is a build error rather than a documented limit because nothing at request time could tell you: a slot that never rendered looks exactly like a slot that simply didn't match. Put the second slot on a segment of the main route chain instead.
|
|
127
|
-
|
|
128
|
-
Note the `layout.tsx` beside each slot. A slot is handed to its owning segment's layout as a named prop, so **the owner must have one** — `app/dashboard/@sidebar/` with no `app/dashboard/layout.tsx` has nothing to be passed to and never renders. That case is dead in the same way as a nested slot, and the build does not currently catch it.
|
|
129
|
-
|
|
130
|
-
Each slot is also its own collision space: a slot page sharing a URL with the parent page is the point of parallel routes, but two pages inside one slot that answer the same URL (`@side/(a)/x/page.tsx` + `@side/(b)/x/page.tsx`) fail the build, just like the same collision outside a slot. Interceptors that start at the same URL are their own space on the same principle — see [Intercepting routes](#intercepting-routes).
|
|
131
|
-
|
|
132
|
-
Every collision space is checked the same way: routes are compared by the URLs they match rather than by how they are spelled, so `(a)/[id]` and `(b)/[slug]` collide even though their paths read differently, and a page collides with an optional catch-all beside it because `[[...rest]]` also matches with zero segments. Segment kinds stay distinct — `[id]` beside `[...rest]`, or an affixed `img-[id]` beside a bare `[slug]`, are ordered deterministically and keep building.
|
|
133
|
-
|
|
134
|
-
## Intercepting Routes
|
|
135
|
-
|
|
136
|
-
Intercepting routes show a different component on soft navigation (client-side link click) vs hard navigation (direct URL).
|
|
137
|
-
|
|
138
|
-
| Marker | Meaning |
|
|
139
|
-
| ---------- | ------------- |
|
|
140
|
-
| `(.)` | Same level |
|
|
141
|
-
| `(..)` | One level up |
|
|
142
|
-
| `(..)(..)` | Two levels up |
|
|
143
|
-
| `(...)` | Root level |
|
|
144
|
-
|
|
145
|
-
Where you put the intercepting directory picks between two behaviours.
|
|
146
|
-
|
|
147
|
-
**Inside a parallel slot → modal overlay.** The slot renders the intercepting page on top; the page you came from stays mounted behind it.
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
app/feed/@modal/(.)photo/[id]/page.tsx ← soft nav: modal over the feed
|
|
151
|
-
app/feed/photo/[id]/page.tsx ← hard nav: the full page
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**As a plain child of a segment or route group → sibling layout swap.** No overlay and no slot: the intercepting page replaces the content of *its own* directory's layout chain. This is how two route groups can serve one URL with different layouts.
|
|
155
|
-
|
|
156
|
-
```
|
|
157
|
-
app/(landing)/layout.tsx
|
|
158
|
-
app/(landing)/[artistSlug]/[year]/page.tsx ← hard nav renders this
|
|
159
|
-
app/(browse)/layout.tsx
|
|
160
|
-
app/(browse)/(...)[artistSlug]/[year]/page.tsx ← soft nav from inside (browse) renders this
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Navigate directly to `/grateful-dead/1977` and you get `(landing)`'s page under `(landing)`'s layout. Click a link to it from anywhere inside `(browse)` and you stay in `(browse)`'s layout with the intercepting page beneath it. Unlike the modal shape, the intercepting page's params come from the URL you navigated to, so `getSegmentParams()` works exactly as it does on a canonical route.
|
|
164
|
-
|
|
165
|
-
An intercepting directory must be a **direct** child of one or the other. A marker one directory deeper inside a slot, or nested inside another intercepting subtree, would match the navigation and then have nothing to render — the build fails naming the directory rather than silently serving the wrong page.
|
|
166
|
-
|
|
167
|
-
```
|
|
168
|
-
app/feed/@modal/(.)photo/[id]/page.tsx ✓ modal overlay
|
|
169
|
-
app/feed/(.)photo/[id]/page.tsx ✓ layout swap (feed/layout.tsx required)
|
|
170
|
-
app/(browse)/(...)photo/[id]/page.tsx ✓ layout swap, scoped to (browse)
|
|
171
|
-
app/feed/@modal/(x)/(.)photo/page.tsx ✗ build error — not a direct slot child
|
|
172
|
-
app/feed/(.)a/(.)b/page.tsx ✗ build error — nested interception
|
|
173
|
-
app/feed/@modal/(.)photo/[id]/route.ts ✗ build error — route handler in interception
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Outside a slot, the directory holding the marker must have a `layout.tsx`. That is the directory the swap is scoped to, and the browser reports which directories it has mounted from its layouts — a scope it cannot report would let the swap fire once and then quietly stop. In practice you already have one, since rendering inside that layout is the point.
|
|
177
|
-
|
|
178
|
-
```
|
|
179
|
-
app/(browse)/layout.tsx ✓ required
|
|
180
|
-
app/(browse)/(...)photo/[id]/page.tsx
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
Also outside a slot, every directory above the marker must be a static segment or a route group. The swapped page renders its own layouts against the URL you navigated to, and that URL carries no values for params declared above the marker — so a dynamic ancestor is a build error rather than a layout that renders with a missing param. Put the same interception in a slot if you need one: the modal shape re-matches the source route, which supplies them.
|
|
184
|
-
|
|
185
|
-
```
|
|
186
|
-
app/(browse)/(...)photo/[id]/page.tsx ✓
|
|
187
|
-
app/docs/guides/(.)[id]/page.tsx ✓
|
|
188
|
-
app/[team]/(..)photo/[id]/page.tsx ✗ build error — [team] is above the marker
|
|
189
|
-
app/[team]/@modal/(.)photo/[id]/page.tsx ✓ a slot supplies [team] from the source route
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
Two pages that intercept the same URL are a build error when both sit under interceptors that **start at the same URL** — the set timber resolves in one pass. Route groups are transparent here just as they are elsewhere, so two of them under one marker both claim the same target; and two markers that compute the same starting point are the same case one level up. Either way, which page renders would come down to the order the filesystem happens to list them in.
|
|
193
|
-
|
|
194
|
-
Pages are compared by the URLs they match, not by how you spell them — so param names don't make two dynamic segments different, and an optional catch-all also matches with *zero* segments.
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
app/feed/(.)photo/(a)/page.tsx ✗ build error — both intercept /feed/photo
|
|
198
|
-
app/feed/(.)photo/(b)/page.tsx
|
|
199
|
-
|
|
200
|
-
app/feed/(.)photo/(a)/[id]/page.tsx ✗ build error — [id] and [slug] match the same URLs
|
|
201
|
-
app/feed/(.)photo/(b)/[slug]/page.tsx
|
|
202
|
-
|
|
203
|
-
app/feed/(.)photo/(a)/page.tsx ✗ build error — [[...rest]] also matches zero segments,
|
|
204
|
-
app/feed/(.)photo/(b)/[[...rest]]/page.tsx so it claims /feed/photo too
|
|
205
|
-
|
|
206
|
-
app/feed/(.)photo/page.tsx ✓ a page plus a tail — the page always wins
|
|
207
|
-
app/feed/(.)photo/[[...rest]]/page.tsx /feed/photo, the catch-all takes the rest
|
|
208
|
-
|
|
209
|
-
app/feed/(.)photo/(x)/a/page.tsx ✓ different URLs
|
|
210
|
-
app/feed/(.)photo/(y)/b/page.tsx
|
|
211
|
-
|
|
212
|
-
app/feed/(.)photo/(x)/[id]/page.tsx ✓ different kinds — a single segment always
|
|
213
|
-
app/feed/(.)photo/(y)/[...rest]/page.tsx beats a catch-all, so this is unambiguous
|
|
214
|
-
|
|
215
|
-
app/feed/@modal/(.)[a]/page.tsx ✗ build error — two markers, one starting point,
|
|
216
|
-
app/feed/@modal/(.)[b]/page.tsx same kind: nothing separates them
|
|
217
|
-
|
|
218
|
-
app/feed/@modal/(.)photo/[id]/page.tsx ✓ same starting point, different kinds — the
|
|
219
|
-
app/feed/@modal/(.)[albumSlug]/page.tsx literal `photo` wins, everything else the second
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
A route group is transparent for matching, so putting a page inside one does not give it a URL of its own:
|
|
223
|
-
|
|
224
|
-
```
|
|
225
|
-
app/feed/(.)photo/page.tsx ✗ build error — both are /feed/photo, so the
|
|
226
|
-
app/feed/(.)photo/(a)/page.tsx one in the group could never render
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
Interceptors that start at **different** URLs stay legal even when they target one page — `(.)x` beside `(..)x`, or interceptors in two different slots. Those are separate spaces, and the resolver orders them (deepest marker first).
|
|
230
|
-
|
|
231
|
-
### Dynamic intercepted segments
|
|
232
|
-
|
|
233
|
-
The marker is a prefix on an ordinary segment name, so the name after it uses the same bracket syntax as anywhere else:
|
|
234
|
-
|
|
235
|
-
```
|
|
236
|
-
app/gallery/@modal/(.)photo/[id]/page.tsx # intercepts /gallery/photo/{id}
|
|
237
|
-
app/gallery/@modal/(.)[albumSlug]/page.tsx # intercepts /gallery/{albumSlug}
|
|
238
|
-
app/gallery/@modal/(.)[...rest]/page.tsx # intercepts the whole tail
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
Intercepting siblings in one slot follow the usual priority — static, then dynamic, then catch-all — so `(.)photo/[id]` and `(.)[albumSlug]` can live in the same `@modal` without ambiguity.
|
|
242
|
-
|
|
243
|
-
Two affixed interceptors are the one case priority cannot separate: `(.)a-[id]` and `(.)[slug]-b` both match `/gallery/a-b` with the same combined affix length, so which modal opened would come down to filesystem order. That fails the build, exactly as it does for ordinary affixed siblings.
|
|
244
|
-
|
|
245
|
-
One placement fails the build: an interception whose intercepted level lands below a catch-all. Markers count URL segments, and a catch-all matches a number of them that changes per request, so "same level as `/docs/[...path]`" has no fixed position in `/docs/a/b/c`. Such an interception would fire only when the catch-all consumed exactly one segment and be silently dropped otherwise, so timber names the directory in a build error instead. Climbing past the catch-all avoids it:
|
|
246
|
-
|
|
247
|
-
```
|
|
248
|
-
app/docs/[...path]/@modal/(.)photo/[id]/page.tsx ✗ build error
|
|
249
|
-
app/docs/[...path]/@modal/(..)photo/[id]/page.tsx ✓ (..) climbs past it, basing at /docs
|
|
250
|
-
app/docs/[...path]/@modal/(...)photo/[id]/page.tsx ✓ (...) bases at the root
|
|
251
|
-
app/[artistSlug]/@modal/(.)photo/[id]/page.tsx ✓ a dynamic segment is one URL part
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
A catch-all inside an intercepting route must also be the last segment — nothing below a catch-all can ever match, and the rewrite generated for the unreachable page would hijack the navigation with nothing to render:
|
|
255
|
-
|
|
256
|
-
```
|
|
257
|
-
app/feed/@modal/(.)[...rest]/page.tsx ✓
|
|
258
|
-
app/feed/@modal/(.)photo/[...rest]/page.tsx ✓
|
|
259
|
-
app/feed/@modal/(.)[...rest]/child/page.tsx ✗ build error — child is unreachable
|
|
260
|
-
app/feed/@modal/(.)photo/[...rest]/child/page.tsx ✗ build error — same, one level down
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
### Params in intercepting directories
|
|
264
|
-
|
|
265
|
-
A dynamic intercepted segment binds a param like any other, so the ordinary param rules apply to it:
|
|
266
|
-
|
|
267
|
-
```
|
|
268
|
-
app/feed/@modal/(.)[id]/[id]/page.tsx ✗ build error — duplicate param name
|
|
269
|
-
app/feed/@modal/(.)[albumSlug]/[id]/... ✓
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Params inside an intercepting page
|
|
273
|
-
|
|
274
|
-
This section is about the **modal** shape. A layout-swap interception has nothing special going on: its chain is the main route, so `getSegmentParams()` returns the URL's params everywhere in it, exactly as on a canonical route.
|
|
275
|
-
|
|
276
|
-
Inside a slot, `getSegmentParams()` returns **the intercepted route's** params — what the page's own directories declare:
|
|
277
|
-
|
|
278
|
-
```tsx title="app/gallery/@modal/(.)photo/[id]/page.tsx"
|
|
279
|
-
export default async function PhotoModal() {
|
|
280
|
-
const { id } = getSegmentParams(); // the photo's id, not the gallery's params
|
|
281
|
-
return <Modal photo={await getPhoto(id)} />;
|
|
282
|
-
}
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
That is worth stating because the request itself is matched against the *source* route (`/gallery`) — the page still rendering behind the modal. The modal's own params are scoped to it, and the source page underneath keeps reading its own.
|
|
286
|
-
|
|
287
|
-
This is the general slot rule: inside a parallel slot, a no-arg `getSegmentParams()` returns that slot's own params merged over the main route's — the same value as passing the slot's segment path explicitly. Params the slot re-derives win, so a slot that reads a URL part as `[...year]` gets `string[]` even when the main route read it as `[year]`.
|
|
288
|
-
|
|
289
|
-
### Scope
|
|
290
|
-
|
|
291
|
-
An interception fires only when the departing page renders the directory that owns it — the slot's parent for a modal, the marker's own parent for a layout swap. For `app/feed/@modal/(.)photo/`, that directory is `/feed`: clicking a photo link from `/feed` or `/feed/trending` opens the modal; clicking one from `/settings` does not.
|
|
292
|
-
|
|
293
|
-
Route groups count here even though they are invisible in the URL. Anything owned by `app/(browse)/` is scoped to `(browse)`, so a navigation starting in a sibling `(landing)` group renders the normal route, not the interception — that is what makes the layout-swap shape work. A directory at the app root is scoped to the root, which every page renders, which is why `(...)` at the root intercepts from anywhere.
|
|
294
|
-
|
|
295
|
-
**When two interceptions both apply, the innermost one wins.** A directory and a directory beneath it may each hold a marker for the same URL, and a page inside the inner one renders both — so `app/feed/(.)photo/` and `app/feed/(a)/(.)photo/` both qualify for a click made inside `(a)`. The one scoped to `(a)` renders, on the same reasoning that a `(.)` marker beats a `(...)` one beside it: the more local directory is the more specific statement. Directories that are *not* on one chain — `(a)` beside `(b)` — never both qualify, so they stay independent.
|
|
296
|
-
|
|
297
|
-
Because scope depends on where the click starts, so does a prefetch: `<Link prefetch>` fetches the variant for the page the link is on, and the cached payload is only used by a click that starts there. Hovering an intercepting link gets you the modal; the same URL prefetched from elsewhere stays the full page.
|
|
298
|
-
|
|
299
|
-
## API Routes
|
|
300
|
-
|
|
301
|
-
Export HTTP method handlers from `route.ts`:
|
|
302
|
-
|
|
303
|
-
```ts title="app/api/hello/route.ts"
|
|
304
|
-
export async function GET(ctx: RouteContext) {
|
|
305
|
-
return Response.json({ message: 'Hello' });
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export async function POST(ctx: RouteContext) {
|
|
309
|
-
const body = await ctx.request.json();
|
|
310
|
-
return Response.json({ received: body });
|
|
311
|
-
}
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
## The Segment Tree
|
|
315
|
-
|
|
316
|
-
Every directory in your `app/` directory is a **segment**. Segments nest into a tree that connects your URL structure, component structure, and HTML structure:
|
|
317
|
-
|
|
318
|
-
| Concern | Segment mapping |
|
|
319
|
-
| ----------------- | ------------------------------------------------------------- |
|
|
320
|
-
| URL matching | Each segment consumes URL segments (except groups and slots) |
|
|
321
|
-
| Params | Dynamic segments extract params, accumulate top-down |
|
|
322
|
-
| Authorization | `access.ts` per segment, top-down, shallowest failure wins |
|
|
323
|
-
| Layouts | `layout.tsx` per segment, persist across navigation |
|
|
324
|
-
| Streaming | `<Suspense>` placement controls flush boundary per segment |
|
|
325
|
-
| Error handling | `error.tsx` / status files per segment, leaf-to-root fallback |
|
|
326
|
-
| Client navigation | Segment cache mirrors the tree, skips mounted sync layouts |
|
|
327
|
-
| Slot isolation | `@slot` branches render independently, fail gracefully |
|
|
328
|
-
|
|
329
|
-
## The Request Lifecycle
|
|
330
|
-
|
|
331
|
-
``` leading="none"
|
|
332
|
-
Request
|
|
333
|
-
├── URL canonicalization
|
|
334
|
-
├── proxy.ts (global — every request)
|
|
335
|
-
├── Route matching
|
|
336
|
-
├── Param coercion (schema.ts codecs)
|
|
337
|
-
├── middleware.ts chain (root → leaf)
|
|
338
|
-
└── Single renderToReadableStream call
|
|
339
|
-
Root Segment → AccessGate → Layout
|
|
340
|
-
Child Segment → AccessGate → Layout
|
|
341
|
-
Leaf Segment → Page
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
The entire route renders in a **single `renderToReadableStream` call**. One React tree, one `React.cache` scope.
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Advanced Forms'
|
|
3
|
-
description: 'Coercion helpers, parseFormData, form flash internals, and sensitive field stripping.'
|
|
4
|
-
slug: 'advanced-forms'
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Advanced Forms
|
|
8
|
-
|
|
9
|
-
This page covers advanced form patterns beyond [Forms and Actions](/docs/forms-and-actions): coercion helpers, raw FormData parsing, form flash internals, and sensitive field stripping.
|
|
10
|
-
|
|
11
|
-
## Coercing FormData Values
|
|
12
|
-
|
|
13
|
-
HTML forms send everything as strings. Use `coerce` helpers to convert FormData values before schema validation:
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import { coerce } from '@timber-js/app/server';
|
|
17
|
-
import { z } from 'zod/v4';
|
|
18
|
-
|
|
19
|
-
const eventSchema = z.object({
|
|
20
|
-
title: z.string().min(1),
|
|
21
|
-
maxAttendees: z.preprocess(coerce.number, z.number().min(1)),
|
|
22
|
-
isPublic: z.preprocess(coerce.checkbox, z.boolean()),
|
|
23
|
-
date: z.preprocess(coerce.date, z.date()),
|
|
24
|
-
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
| Helper | Input | Output |
|
|
28
|
-
| ----------------- | ------------------- | ------------------- |
|
|
29
|
-
| `coerce.number` | `"42"`, `""` | `42`, `undefined` |
|
|
30
|
-
| `coerce.checkbox` | `"on"`, `undefined` | `true`, `false` |
|
|
31
|
-
| `coerce.json` | `'{"a":1}'` | `{ a: 1 }` |
|
|
32
|
-
| `coerce.date` | `"2024-01-15"` | `Date` |
|
|
33
|
-
| `coerce.file` | `File`, empty input | `File`, `undefined` |
|
|
34
|
-
|
|
35
|
-
`coerce.file` accepts options for validation:
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
z.preprocess(
|
|
39
|
-
coerce.file({ maxSize: 5 * 1024 * 1024, accept: ['image/png', 'image/jpeg'] }),
|
|
40
|
-
z.instanceof(File)
|
|
41
|
-
);
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## `parseFormData`
|
|
45
|
-
|
|
46
|
-
For advanced cases, `parseFormData` converts raw `FormData` into a plain object before schema validation:
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
import { parseFormData } from '@timber-js/app/server';
|
|
50
|
-
|
|
51
|
-
const obj = parseFormData(formData);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
It handles common patterns:
|
|
55
|
-
|
|
56
|
-
- **Duplicate keys → arrays**: `tags=js&tags=ts` → `{ tags: ["js", "ts"] }`
|
|
57
|
-
- **Dot-path nesting**: `user.name=Alice` → `{ user: { name: "Alice" } }`
|
|
58
|
-
- **Empty strings → undefined**: Enables `.optional()` semantics
|
|
59
|
-
- **Empty file inputs → undefined**: File inputs with no selection become `undefined`
|
|
60
|
-
|
|
61
|
-
`createActionClient` calls `parseFormData` automatically — you only need it for manual FormData handling.
|
|
62
|
-
|
|
63
|
-
## Form Flash Internals
|
|
64
|
-
|
|
65
|
-
When JavaScript is disabled and a server action returns validation errors, timber re-renders the page with flash data available via `getFormFlash()`:
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
interface FormFlashData {
|
|
69
|
-
validationErrors: Record<string, string[]>;
|
|
70
|
-
submittedValues: Record<string, unknown>;
|
|
71
|
-
serverError?: { code: string; data?: Record<string, unknown> };
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
- `validationErrors` — field-level errors keyed by field name
|
|
76
|
-
- `submittedValues` — raw input for repopulating form fields (File objects excluded, sensitive fields stripped)
|
|
77
|
-
- `serverError` — present if an `ActionError` was thrown
|
|
78
|
-
|
|
79
|
-
Flash data is server-side only — stored in AsyncLocalStorage for the duration of the re-render. Never serialized to cookies or headers.
|
|
80
|
-
|
|
81
|
-
## Sensitive Field Stripping
|
|
82
|
-
|
|
83
|
-
On validation failure timber echoes submitted form values back so users don't re-type everything. To prevent plaintext passwords or credit-card numbers from leaking through the RSC payload or into HTML `defaultValue` attributes, timber automatically strips a deny-list of sensitive field names.
|
|
84
|
-
|
|
85
|
-
**Built-in deny-list** (case-insensitive, nested objects walked recursively):
|
|
86
|
-
|
|
87
|
-
- `password`, `passwd`, `pwd` (and variants like `currentPassword`, `newPassword`)
|
|
88
|
-
- `secret`, `apiKey`, `accessToken`, `refreshToken`, `privateKey`
|
|
89
|
-
- `cvv`, `cvc`, `cardNumber`, `cardCvc`
|
|
90
|
-
- `ssn`, `socialSecurityNumber`
|
|
91
|
-
- `otp`, `totp`, `mfaCode`, `twoFactorCode`
|
|
92
|
-
- `token` (exact match only — `csrfToken` is preserved)
|
|
93
|
-
|
|
94
|
-
Stripped fields are omitted from `submittedValues` entirely — not replaced with empty strings.
|
|
95
|
-
|
|
96
|
-
### Global Configuration
|
|
97
|
-
|
|
98
|
-
```ts title="timber.config.ts"
|
|
99
|
-
import { defineConfig } from '@timber-js/app';
|
|
100
|
-
|
|
101
|
-
export default defineConfig({
|
|
102
|
-
forms: {
|
|
103
|
-
// true / omitted — use built-in deny-list (default)
|
|
104
|
-
// false — disable all stripping (NEVER in prod)
|
|
105
|
-
// string[] — extra field names merged with built-in list
|
|
106
|
-
stripSensitiveFields: ['internalCode', 'bankAccount'],
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Per-Action Override
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
import { createActionClient } from '@timber-js/app/server';
|
|
115
|
-
|
|
116
|
-
const action = createActionClient({
|
|
117
|
-
stripSensitiveFields: (name) => name.startsWith('secret_'),
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Per-action config takes precedence over global config, which takes precedence over the built-in default.
|
|
122
|
-
|
|
123
|
-
## Shared Schemas for Client + Server Validation
|
|
124
|
-
|
|
125
|
-
Define Zod schemas in shared files and import them on both sides for instant client-side validation while keeping the server as the source of truth:
|
|
126
|
-
|
|
127
|
-
```ts title="lib/schemas/contact.ts"
|
|
128
|
-
import { z } from 'zod/v4';
|
|
129
|
-
|
|
130
|
-
export const contactSchema = z.object({
|
|
131
|
-
name: z.string().min(1, 'Name is required').max(100),
|
|
132
|
-
email: z.string().email('Invalid email address'),
|
|
133
|
-
message: z.string().min(10).max(2000),
|
|
134
|
-
});
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Use in the server action via `.schema(contactSchema)` and in the client form for `onBlur` validation. Client validation is a UX enhancement — always validate on the server.
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: 'Coming from Next.js'
|
|
3
|
-
description: 'A practical mapping for Next.js developers — in Next.js you did X, in timber you do Y.'
|
|
4
|
-
slug: 'coming-from-nextjs'
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Coming from Next.js
|
|
8
|
-
|
|
9
|
-
This page maps Next.js patterns to timber equivalents. It's not a comparison (see [timber vs Next.js](/docs/timber-vs-nextjs) for that) — it's a migration mental model.
|
|
10
|
-
|
|
11
|
-
## Data Fetching
|
|
12
|
-
|
|
13
|
-
**Next.js:** `getServerSideProps`, `getStaticProps`, or `fetch()` with implicit caching.
|
|
14
|
-
|
|
15
|
-
**timber:** Async server components. No loaders, no special functions. `fetch()` is never patched or cached — use `timber.cache()` explicitly when you want caching.
|
|
16
|
-
|
|
17
|
-
```tsx title="app/products/page.tsx"
|
|
18
|
-
// timber — just an async component
|
|
19
|
-
export default async function ProductsPage() {
|
|
20
|
-
const products = await db.products.findMany();
|
|
21
|
-
return <ProductList products={products} />;
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## `loading.tsx`
|
|
26
|
-
|
|
27
|
-
**Next.js:** `loading.tsx` convention inserts a Suspense boundary automatically.
|
|
28
|
-
|
|
29
|
-
**timber:** No `loading.tsx`. Place `<Suspense>` explicitly where you want it. This keeps you in control of what streams and what blocks the HTTP status code.
|
|
30
|
-
|
|
31
|
-
```tsx
|
|
32
|
-
// timber — explicit Suspense
|
|
33
|
-
import { Suspense } from 'react';
|
|
34
|
-
|
|
35
|
-
export default async function Page() {
|
|
36
|
-
const product = await getProduct(id); // blocks, can affect status code
|
|
37
|
-
return (
|
|
38
|
-
<div>
|
|
39
|
-
<h1>{product.name}</h1>
|
|
40
|
-
<Suspense fallback={<Skeleton />}>
|
|
41
|
-
<Reviews productId={id} /> {/* streams in */}
|
|
42
|
-
</Suspense>
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Middleware
|
|
49
|
-
|
|
50
|
-
**Next.js:** Single global `middleware.ts` at the project root. Matcher patterns select routes.
|
|
51
|
-
|
|
52
|
-
**timber:** Per-segment `middleware.ts` files. Place them at the route level that matches the concern. `proxy.ts` for global concerns (CORS, rate limiting, security headers).
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
app/
|
|
56
|
-
proxy.ts # Global — every request (like Next.js middleware but with next())
|
|
57
|
-
dashboard/
|
|
58
|
-
middleware.ts # Only runs for /dashboard/*
|
|
59
|
-
settings/
|
|
60
|
-
middleware.ts # Only runs for /dashboard/settings/*
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## `useSearchParams`
|
|
64
|
-
|
|
65
|
-
**Next.js:** `useSearchParams()` hook returns a `URLSearchParams` object.
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
```ts title="app/products/search-params.ts"
|
|
70
|
-
import { defineSearchParams } from '@timber-js/app/search-params';
|
|
71
|
-
import { z } from 'zod/v4';
|
|
72
|
-
|
|
73
|
-
export const searchParams = defineSearchParams({
|
|
74
|
-
page: z.coerce.number().default(1),
|
|
75
|
-
sort: z.enum(['price', 'name']).default('name'),
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Caching
|
|
80
|
-
|
|
81
|
-
**Next.js:** Implicit fetch caching, `unstable_cache`, ISR with `revalidate`.
|
|
82
|
-
|
|
83
|
-
**timber:** No implicit caching. No ISR. Explicit `cache.data()` with TTL and tags:
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import { cache } from '@timber-js/app/cache';
|
|
87
|
-
|
|
88
|
-
declare const db: { products: { findPopular(): Promise<{ id: string; name: string }[]> } };
|
|
89
|
-
|
|
90
|
-
const getProducts = cache.data(
|
|
91
|
-
async () => db.products.findPopular(),
|
|
92
|
-
{ ttl: 300, tags: ['products'] }
|
|
93
|
-
);
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Authorization
|
|
97
|
-
|
|
98
|
-
**Next.js:** Usually done in middleware or layout components. No built-in access gate pattern.
|
|
99
|
-
|
|
100
|
-
**timber:** `access.ts` per segment. Runs inside the React tree with `React.cache` sharing. Supports slot degradation (a denied slot renders `denied.tsx` instead of failing the whole page).
|
|
101
|
-
|
|
102
|
-
```ts title="app/(auth)/access.ts"
|
|
103
|
-
import { redirect, getCookieJar } from '@timber-js/app/server';
|
|
104
|
-
|
|
105
|
-
declare function getSessionFromCookie(jar: ReturnType<typeof getCookieJar>): { userId: string } | null;
|
|
106
|
-
|
|
107
|
-
export default async function access() {
|
|
108
|
-
const session = getSessionFromCookie(getCookieJar());
|
|
109
|
-
if (!session) redirect('/login');
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Server Actions
|
|
114
|
-
|
|
115
|
-
**Next.js:** Server actions with `'use server'`. `useFormState` / `useFormStatus`.
|
|
116
|
-
|
|
117
|
-
**timber:** `createActionClient` for reusable middleware (auth, validation). `useActionState` from `@timber-js/app/client` returns a 4-tuple with auto-derived errors. Forms work without JavaScript via form flash.
|
|
118
|
-
|
|
119
|
-
```ts title="lib/action.ts"
|
|
120
|
-
import { createActionClient, ActionError } from '@timber-js/app/server';
|
|
121
|
-
import { getUser } from '@/lib/auth';
|
|
122
|
-
|
|
123
|
-
export const action = createActionClient({
|
|
124
|
-
middleware: async () => {
|
|
125
|
-
const user = await getUser();
|
|
126
|
-
if (!user) throw new ActionError('UNAUTHORIZED');
|
|
127
|
-
return { user };
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## `notFound()`
|
|
133
|
-
|
|
134
|
-
**Next.js:** `notFound()` function.
|
|
135
|
-
|
|
136
|
-
**timber:** `deny(404)` — sends a real HTTP 404 status code:
|
|
137
|
-
|
|
138
|
-
```tsx
|
|
139
|
-
import { deny } from '@timber-js/app/server';
|
|
140
|
-
|
|
141
|
-
if (!product) deny(404);
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## `redirect()`
|
|
145
|
-
|
|
146
|
-
**Next.js:** `redirect()` from `next/navigation`.
|
|
147
|
-
|
|
148
|
-
**timber:** `redirect()` from `@timber-js/app/server`. Same concept, different import:
|
|
149
|
-
|
|
150
|
-
```ts
|
|
151
|
-
import { redirect } from '@timber-js/app/server';
|
|
152
|
-
|
|
153
|
-
redirect('/login'); // 302 by default
|
|
154
|
-
redirect('/login', 301); // Permanent redirect
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Code that imports `redirect()` or `notFound()` from `next/navigation` works unmodified — including calls during client component render, which timber converts into an SPA navigation (`redirect`) or your nearest 404 boundary (`notFound`), matching Next.js behavior.
|
|
158
|
-
|
|
159
|
-
## Metadata
|
|
160
|
-
|
|
161
|
-
**Next.js:** `export const metadata` or `export async function generateMetadata()`.
|
|
162
|
-
|
|
163
|
-
**timber:** Same pattern — export `metadata` (static) or a `metadata()` function (dynamic) from any page or layout.
|
|
164
|
-
|
|
165
|
-
## Imports
|
|
166
|
-
|
|
167
|
-
| Next.js import | timber import |
|
|
168
|
-
| ------------------------- | ------------------------------------------ |
|
|
169
|
-
| `next/link` | `@timber-js/app/client` (`Link`) |
|
|
170
|
-
| `next/navigation` | `@timber-js/app/client` (`useRouter`, etc) |
|
|
171
|
-
| `next/headers` | `@timber-js/app/server` (`getHeaders`) |
|
|
172
|
-
| `next/server` | `@timber-js/app/server` |
|
|
173
|
-
| `unstable_cache` | `@timber-js/app/cache` (`cache`) |
|
|
174
|
-
|
|
175
|
-
## Key Differences Summary
|
|
176
|
-
|
|
177
|
-
| Concept | Next.js | timber |
|
|
178
|
-
| -------------------- | -------------------------------- | ------------------------------------- |
|
|
179
|
-
| Fetch caching | Implicit, patched `fetch` | Explicit `timber.cache()` |
|
|
180
|
-
| ISR | Built-in | Not supported (use cache + TTL) |
|
|
181
|
-
| `loading.tsx` | Convention | Use explicit `<Suspense>` |
|
|
182
|
-
| Middleware | Single global file | Per-segment + global `proxy.ts` |
|
|
183
|
-
| Status codes | Often 200 for errors | Real HTTP status codes always |
|
|
184
|
-
| Auth | In middleware or components | `access.ts` with slot degradation |
|
|
185
|
-
| Search params | Untyped `URLSearchParams` | Typed codecs with validation |
|
|
186
|
-
| Forms without JS | Limited support | Full form flash support |
|