@rsc-kit/mcp 0.41.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recipes.js +12 -2
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +206 -6
- package/guides/api-routes.md +159 -215
- package/guides/authorization.md +103 -114
- package/guides/backend-answered-pages.md +301 -252
- package/guides/bap-vs-inertia.md +67 -25
- package/guides/blueprints.md +300 -169
- package/guides/bun.md +42 -25
- package/guides/caching.md +46 -49
- package/guides/coming-from-inertia.md +2 -2
- package/guides/commands.md +251 -200
- package/guides/connection.md +50 -54
- package/guides/content-security-policy.md +133 -84
- package/guides/domains.md +190 -149
- package/guides/edge-caching.md +242 -268
- package/guides/emails.md +96 -45
- package/guides/errors.md +116 -137
- package/guides/feature-flags.md +100 -30
- package/guides/file-uploads.md +101 -26
- package/guides/fonts.md +139 -110
- package/guides/forms.md +520 -542
- package/guides/images.md +87 -28
- package/guides/index.json +13 -33
- package/guides/instrumentation.md +134 -95
- package/guides/isr.md +3 -3
- package/guides/live-data-in-production.md +695 -0
- package/guides/live-data.md +170 -839
- package/guides/mcp.md +83 -59
- package/guides/metadata.md +124 -179
- package/guides/navigation.md +118 -147
- package/guides/no-javascript.md +49 -57
- package/guides/offline.md +118 -153
- package/guides/openapi.md +100 -35
- package/guides/pages.md +160 -50
- package/guides/ppr.md +178 -256
- package/guides/pwa.md +251 -218
- package/guides/queries.md +171 -300
- package/guides/react-compiler.md +90 -50
- package/guides/redirects.md +141 -177
- package/guides/response-headers.md +76 -74
- package/guides/route-interception.md +112 -111
- package/guides/routing.md +216 -322
- package/guides/sections.md +63 -66
- package/guides/seo-files.md +127 -65
- package/guides/server-actions.md +285 -357
- package/guides/static-generation.md +131 -199
- package/guides/testing.md +269 -147
- package/guides/third-party-scripts.md +94 -47
- package/guides/typed-routes.md +115 -113
- package/guides/url-validation.md +113 -61
- package/guides/validation.md +53 -62
- package/guides/view-transitions.md +159 -132
- package/guides/where-it-runs.md +226 -162
- package/package.json +2 -2
- package/guides/admin.md +0 -520
- package/guides/deployment.md +0 -598
- package/guides/go.md +0 -539
- package/guides/laravel.md +0 -787
- package/guides/your-own-backend.md +0 -602
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
# Headers and cookies
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Reading request headers and cookies, setting response headers and cookies, and security headers.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Anywhere in a server component or action:
|
|
5
|
+
Read headers and cookies anywhere on the server. Set them in a middleware:
|
|
8
6
|
|
|
9
7
|
```tsx
|
|
10
|
-
import {
|
|
8
|
+
import { cookies } from '@rsc-kit/core/request'
|
|
11
9
|
|
|
12
10
|
export default async function Page() {
|
|
13
|
-
const h = await headers()
|
|
14
11
|
const jar = await cookies()
|
|
15
12
|
|
|
16
13
|
return <p>Hello {jar.get('name')?.value ?? 'stranger'}</p>
|
|
17
14
|
}
|
|
18
15
|
```
|
|
19
16
|
|
|
20
|
-
##
|
|
17
|
+
## Reading headers and cookies
|
|
18
|
+
|
|
19
|
+
In a server component or an action:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { headers, cookies, searchParams } from '@rsc-kit/core/request'
|
|
23
|
+
|
|
24
|
+
const h = await headers()
|
|
25
|
+
const jar = await cookies()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Setting headers and cookies
|
|
29
|
+
|
|
30
|
+
Set them in a `middleware.ts`:
|
|
21
31
|
|
|
22
32
|
```tsx
|
|
23
33
|
import { responseHeaders, cookies } from '@rsc-kit/core/request'
|
|
@@ -30,13 +40,12 @@ export async function middleware() {
|
|
|
30
40
|
}
|
|
31
41
|
```
|
|
32
42
|
|
|
33
|
-
**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
being silently dropped, so you find out immediately.
|
|
43
|
+
**Only middleware can set them.** It runs before the render, while the response
|
|
44
|
+
headers haven't been sent. A component runs while the page streams, after
|
|
45
|
+
they have, so setting one from a component throws.
|
|
37
46
|
|
|
38
|
-
A redirect carries them too,
|
|
39
|
-
|
|
47
|
+
A redirect carries them too, so a middleware can remember where someone was
|
|
48
|
+
going before sending them to sign in:
|
|
40
49
|
|
|
41
50
|
```tsx
|
|
42
51
|
export async function middleware() {
|
|
@@ -49,10 +58,34 @@ export async function middleware() {
|
|
|
49
58
|
}
|
|
50
59
|
```
|
|
51
60
|
|
|
61
|
+
### Cookie options
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
jar.set('name', 'value', {
|
|
65
|
+
httpOnly: true,
|
|
66
|
+
secure: true,
|
|
67
|
+
sameSite: 'lax', // 'strict' | 'lax' | 'none'
|
|
68
|
+
path: '/',
|
|
69
|
+
maxAge: 60 * 60 * 24,
|
|
70
|
+
expires: new Date('2027-01-01'),
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Names, `sameSite` and `expires` are checked, so a typo is an error rather than
|
|
75
|
+
a header the browser quietly ignores.
|
|
76
|
+
|
|
77
|
+
### A cookie you set is the one you read
|
|
78
|
+
|
|
79
|
+
For the rest of the request, `cookies().get()` returns the value you set, not
|
|
80
|
+
what the browser sent. That includes the sections an action `revalidate()`s,
|
|
81
|
+
which render in the same request. A deleted cookie is gone from `get`, `has`
|
|
82
|
+
and `getAll`. So an action that does `jar.set('agent', id)` then
|
|
83
|
+
`revalidate('all')` gets a sidebar rendered with the new choice. Next.js works
|
|
84
|
+
the same way. The next request starts from what the browser sends.
|
|
85
|
+
|
|
52
86
|
## Security headers
|
|
53
87
|
|
|
54
|
-
Nothing sets
|
|
55
|
-
decision. The ones that are the same on every page go in the config:
|
|
88
|
+
Nothing sets security headers for you. The ones that are the same on every page go in the config:
|
|
56
89
|
|
|
57
90
|
```ts title="vite.config.ts"
|
|
58
91
|
rscKit({
|
|
@@ -65,72 +98,41 @@ rscKit({
|
|
|
65
98
|
})
|
|
66
99
|
```
|
|
67
100
|
|
|
68
|
-
Every response gets them
|
|
69
|
-
[edge may serve from its cache](/guides/edge-caching): they are fixed for the
|
|
70
|
-
build, so the edge sends them with its copy. A middleware's own value for the
|
|
71
|
-
same header wins.
|
|
101
|
+
Every response gets them.
|
|
72
102
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
`X-
|
|
103
|
+
They are fixed for the build, so a page can still be
|
|
104
|
+
[served from an edge's cache](/guides/edge-caching) with them. Only headers an
|
|
105
|
+
edge can send with a cached page are accepted: `Content-Language`,
|
|
106
|
+
`X-Robots-Tag`, `Content-Security-Policy`,
|
|
107
|
+
`Content-Security-Policy-Report-Only`, `Permissions-Policy`,
|
|
108
|
+
`Referrer-Policy`, `Strict-Transport-Security`, `X-Frame-Options`,
|
|
109
|
+
`X-Content-Type-Options`, `Cross-Origin-Opener-Policy`,
|
|
77
110
|
`Cross-Origin-Embedder-Policy`, `Cross-Origin-Resource-Policy` and
|
|
78
|
-
`X-DNS-Prefetch-Control`. Anything else is a build error
|
|
79
|
-
`
|
|
80
|
-
response.
|
|
111
|
+
`X-DNS-Prefetch-Control`. Anything else is a build error. `Cache-Control` and
|
|
112
|
+
`Link` are left out because the renderer sets them per response.
|
|
81
113
|
|
|
82
|
-
A header that depends on the request goes in a middleware
|
|
83
|
-
|
|
84
|
-
edge's cache
|
|
114
|
+
- **A header that depends on the request** goes in a middleware. A middleware's
|
|
115
|
+
value for a header wins over the config's. A page under a middleware is never
|
|
116
|
+
served from an edge's cache, so a root `middleware.ts` keeps every page out.
|
|
117
|
+
- **`Content-Security-Policy`** needs each page's inline code allowed. Use
|
|
118
|
+
[`contentSecurityPolicy`](/guides/content-security-policy), which adds the
|
|
119
|
+
hashes, and a nonce where the page streams.
|
|
85
120
|
|
|
86
|
-
|
|
87
|
-
has inline code of its own to allow. Set it with
|
|
88
|
-
[`contentSecurityPolicy`](/guides/content-security-policy) instead, which adds
|
|
89
|
-
each page's hashes, and a nonce where it streams.
|
|
121
|
+
## Headers rsc-kit sets
|
|
90
122
|
|
|
91
|
-
|
|
123
|
+
**`X-RSC-Kit`** says how a response was served: `stored` (a page the build
|
|
124
|
+
wrote), `rendered` (rendered for this visitor) or `shell` (a stored shell with
|
|
125
|
+
its holes rendered now). Check it in the Network tab when a page is slower
|
|
126
|
+
than expected, or key a CDN rule or health check on it. It's the equivalent of
|
|
127
|
+
`X-Nextjs-Cache`.
|
|
92
128
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
secure: true,
|
|
97
|
-
sameSite: 'lax', // 'strict' | 'lax' | 'none'
|
|
98
|
-
path: '/',
|
|
99
|
-
maxAge: 60 * 60 * 24,
|
|
100
|
-
expires: new Date('2027-01-01'),
|
|
101
|
-
})
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Names are validated as cookie tokens and `sameSite` / `expires` are checked, so
|
|
105
|
-
a typo is an error rather than a header the browser quietly ignores.
|
|
106
|
-
|
|
107
|
-
A cookie set is the cookie read, for the rest of the request. After
|
|
108
|
-
`jar.set('agent', id)`, every `cookies().get('agent')` in the same request —
|
|
109
|
-
in the action, and in the sections it `revalidate()`s, which render in the
|
|
110
|
-
same request and travel back with the answer — sees `id`, not what the
|
|
111
|
-
browser sent; a deleted one is gone from `get`, `has` and `getAll`. This is
|
|
112
|
-
Next's rule too, and it is what makes `set` then `revalidate('all')` the
|
|
113
|
-
whole of a switcher: the sidebar re-renders with the choice the browser is
|
|
114
|
-
about to hold. The next request starts from what it arrives with.
|
|
115
|
-
|
|
116
|
-
## What a response says about itself
|
|
117
|
-
|
|
118
|
-
Two things, and they are not the same kind:
|
|
119
|
-
|
|
120
|
-
**How it was served**, always: `X-RSC-Kit: stored`, `rendered` or `shell` on
|
|
121
|
-
every response — a page from a file the build wrote, a page rendered for this
|
|
122
|
-
visitor, or a stored shell with its holes rendered now. It is the header a
|
|
123
|
-
developer reads in the Network tab when a page is slower than expected, the
|
|
124
|
-
way `X-Nextjs-Cache` is, and a CDN rule or a health check can key on it. It
|
|
125
|
-
names no product, so there is nothing to strip.
|
|
126
|
-
|
|
127
|
-
**What built it**, by default: `X-Powered-By: rsc-kit` on every response and
|
|
128
|
-
`<meta name="generator" content="rsc-kit">` in every document — what
|
|
129
|
-
BuiltWith and Wappalyzer read. The name only, never the version: a version in
|
|
130
|
-
every response is what a vulnerability scanner filters on. A policy that
|
|
131
|
-
strips every framework identifier turns both off, which matters for the tag,
|
|
132
|
-
since a proxy can strip a header but not a line inside the HTML:
|
|
129
|
+
**`X-Powered-By: rsc-kit`** on every response, and
|
|
130
|
+
`<meta name="generator" content="rsc-kit">` in every document, name the
|
|
131
|
+
framework but never its version. To turn both off:
|
|
133
132
|
|
|
134
133
|
```ts title="vite.config.ts"
|
|
135
134
|
rscKit({ identify: false })
|
|
136
135
|
```
|
|
136
|
+
|
|
137
|
+
A proxy can strip the header but not the tag inside the HTML, which is why
|
|
138
|
+
the option exists.
|
|
@@ -2,41 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
> Opening a route as a modal over the page you were on.
|
|
4
4
|
|
|
5
|
-
Route interception
|
|
5
|
+
Route interception opens a route over the page you are on, usually as a modal.
|
|
6
|
+
Clicking a photo in a feed opens it in a modal, and the feed stays behind it.
|
|
7
|
+
Refreshing, or opening the link directly, shows the photo's own page:
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
```text
|
|
10
|
+
src/app/
|
|
11
|
+
layout.tsx renders {children} and {modal}
|
|
12
|
+
page.tsx the feed
|
|
13
|
+
@modal/
|
|
14
|
+
default.tsx nothing, when no modal is open
|
|
15
|
+
(.)photo/[id]/
|
|
16
|
+
page.tsx the photo, in a modal
|
|
17
|
+
photo/[id]/
|
|
18
|
+
page.tsx the photo's own page
|
|
19
|
+
```
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
The prefixes are the same as Next.js:
|
|
10
22
|
|
|
11
23
|
| Prefix | Intercepts |
|
|
12
24
|
| --- | --- |
|
|
13
|
-
| (.)folder |
|
|
14
|
-
| (..)folder |
|
|
15
|
-
| (...)folder |
|
|
16
|
-
|
|
17
|
-
## A photo modal
|
|
25
|
+
| `(.)folder` | A route at the same level |
|
|
26
|
+
| `(..)folder` | A route one level up |
|
|
27
|
+
| `(...)folder` | A route from the app root |
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
## Opening a page in a modal
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```tsx title="File structure"
|
|
24
|
-
src/app/
|
|
25
|
-
├── layout.tsx ← renders {children} + {modal}
|
|
26
|
-
├── page.tsx ← feed page
|
|
27
|
-
├── @modal/
|
|
28
|
-
│ ├── default.tsx ← empty by default (no modal open)
|
|
29
|
-
│ └── (.)photo/[id]/
|
|
30
|
-
│ └── page.tsx ← photo modal (interceptor)
|
|
31
|
-
└── photo/[id]/
|
|
32
|
-
└── page.tsx ← full photo page (hard nav)
|
|
33
|
-
```
|
|
31
|
+
Interception builds on [parallel routes](/guides/routing#parallel-routes): the
|
|
32
|
+
modal is a slot. The layout receives it as a prop and renders it:
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
The layout receives the `modal` parallel slot as a prop. No special wrapper component needed — just render it directly:
|
|
38
|
-
|
|
39
|
-
```tsx title="app/layout.tsx"
|
|
34
|
+
```tsx title="src/app/layout.tsx"
|
|
40
35
|
export default function Layout({
|
|
41
36
|
children,
|
|
42
37
|
modal,
|
|
@@ -45,54 +40,77 @@ export default function Layout({
|
|
|
45
40
|
modal: React.ReactNode;
|
|
46
41
|
}) {
|
|
47
42
|
return (
|
|
48
|
-
|
|
43
|
+
<>
|
|
49
44
|
<main>{children}</main>
|
|
50
45
|
{modal}
|
|
51
|
-
|
|
46
|
+
</>
|
|
52
47
|
);
|
|
53
48
|
}
|
|
54
49
|
```
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
The slot renders nothing until a navigation puts something in it:
|
|
57
52
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
```tsx title="app/@modal/default.tsx"
|
|
61
|
-
export default function ModalDefault() {
|
|
53
|
+
```tsx title="src/app/@modal/default.tsx"
|
|
54
|
+
export default function NoModal() {
|
|
62
55
|
return null;
|
|
63
56
|
}
|
|
64
57
|
```
|
|
65
58
|
|
|
66
|
-
|
|
59
|
+
The interceptor is an ordinary page inside the slot. It receives the target
|
|
60
|
+
route's `params`, and it can be a server component. Only the frame around it
|
|
61
|
+
needs to be interactive:
|
|
62
|
+
|
|
63
|
+
```tsx title="src/app/@modal/(.)photo/[id]/page.tsx"
|
|
64
|
+
import { Suspense } from 'react';
|
|
65
|
+
import { findPhoto } from '@/data';
|
|
66
|
+
|
|
67
|
+
export default function PhotoModal({ params }: { params: Promise<{ id: string }> }) {
|
|
68
|
+
return (
|
|
69
|
+
<ModalShell>
|
|
70
|
+
<Suspense fallback={<p>Loading…</p>}>
|
|
71
|
+
<Photo params={params} />
|
|
72
|
+
</Suspense>
|
|
73
|
+
</ModalShell>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function Photo({ params }: { params: Promise<{ id: string }> }) {
|
|
78
|
+
const { id } = await params;
|
|
79
|
+
const photo = await findPhoto(id);
|
|
80
|
+
|
|
81
|
+
return <img src={photo.url} alt={photo.title} />;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
67
84
|
|
|
68
|
-
The
|
|
85
|
+
The photo's own page is what a refresh or a shared link renders:
|
|
69
86
|
|
|
70
|
-
```tsx title="app
|
|
71
|
-
import {
|
|
72
|
-
import { findPhoto } from '../../../../data';
|
|
87
|
+
```tsx title="src/app/photo/[id]/page.tsx"
|
|
88
|
+
import { findPhoto } from '@/data';
|
|
73
89
|
|
|
74
|
-
export default async function
|
|
90
|
+
export default async function PhotoPage({ params }: { params: Promise<{ id: string }> }) {
|
|
91
|
+
const { id } = await params;
|
|
75
92
|
const photo = await findPhoto(id);
|
|
76
93
|
|
|
77
94
|
return (
|
|
78
|
-
<
|
|
79
|
-
<
|
|
80
|
-
<
|
|
81
|
-
</
|
|
95
|
+
<article>
|
|
96
|
+
<h1>{photo.title}</h1>
|
|
97
|
+
<img src={photo.url} alt={photo.title} />
|
|
98
|
+
</article>
|
|
82
99
|
);
|
|
83
100
|
}
|
|
84
101
|
```
|
|
85
102
|
|
|
86
|
-
Read the same data
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
not exist.
|
|
103
|
+
Read the same data in both. An interceptor pointed at a different source than
|
|
104
|
+
the page it stands in for looks exactly like a broken interception: the modal
|
|
105
|
+
opens correctly and says the record does not exist.
|
|
90
106
|
|
|
91
|
-
|
|
107
|
+
## Closing the modal
|
|
92
108
|
|
|
93
|
-
The engine puts the interceptor in the slot
|
|
109
|
+
The engine puts the interceptor in the slot. The ways to dismiss it are yours
|
|
110
|
+
to write, and a modal needs three: a close button, the `Escape` key, and a
|
|
111
|
+
click on the backdrop. The last two are the ones that get forgotten:
|
|
94
112
|
|
|
95
|
-
```tsx title="components/ModalShell.tsx"
|
|
113
|
+
```tsx title="src/components/ModalShell.tsx"
|
|
96
114
|
"use client";
|
|
97
115
|
|
|
98
116
|
import { useEffect, useRef } from 'react';
|
|
@@ -127,80 +145,63 @@ export function ModalShell({ children }: { children: ReactNode }) {
|
|
|
127
145
|
}
|
|
128
146
|
```
|
|
129
147
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
148
|
+
Close with `history.back()`, not a link to a fixed URL. Opening the modal
|
|
149
|
+
pushed a history entry over the page beneath, so going back returns to
|
|
150
|
+
whichever page it was opened over. A hardcoded destination is wrong as soon as
|
|
151
|
+
the same modal opens from two places.
|
|
133
152
|
|
|
134
|
-
|
|
153
|
+
The router sees going back as leaving the interception and empties the slot
|
|
154
|
+
without asking the server for anything. The page underneath never left, so
|
|
155
|
+
closing costs no request, and anything typed into it is still there.
|
|
135
156
|
|
|
136
|
-
|
|
157
|
+
A modal that opens from exactly one place can link to that place instead. A
|
|
158
|
+
real `<Link>` is worth keeping then: it opens in a new tab, and it works before
|
|
159
|
+
the page hydrates.
|
|
137
160
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
```tsx title="app/photo/[id]/page.tsx"
|
|
141
|
-
export default function PhotoPage({ id }: { id: string }) {
|
|
142
|
-
return (
|
|
143
|
-
<div>
|
|
144
|
-
<h1>Photo {id}</h1>
|
|
145
|
-
<p>Full photo page — shown on direct navigation or refresh.</p>
|
|
146
|
-
</div>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## How it works
|
|
161
|
+
## Intercepting from another level
|
|
152
162
|
|
|
153
|
-
|
|
163
|
+
Use `(..)` for a route one level up, and `(...)` for a route from the app root:
|
|
154
164
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
- It renders the interceptor *alone*, and says so with `X-RSC-Revalidate: modal`
|
|
159
|
-
- The client puts it in that slot. The page underneath is never re-rendered — so a half-filled form on it is still half-filled
|
|
165
|
+
```text
|
|
166
|
+
# From /feed, intercept /photo/[id] at the same level
|
|
167
|
+
src/app/@modal/(.)photo/[id]/page.tsx
|
|
160
168
|
|
|
161
|
-
|
|
169
|
+
# From /feed/trending, intercept /photo/[id] one level up
|
|
170
|
+
src/app/feed/@modal/(..)photo/[id]/page.tsx
|
|
162
171
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
Re-rendering the page underneath would put the modal on screen at the
|
|
167
|
-
cost of rebuilding everything below the layout that declares the slot.
|
|
168
|
-
That page is already mounted and still correct; only the slot is new.
|
|
169
|
-
|
|
170
|
-
## Nested interception
|
|
171
|
-
|
|
172
|
-
Use `(..)` to intercept routes one level up, or `(...)` to intercept from the app root:
|
|
173
|
-
|
|
174
|
-
```tsx title="Intercepting from a nested page"
|
|
175
|
-
// From /feed, intercept /photo/[id] at the same level
|
|
176
|
-
app/@modal/(.)photo/[id]/page.tsx
|
|
177
|
-
|
|
178
|
-
// From /feed/trending, intercept /photo/[id] one level up
|
|
179
|
-
app/feed/@modal/(..)photo/[id]/page.tsx
|
|
180
|
-
|
|
181
|
-
// From /dashboard/settings, intercept /photo/[id] from root
|
|
182
|
-
app/dashboard/settings/@drawer/(...)photo/[id]/page.tsx
|
|
172
|
+
# From /dashboard/settings, intercept /photo/[id] from the root
|
|
173
|
+
src/app/dashboard/settings/@drawer/(...)photo/[id]/page.tsx
|
|
183
174
|
```
|
|
184
175
|
|
|
185
|
-
##
|
|
176
|
+
## Intercepting into several slots
|
|
186
177
|
|
|
187
|
-
|
|
178
|
+
The same route can be intercepted into different slots:
|
|
188
179
|
|
|
189
|
-
```
|
|
190
|
-
app/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
180
|
+
```text
|
|
181
|
+
src/app/
|
|
182
|
+
@modal/(.)photo/[id]/page.tsx renders in the modal slot
|
|
183
|
+
@preview/(.)photo/[id]/page.tsx renders in the preview slot
|
|
184
|
+
photo/[id]/page.tsx the photo's own page
|
|
194
185
|
```
|
|
195
186
|
|
|
196
187
|
## Seeing it work
|
|
197
188
|
|
|
198
|
-
The example app in the repository has
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
The example app in the repository has one: `@modal/(.)posts/[slug]` over a
|
|
190
|
+
feed of posts. Click a post to open it in a modal, then refresh to get the
|
|
191
|
+
same route as a page.
|
|
192
|
+
|
|
193
|
+
## How it works
|
|
194
|
+
|
|
195
|
+
On a client navigation, through a `Link`:
|
|
201
196
|
|
|
202
|
-
|
|
197
|
+
- The client checks the intercept manifest, which the build generates.
|
|
198
|
+
- If the target URL matches an intercept pattern, headers are added to the
|
|
199
|
+
request.
|
|
200
|
+
- The server resolves the current page from the referer URL, to know which
|
|
201
|
+
slot the interceptor belongs in.
|
|
202
|
+
- It renders the interceptor *alone*, and says so with `X-RSC-Revalidate: modal`.
|
|
203
|
+
- The client puts it in that slot. The page underneath is never rendered
|
|
204
|
+
again, so a half-filled form on it is still half-filled.
|
|
203
205
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
inside a slot, and everything a slot does applies to it.
|
|
206
|
+
On a full page load, from a refresh or a direct URL, routes match as normal:
|
|
207
|
+
`/photo/123` renders `photo/[id]/page.tsx`, and nothing is intercepted.
|