@timber-js/app 0.2.0-alpha.213 → 0.2.0-alpha.215
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-CEootpB1.js → actions-CUh3cClk.js} +2 -2
- package/dist/_chunks/{actions-CEootpB1.js.map → actions-CUh3cClk.js.map} +1 -1
- package/dist/_chunks/{canonicalize-CgHoscYO.js → canonicalize-BAWkWiKK.js} +28 -2
- package/dist/_chunks/{canonicalize-CgHoscYO.js.map → canonicalize-BAWkWiKK.js.map} +1 -1
- package/dist/_chunks/{chains-BfoPFraI.js → chains-CjK1Eu6a.js} +2 -2
- package/dist/_chunks/{chains-BfoPFraI.js.map → chains-CjK1Eu6a.js.map} +1 -1
- package/dist/_chunks/{classify-BT66U83D.js → classify-GAdt6aiA.js} +2 -2
- package/dist/_chunks/{classify-BT66U83D.js.map → classify-GAdt6aiA.js.map} +1 -1
- package/dist/_chunks/{cli-check-BfQ54-UJ.js → cli-check-DOzjlycg.js} +3 -3
- package/dist/_chunks/{cli-check-BfQ54-UJ.js.map → cli-check-DOzjlycg.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-czh2dsLs.js → cli-schema-sync-B9wDaQvW.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-czh2dsLs.js.map → cli-schema-sync-B9wDaQvW.js.map} +1 -1
- package/dist/_chunks/{client-dep-entries-CQwpb8dI.js → client-dep-entries-DEp8ZHce.js} +47 -3
- package/dist/_chunks/client-dep-entries-DEp8ZHce.js.map +1 -0
- package/dist/_chunks/{convention-lint-BEVW4EID.js → convention-lint-B3QEGJX7.js} +2 -2
- package/dist/_chunks/{convention-lint-BEVW4EID.js.map → convention-lint-B3QEGJX7.js.map} +1 -1
- package/dist/_chunks/{dev-server-FKxptbnI.js → dev-server-_9L4KWC-.js} +3 -3
- package/dist/_chunks/{dev-server-FKxptbnI.js.map → dev-server-_9L4KWC-.js.map} +1 -1
- package/dist/_chunks/{error-boundary-9g_Lb2na.js → error-boundary-xxxLtXt6.js} +38 -5
- package/dist/_chunks/{error-boundary-9g_Lb2na.js.map → error-boundary-xxxLtXt6.js.map} +1 -1
- package/dist/_chunks/{live-graph-C_4v-fHv.js → live-graph-Cd3YHvrH.js} +4 -4
- package/dist/_chunks/{live-graph-C_4v-fHv.js.map → live-graph-Cd3YHvrH.js.map} +1 -1
- package/dist/_chunks/{poison-scan-C92liMAr.js → poison-scan-BnJjBOkn.js} +2 -2
- package/dist/_chunks/{poison-scan-C92liMAr.js.map → poison-scan-BnJjBOkn.js.map} +1 -1
- package/dist/_chunks/{scanner-CQt12vE2.js → scanner-CKAT5gRx.js} +2 -2
- package/dist/_chunks/{scanner-CQt12vE2.js.map → scanner-CKAT5gRx.js.map} +1 -1
- package/dist/_chunks/{walkers-DAT4avhZ.js → walkers-DwCXEyRu.js} +3 -3
- package/dist/_chunks/{walkers-DAT4avhZ.js.map → walkers-DwCXEyRu.js.map} +1 -1
- package/dist/adapters/nitro-preview.d.ts.map +1 -1
- package/dist/adapters/nitro.js +11 -2
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/adapters/types.d.ts +3 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/analyze/crawl-entry.js +3 -3
- package/dist/analyze/graph-command.js +2 -2
- package/dist/cli.d.ts +5 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +15 -14
- package/dist/cli.js.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/internal.js +22 -7
- package/dist/client/internal.js.map +1 -1
- package/dist/client/router-effects.d.ts +70 -12
- package/dist/client/router-effects.d.ts.map +1 -1
- package/dist/client/router.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -52
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-dep-entries.d.ts +36 -0
- package/dist/plugins/client-dep-entries.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/canonicalize.d.ts +22 -0
- package/dist/server/canonicalize.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +54 -3
- package/dist/server/internal.js.map +1 -1
- package/dist/server/pipeline-helpers.d.ts +31 -0
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/port-resolution.d.ts +3 -12
- package/dist/server/port-resolution.d.ts.map +1 -1
- package/docs/api/36-cli.mdx +8 -4
- package/docs/learn/13-deploying.mdx +2 -0
- package/package.json +1 -1
- package/src/adapters/nitro-preview.ts +10 -1
- package/src/adapters/types.ts +3 -1
- package/src/cli.ts +18 -16
- package/src/client/router-effects.ts +99 -14
- package/src/client/router.ts +29 -13
- package/src/index.ts +48 -71
- package/src/plugins/client-dep-entries.ts +46 -0
- package/src/server/canonicalize.ts +29 -0
- package/src/server/pipeline-helpers.ts +61 -0
- package/src/server/pipeline.ts +13 -1
- package/src/server/port-resolution.ts +6 -16
- package/dist/_chunks/client-dep-entries-CQwpb8dI.js.map +0 -1
|
@@ -31,6 +31,37 @@ import type { PhaseName } from './pipeline-outcome.ts';
|
|
|
31
31
|
* See design/08-forms-and-actions.md §"CSRF Protection".
|
|
32
32
|
*/
|
|
33
33
|
export declare function csrfGate(req: Request, canonicalPath: string, csrf: CsrfConfig, matchRoute: RouteMatcher): Response | null;
|
|
34
|
+
/**
|
|
35
|
+
* The redirect for a safe request whose URL is not canonical, or null to
|
|
36
|
+
* serve it.
|
|
37
|
+
*
|
|
38
|
+
* A GET for `/admin/` used to render with a 200 at that URL. The server
|
|
39
|
+
* rendered with the canonical `/admin` while the browser hydrated with the
|
|
40
|
+
* raw `/admin/`, so anything branching on `usePathname()` hydrated
|
|
41
|
+
* mismatched (TIM-1571). Redirecting makes the address bar — the client's
|
|
42
|
+
* copy of the URL — the canonical one, and leaves one URL per page for
|
|
43
|
+
* caches and crawlers.
|
|
44
|
+
*
|
|
45
|
+
* Only GET and HEAD are redirected. Every other method — an action's POST,
|
|
46
|
+
* a CORS preflight — is served at the canonical path, as before: a
|
|
47
|
+
* redirected POST is re-sent by the browser, which an action must not
|
|
48
|
+
* depend on.
|
|
49
|
+
*
|
|
50
|
+
* Runs inside proxy.ts's `next()`, not before it, so proxy.ts still runs
|
|
51
|
+
* on every request and its headers land on the redirect. A cross-origin
|
|
52
|
+
* `GET /api/items/` needs proxy.ts's CORS headers on the 308 itself:
|
|
53
|
+
* browsers apply the CORS check to a redirect response.
|
|
54
|
+
*
|
|
55
|
+
* A document request gets a relative 308 (never built from `Host`). A page
|
|
56
|
+
* navigation gets the router's soft redirect, decided exactly as for a
|
|
57
|
+
* `redirect()` outcome: an RSC request that does not match a route.ts
|
|
58
|
+
* handler (`buildRedirectResponse`). The framework's `_rsc` cache key is
|
|
59
|
+
* dropped from the soft target; the router appends a fresh one when it
|
|
60
|
+
* fetches the canonical URL.
|
|
61
|
+
*
|
|
62
|
+
* See design/07-routing.md §"Non-Canonical URLs Redirect".
|
|
63
|
+
*/
|
|
64
|
+
export declare function canonicalRedirect(req: Request, canonicalPath: string, stripTrailingSlash: boolean, matchRoute: RouteMatcher): Response | null;
|
|
34
65
|
/**
|
|
35
66
|
* Resolver closure produced once at pipeline construction. The lazy variant
|
|
36
67
|
* still calls `loader()` per-request (HMR relies on re-importing), but the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-helpers.d.ts","sourceRoot":"","sources":["../../src/server/pipeline-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAS9C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAsC,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClG,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO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I,EAAE,UAAU,EAChB,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,OAAO;IACxB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,UAAU,KACf,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAElC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,cAAc,CAAC,EAAE,CACf,GAAG,EAAE,OAAO,EACZ,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,QAAQ,CAAC,KACnE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,wEAAwE;IACxE,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC;AAID;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAuR1F"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** Port input precedence for dev
|
|
2
|
-
/** Default port used by `timber dev
|
|
1
|
+
/** Port input precedence for dev. Vite owns binding and restart reuse. */
|
|
2
|
+
/** Default port used by `timber dev`. */
|
|
3
3
|
export declare const DEFAULT_PORT = 3000;
|
|
4
4
|
export interface ResolvePortInput {
|
|
5
5
|
/**
|
|
@@ -13,19 +13,10 @@ export interface ResolvePortInput {
|
|
|
13
13
|
/** Default port to use when neither `configPort` nor `envPort` is set. */
|
|
14
14
|
defaultPort?: number;
|
|
15
15
|
}
|
|
16
|
-
export interface ResolvedPortInput {
|
|
17
|
-
/** Port to start binding from. */
|
|
18
|
-
port: number;
|
|
19
|
-
/**
|
|
20
|
-
* `true` if the port came from an explicit user override (config or
|
|
21
|
-
* env). Preview uses this to default to strict port binding.
|
|
22
|
-
*/
|
|
23
|
-
explicit: boolean;
|
|
24
|
-
}
|
|
25
16
|
/**
|
|
26
17
|
* Pure: compute the starting port from config / env / defaults.
|
|
27
18
|
*
|
|
28
19
|
* Performs no I/O.
|
|
29
20
|
*/
|
|
30
|
-
export declare function resolveStartPort(input: ResolvePortInput):
|
|
21
|
+
export declare function resolveStartPort(input: ResolvePortInput): number;
|
|
31
22
|
//# sourceMappingURL=port-resolution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"port-resolution.d.ts","sourceRoot":"","sources":["../../src/server/port-resolution.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"port-resolution.d.ts","sourceRoot":"","sources":["../../src/server/port-resolution.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAE1E,yCAAyC;AACzC,eAAO,MAAM,YAAY,OAAO,CAAC;AAIjC,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAiBhE"}
|
package/docs/api/36-cli.mdx
CHANGED
|
@@ -29,7 +29,7 @@ When the requested port is available, the server shows a loading page while Vite
|
|
|
29
29
|
|
|
30
30
|
#### Port selection
|
|
31
31
|
|
|
32
|
-
The default port
|
|
32
|
+
The default port for `timber dev` is **`3000`** (matching Next.js and most Node web frameworks). If `3000` is already in use, timber automatically bumps to `3001`, then `3002`, and so on until it finds a free port:
|
|
33
33
|
|
|
34
34
|
```
|
|
35
35
|
Port 3000 is in use, trying another one...
|
|
@@ -42,7 +42,7 @@ To override the default, use any of the following (highest precedence first):
|
|
|
42
42
|
|
|
43
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
|
+
An occupied port produces a notice and the server tries the next free port. Set `server.strictPort: true` in `vite.config.ts` to fail on a conflict instead.
|
|
46
46
|
|
|
47
47
|
Editing `timber.config.ts` triggers a full process restart so the updated config takes effect. The dev server briefly shuts down and restarts on the same port. Changing the configured port takes effect on restart.
|
|
48
48
|
|
|
@@ -78,7 +78,7 @@ Serve the production build locally for testing.
|
|
|
78
78
|
timber preview
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
If your adapter
|
|
81
|
+
Preview runs your adapter's `preview()`. The Cloudflare and Nitro adapters both provide one. If no adapter is configured, or your adapter has no `preview()`, preview exits with an error that says so. It does not fall back to Vite's preview server, because that would serve your build directory, server bundles included, as static files.
|
|
82
82
|
|
|
83
83
|
Preview reads your project the same way `timber build` does: it resolves your Vite config, so options passed inline to `timber({ ... })`, a custom `--config`, and `build.outDir` all apply. It serves your last build using the `output` mode your config sets now. If you change `output`, rebuild before you preview:
|
|
84
84
|
|
|
@@ -90,7 +90,11 @@ Preview reads your project the same way `timber build` does: it resolves your Vi
|
|
|
90
90
|
|
|
91
91
|
The Nitro static preview serves under your `base` path, but it does not apply `_redirects` or `_headers` rules. Check those on your hosting platform.
|
|
92
92
|
|
|
93
|
-
A `timber.config.ts` that exists but fails to load is a hard error naming the file
|
|
93
|
+
A `timber.config.ts` that exists but fails to load is a hard error naming the file, so preview never runs with your adapter ignored.
|
|
94
|
+
|
|
95
|
+
The adapter picks the preview port, not `server.port`. The Nitro preview server starts at `3000` and tries the next free port, unless you set `PORT`, in which case a conflict is an error. Cloudflare preview uses wrangler's own default port.
|
|
96
|
+
|
|
97
|
+
Running `vite preview` directly is an error. It would serve your build directory, server bundles included, as static files.
|
|
94
98
|
|
|
95
99
|
Always run `timber build` before `timber preview`.
|
|
96
100
|
|
|
@@ -200,6 +200,8 @@ export default {
|
|
|
200
200
|
|
|
201
201
|
Pre-renders every route to HTML at build time. Add `clientJavascript: false` for zero-JavaScript output. Deploy to any static file host — S3, CloudFront, Cloudflare Pages, GitHub Pages, Netlify, or any HTTP server.
|
|
202
202
|
|
|
203
|
+
`timber preview` runs an adapter, so a static build with no adapter can't be previewed. Add `adapter: nitro()` to preview it locally. A static Nitro build doesn't need a Nitro server, and its preview works with any preset.
|
|
204
|
+
|
|
203
205
|
### Serving from a sub-path
|
|
204
206
|
|
|
205
207
|
To deploy under a path instead of a domain root — `https://user.github.io/repo/` on GitHub Pages, for example — set Vite's `base`:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.215",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
|
@@ -326,7 +326,16 @@ const server = createServer(async (req, res) => {
|
|
|
326
326
|
// connection it would be attacker-controlled. The CSRF layer honors it
|
|
327
327
|
// separately for reverse-proxy deployments.
|
|
328
328
|
const scheme = req.socket?.encrypted ? 'https' : 'http';
|
|
329
|
-
|
|
329
|
+
// An origin-form target ('/path') is concatenated, not resolved against
|
|
330
|
+
// the base: resolved as a relative reference, '//evil.com/' names another
|
|
331
|
+
// host, and the pipeline would see '/' instead of the path it must
|
|
332
|
+
// redirect to '/evil.com' (TIM-1571). Any other form — 'OPTIONS *', an
|
|
333
|
+
// absolute-form target — is resolved as before: concatenating '*' makes
|
|
334
|
+
// an invalid URL, and this callback has no catch around it, so the
|
|
335
|
+
// rejection would take the preview process down.
|
|
336
|
+
const origin = \`\${scheme}://\${host}:\${boundPort}\`;
|
|
337
|
+
const target = req.url || '/';
|
|
338
|
+
const url = target.startsWith('/') ? new URL(origin + target) : new URL(target, origin);
|
|
330
339
|
|
|
331
340
|
// The runtime's own request-boundary canonicalizer (_canonicalize.mjs,
|
|
332
341
|
// compiled from server/canonicalize.ts): one decode, and the same 400s for
|
package/src/adapters/types.ts
CHANGED
|
@@ -152,7 +152,9 @@ export interface TimberPlatformAdapter {
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Start a local preview server for the built output.
|
|
155
|
-
*
|
|
155
|
+
* Without it, `timber preview` fails with an error naming the adapter —
|
|
156
|
+
* there is no fallback to Vite preview, which would serve the build
|
|
157
|
+
* directory (server bundles included) as static files.
|
|
156
158
|
*
|
|
157
159
|
* Runs in a later process than the build (`timber preview`); see
|
|
158
160
|
* {@link PreviewTarget}.
|
package/src/cli.ts
CHANGED
|
@@ -140,7 +140,6 @@ export function parseArgs(args: string[]): ParsedArgs {
|
|
|
140
140
|
export interface ViteDeps {
|
|
141
141
|
createServer?: typeof import('vite').createServer;
|
|
142
142
|
createBuilder?: typeof import('vite').createBuilder;
|
|
143
|
-
preview?: typeof import('vite').preview;
|
|
144
143
|
resolveViteConfig?: ResolveViteConfig;
|
|
145
144
|
}
|
|
146
145
|
|
|
@@ -231,16 +230,17 @@ export async function runBuild(options: CommandOptions, _deps?: ViteDeps): Promi
|
|
|
231
230
|
|
|
232
231
|
/**
|
|
233
232
|
* Serve the production build for local testing.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
233
|
+
* The adapter's preview() serves it; without one, preview fails (TIM-1565).
|
|
234
|
+
* There is no fallback to Vite preview: it would serve the build directory
|
|
235
|
+
* itself — the server bundles as static files, with no root `index.html` —
|
|
236
|
+
* which is useless in either output mode.
|
|
236
237
|
*
|
|
237
238
|
* The project is resolved through Vite, as `timber check` resolves it
|
|
238
239
|
* (`cli-context.ts`), so the adapter, the output mode, and the build
|
|
239
240
|
* directory are the ones `timber build` used — including `--config`, inline
|
|
240
241
|
* `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which
|
|
241
242
|
* a re-read of `timber.config.ts` can see (TIM-1531). A config file that
|
|
242
|
-
* exists but fails to load throws
|
|
243
|
-
* degrading to plain Vite preview (TIM-1066).
|
|
243
|
+
* exists but fails to load throws, naming the file (TIM-1066).
|
|
244
244
|
*/
|
|
245
245
|
export async function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void> {
|
|
246
246
|
const { resolveTimberContext } = await import('./cli-context.ts');
|
|
@@ -249,20 +249,22 @@ export async function runPreview(options: CommandOptions, _deps?: ViteDeps): Pro
|
|
|
249
249
|
const ctx = await resolveTimberContext('preview', options.config, _deps?.resolveViteConfig);
|
|
250
250
|
const adapter = contextAdapter(ctx);
|
|
251
251
|
|
|
252
|
-
if (typeof adapter?.preview
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
if (typeof adapter?.preview !== 'function') {
|
|
253
|
+
const missing = adapter
|
|
254
|
+
? `The adapter '${adapter.name}' has no preview(), so \`timber preview\` cannot serve this build.`
|
|
255
|
+
: `No adapter is configured, so \`timber preview\` has nothing to serve this build with.`;
|
|
256
|
+
throw new Error(
|
|
257
|
+
`[timber] ${missing} Use an adapter that implements preview() — ` +
|
|
258
|
+
`cloudflare() from '@timber-js/app/adapters/cloudflare', or nitro() from ` +
|
|
259
|
+
`'@timber-js/app/adapters/nitro' (any preset for a static build; node-server or bun ` +
|
|
260
|
+
`for a server build) — or serve the build with your platform's own tooling.`
|
|
261
|
+
);
|
|
258
262
|
}
|
|
259
263
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
configFile: options.config,
|
|
264
|
+
await adapter.preview(adapterConfig(ctx), {
|
|
265
|
+
output: ctx.config.output ?? 'server',
|
|
266
|
+
outputDir: ctx.buildDir,
|
|
264
267
|
});
|
|
265
|
-
server.printUrls();
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
/**
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { setHardNavigating } from './navigation-root.tsx';
|
|
13
|
-
import type { RenderOwner } from './navigation-transition.ts';
|
|
13
|
+
import type { CommitOutcome, RenderOwner } from './navigation-transition.ts';
|
|
14
14
|
import { RedirectError, ServerErrorResponse, NonRscResponse } from './rsc-fetch.ts';
|
|
15
15
|
import { recordSkew } from './router-skew.ts';
|
|
16
16
|
|
|
@@ -147,14 +147,96 @@ export interface NavigationRecoveryDeps {
|
|
|
147
147
|
currentOwner: () => RenderOwner | null;
|
|
148
148
|
leaveSpaIfOwned: SpaExits['leaveSpaIfOwned'];
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* redirect interrupted, so a redirected Back still animates as Back and a
|
|
153
|
-
* link's own `transitionTypes` survive the hop (TIM-1471). `onHandOff`
|
|
154
|
-
* survives it too: a server action redirect waits for the tree that is
|
|
155
|
-
* finally handed to React, which is the redirected one (TIM-1573).
|
|
150
|
+
* Follow a redirect to `url` — the router's own `navigate()`, carrying
|
|
151
|
+
* the interrupted navigation's {@link RedirectHop}.
|
|
156
152
|
*/
|
|
157
|
-
navigate: (url: string,
|
|
153
|
+
navigate: (url: string, hop: RedirectHop) => Promise<void>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* What a redirect hop inherits from the navigation the redirect interrupted.
|
|
158
|
+
*/
|
|
159
|
+
export interface RedirectHop {
|
|
160
|
+
/**
|
|
161
|
+
* The view transition types of the interrupted render, so a redirected Back
|
|
162
|
+
* still animates as Back and a link's own `transitionTypes` survive the
|
|
163
|
+
* hop (TIM-1471).
|
|
164
|
+
*/
|
|
165
|
+
types: readonly string[];
|
|
166
|
+
/**
|
|
167
|
+
* The interrupted navigation's history mode. A push stays a push: the
|
|
168
|
+
* address bar moves only when a destination commits, so the interrupted
|
|
169
|
+
* navigation wrote no entry, and replacing would overwrite the page being
|
|
170
|
+
* left — Back would skip it (TIM-1571). A refresh or a traversal replaces:
|
|
171
|
+
* the browser is already on the entry being redirected.
|
|
172
|
+
*/
|
|
173
|
+
replace: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* The interrupted navigation's scroll mode. `<Link scroll={false}>` to a
|
|
176
|
+
* URL that redirects — a non-canonical `/x/` among them — still keeps the
|
|
177
|
+
* scroll position; the hop would otherwise default to scrolling to the top.
|
|
178
|
+
*/
|
|
179
|
+
scroll: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* The interrupted navigation's `onCommit`, as {@link HeldCommit.settle}.
|
|
182
|
+
* A followed redirect is one logical navigation: the hop's commit is the
|
|
183
|
+
* one the caller is waiting for. `<Link>` holds `isPending` until it, and
|
|
184
|
+
* a `'failed'` from the interrupted render would release it on the hop's
|
|
185
|
+
* decode, ahead of a commit React is still holding (TIM-1571). Recovery
|
|
186
|
+
* delivers it itself on every path that does not follow the redirect.
|
|
187
|
+
*/
|
|
188
|
+
onCommit?: (outcome: CommitOutcome) => void;
|
|
189
|
+
/**
|
|
190
|
+
* The interrupted navigation's `onHandOff`: a server action redirect
|
|
191
|
+
* waits for the tree that is finally handed to React, which is the
|
|
192
|
+
* redirected one (TIM-1573).
|
|
193
|
+
*/
|
|
194
|
+
onHandOff?: () => void;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* A navigation's `onCommit`, split around its failure.
|
|
199
|
+
*
|
|
200
|
+
* `navigateTransition` settles `onCommit` `'failed'` as soon as `perform`
|
|
201
|
+
* throws — before the router has seen the error, so before it knows the
|
|
202
|
+
* failure is a redirect it will follow. `transition` is what the render
|
|
203
|
+
* gets: every outcome but `'failed'` reaches the caller at once, and
|
|
204
|
+
* `'failed'` is left to recovery, which either hands `settle` to the
|
|
205
|
+
* redirect hop or delivers it. `settle` runs the caller's callback at most
|
|
206
|
+
* once, so a commit or supersession already delivered wins over a later
|
|
207
|
+
* `'failed'`.
|
|
208
|
+
*/
|
|
209
|
+
export interface HeldCommit {
|
|
210
|
+
transition: ((outcome: CommitOutcome) => void) | undefined;
|
|
211
|
+
settle: ((outcome: CommitOutcome) => void) | undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function holdCommit(onCommit?: (outcome: CommitOutcome) => void): HeldCommit {
|
|
215
|
+
if (!onCommit) return { transition: undefined, settle: undefined };
|
|
216
|
+
let settled = false;
|
|
217
|
+
const settle = (outcome: CommitOutcome): void => {
|
|
218
|
+
if (settled) return;
|
|
219
|
+
settled = true;
|
|
220
|
+
onCommit(outcome);
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
transition: (outcome) => {
|
|
224
|
+
if (outcome !== 'failed') settle(outcome);
|
|
225
|
+
},
|
|
226
|
+
settle,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The URL a redirect hop navigates to. A redirect target without a fragment
|
|
232
|
+
* keeps the one the navigation asked for, as a browser does for a 3xx
|
|
233
|
+
* (RFC 9110 §10.2.2): the server never sees the fragment, so a soft redirect
|
|
234
|
+
* — `<Link href="/docs/#install">` answered with `/docs` — cannot carry it.
|
|
235
|
+
*/
|
|
236
|
+
export function redirectHopUrl(redirectUrl: string, requestedUrl: string): string {
|
|
237
|
+
if (redirectUrl.includes('#')) return redirectUrl;
|
|
238
|
+
const hashIndex = requestedUrl.indexOf('#');
|
|
239
|
+
return hashIndex === -1 ? redirectUrl : redirectUrl + requestedUrl.slice(hashIndex);
|
|
158
240
|
}
|
|
159
241
|
|
|
160
242
|
/**
|
|
@@ -189,18 +271,21 @@ export function createNavigationRecovery({
|
|
|
189
271
|
owner: RenderOwner,
|
|
190
272
|
url: string,
|
|
191
273
|
fromUrl: string,
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
/** The failed navigation's `NavigationOptions.onHandOff`, for the hop. */
|
|
195
|
-
onHandOff?: () => void
|
|
274
|
+
/** What a redirect hop inherits from the navigation that failed. */
|
|
275
|
+
hop: RedirectHop
|
|
196
276
|
): Promise<boolean> {
|
|
197
277
|
if (error instanceof RedirectError) {
|
|
198
278
|
// Same ownership rule as leaving the SPA: a superseded navigation must
|
|
199
279
|
// not steer the document to the destination it was abandoned for.
|
|
200
|
-
if (currentOwner() !== owner)
|
|
201
|
-
|
|
280
|
+
if (currentOwner() !== owner) {
|
|
281
|
+
hop.onCommit?.('superseded');
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
await navigate(redirectHopUrl(error.redirectUrl, url), hop);
|
|
202
285
|
return true;
|
|
203
286
|
}
|
|
287
|
+
// Anything else ends this navigation here: its held `'failed'`.
|
|
288
|
+
hop.onCommit?.('failed');
|
|
204
289
|
// A server error, a non-RSC response and a version skew all end the same
|
|
205
290
|
// way: hand `url` back to the server as a document load, so it can render
|
|
206
291
|
// the outcome as HTML (design/10-error-handling.md §"Error Page Rendering
|
package/src/client/router.ts
CHANGED
|
@@ -18,7 +18,12 @@ import { createNavigationCommitter } from './navigation-commit.ts';
|
|
|
18
18
|
import { fetchRscPayload, NonRscResponse } from './rsc-fetch.ts';
|
|
19
19
|
import { readPayloadTree, readPublishedParams } from '../shared/payload-root.ts';
|
|
20
20
|
import { isClientStale } from './stale-client.ts';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
createScrollEffects,
|
|
23
|
+
createSpaExits,
|
|
24
|
+
createNavigationRecovery,
|
|
25
|
+
holdCommit,
|
|
26
|
+
} from './router-effects.ts';
|
|
22
27
|
import { createNavigationLifecycle } from './router-lifecycle.ts';
|
|
23
28
|
import { createNavigationPipeline, prefetchKeyFor } from './router-pipeline.ts';
|
|
24
29
|
import { recordSkew } from './router-skew.ts';
|
|
@@ -102,8 +107,8 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
102
107
|
currentOwner,
|
|
103
108
|
leaveSpaIfOwned,
|
|
104
109
|
// Hoisted — `navigate` is a function declaration below.
|
|
105
|
-
navigate: (url, types, onHandOff) =>
|
|
106
|
-
navigate(url, { replace
|
|
110
|
+
navigate: (url, { types, replace, scroll, onCommit, onHandOff }) =>
|
|
111
|
+
navigate(url, { replace, scroll, _renderTypes: types, onCommit, onHandOff }),
|
|
107
112
|
});
|
|
108
113
|
|
|
109
114
|
async function navigate(url: string, options: NavigationOptions = {}): Promise<void> {
|
|
@@ -152,6 +157,9 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
152
157
|
await leaveSpaSuperseding(url, departingUrl);
|
|
153
158
|
}
|
|
154
159
|
|
|
160
|
+
// A redirect this navigation follows inherits its onCommit (RedirectHop).
|
|
161
|
+
const heldCommit = holdCommit(options.onCommit);
|
|
162
|
+
|
|
155
163
|
await runNavigation(url, async (owner) => {
|
|
156
164
|
try {
|
|
157
165
|
await renderViaTransition(
|
|
@@ -165,7 +173,7 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
165
173
|
signal: owner.fetchAbort.signal,
|
|
166
174
|
departingUrl,
|
|
167
175
|
}),
|
|
168
|
-
|
|
176
|
+
heldCommit.transition,
|
|
169
177
|
options.onHandOff
|
|
170
178
|
);
|
|
171
179
|
|
|
@@ -183,14 +191,13 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
183
191
|
// instead would rebuild the page they were *leaving* and discard
|
|
184
192
|
// the click (TIM-1275).
|
|
185
193
|
if (
|
|
186
|
-
await recoverFromNavigationError(
|
|
187
|
-
error,
|
|
188
|
-
owner,
|
|
189
|
-
url,
|
|
190
|
-
departingUrl,
|
|
194
|
+
await recoverFromNavigationError(error, owner, url, departingUrl, {
|
|
191
195
|
types,
|
|
192
|
-
|
|
193
|
-
|
|
196
|
+
replace,
|
|
197
|
+
scroll,
|
|
198
|
+
onCommit: heldCommit.settle,
|
|
199
|
+
onHandOff: options.onHandOff,
|
|
200
|
+
})
|
|
194
201
|
) {
|
|
195
202
|
return;
|
|
196
203
|
}
|
|
@@ -222,6 +229,7 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
222
229
|
onCommit?: (outcome: CommitOutcome) => void;
|
|
223
230
|
} = {}
|
|
224
231
|
): Promise<void> {
|
|
232
|
+
const heldCommit = holdCommit(opts.onCommit);
|
|
225
233
|
await runNavigation(
|
|
226
234
|
url,
|
|
227
235
|
async (owner) => {
|
|
@@ -247,7 +255,7 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
247
255
|
});
|
|
248
256
|
return { ...result, params, navState, commit };
|
|
249
257
|
},
|
|
250
|
-
|
|
258
|
+
heldCommit.transition
|
|
251
259
|
);
|
|
252
260
|
} catch (error) {
|
|
253
261
|
// Neither path is a navigate(), and neither has a caller that
|
|
@@ -261,7 +269,15 @@ export function createRouter(deps: RouterDeps): RouterInstance {
|
|
|
261
269
|
// browser has already traversed, and `refresh()` is by definition
|
|
262
270
|
// where it already is. So `hardNavigate()` takes its same-document
|
|
263
271
|
// branch and reloads rather than pushing an entry.
|
|
264
|
-
if (
|
|
272
|
+
if (
|
|
273
|
+
await recoverFromNavigationError(error, owner, url, url, {
|
|
274
|
+
types: [type],
|
|
275
|
+
replace: true,
|
|
276
|
+
scroll: true,
|
|
277
|
+
onCommit: heldCommit.settle,
|
|
278
|
+
})
|
|
279
|
+
)
|
|
280
|
+
return;
|
|
265
281
|
throw error;
|
|
266
282
|
}
|
|
267
283
|
|