@rsc-kit/mcp 0.41.0 → 0.42.1
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 +18 -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 +270 -216
- 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
package/guides/emails.md
CHANGED
|
@@ -2,25 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> Rendering React to HTML on the server — an email, a PDF, a feed — from a server action or a route, with "use ssr".
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
a server action and this comes back:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
Error: react-dom/server is not supported in React Server Components.
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
React means it. Where server components render, `react` is a server-only
|
|
14
|
-
build: the renderer needs the client build's internals, and the components it
|
|
15
|
-
would render import that same `react` — no `useState`, no `useContext`. Nothing
|
|
16
|
-
that renders React to HTML can run there, and no alias fixes that. It has to
|
|
17
|
-
run in the **ssr** environment, which every app here already has: the one that
|
|
18
|
-
turns your pages into HTML for the browser.
|
|
19
|
-
|
|
20
|
-
## `"use ssr"`
|
|
21
|
-
|
|
22
|
-
Put the rendering — the template and the call that renders it — in a module
|
|
23
|
-
that starts with the directive:
|
|
5
|
+
To render React to an HTML string on the server, for an email, a PDF or a feed,
|
|
6
|
+
put the rendering in a module that starts with `"use ssr"`:
|
|
24
7
|
|
|
25
8
|
```tsx title="src/lib/email/render.tsx"
|
|
26
9
|
"use ssr";
|
|
@@ -40,7 +23,7 @@ export async function renderOtpEmail(code: string) {
|
|
|
40
23
|
}
|
|
41
24
|
```
|
|
42
25
|
|
|
43
|
-
|
|
26
|
+
Then import it from anywhere, a server action included:
|
|
44
27
|
|
|
45
28
|
```ts title="src/lib/email/send-otp.ts"
|
|
46
29
|
import { renderOtpEmail } from './render';
|
|
@@ -52,34 +35,93 @@ export async function sendOtpEmail(to: string, code: string) {
|
|
|
52
35
|
}
|
|
53
36
|
```
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
There's nothing to configure.
|
|
39
|
+
|
|
40
|
+
## Why it needs the directive
|
|
41
|
+
|
|
42
|
+
Without it, a server action that calls `@react-email/render` (or
|
|
43
|
+
`renderToString` from `react-dom/server`) fails:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
Error: react-dom/server is not supported in React Server Components.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Where server components render, `react` is a server-only build, with no
|
|
50
|
+
`useState` and no `useContext`. Rendering React to HTML needs the client build,
|
|
51
|
+
so it can't run there, and no alias fixes that. It has to run in the **ssr**
|
|
52
|
+
environment, which every app already has: it's the one that turns your pages
|
|
53
|
+
into HTML for the browser. `"use ssr"` puts a module there.
|
|
54
|
+
|
|
55
|
+
## Writing an email template
|
|
56
|
+
|
|
57
|
+
The template is an ordinary component, with no directive:
|
|
58
|
+
|
|
59
|
+
```tsx title="src/lib/email/otp-email.tsx"
|
|
60
|
+
import { Html, Body, Heading, Text } from '@react-email/components';
|
|
61
|
+
|
|
62
|
+
export function OtpEmail({ code }: { code: string }) {
|
|
63
|
+
return (
|
|
64
|
+
<Html>
|
|
65
|
+
<Body>
|
|
66
|
+
<Heading>Your sign-in code</Heading>
|
|
67
|
+
<Text>{code}</Text>
|
|
68
|
+
</Body>
|
|
69
|
+
</Html>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Only the `"use ssr"` module imports it, so it's bundled for the ssr
|
|
75
|
+
environment along with `@react-email/components`.
|
|
76
|
+
|
|
77
|
+
## Rendering HTML in an API route
|
|
78
|
+
|
|
79
|
+
A route that answers with a standalone HTML document, such as a printable
|
|
80
|
+
invoice, calls the same kind of module:
|
|
81
|
+
|
|
82
|
+
```tsx title="src/lib/invoices/render.tsx"
|
|
83
|
+
"use ssr";
|
|
84
|
+
|
|
85
|
+
import { renderToString } from 'react-dom/server';
|
|
86
|
+
import { InvoiceDocument } from './invoice-document';
|
|
87
|
+
|
|
88
|
+
export async function renderInvoice(invoice: Invoice) {
|
|
89
|
+
return '<!doctype html>' + renderToString(<InvoiceDocument invoice={invoice} />);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```ts title="src/app/invoices/[id]/print/route.ts"
|
|
94
|
+
import type { RouteContext } from '@rsc-kit/core/route-schema';
|
|
95
|
+
import { renderInvoice } from '@/lib/invoices/render';
|
|
96
|
+
|
|
97
|
+
export async function GET(request: Request, { params }: RouteContext<'/invoices/[id]/print'>) {
|
|
98
|
+
const { id } = await params;
|
|
99
|
+
const html = await renderInvoice(await findInvoice(id));
|
|
100
|
+
|
|
101
|
+
return new Response(html, { headers: { 'Content-Type': 'text/html; charset=utf-8' } });
|
|
102
|
+
}
|
|
103
|
+
```
|
|
61
104
|
|
|
62
105
|
## The rules
|
|
63
106
|
|
|
64
107
|
**Exports are async functions.** A call crosses environments, so the answer is
|
|
65
108
|
a promise. A function declared without `async` is refused at build with its
|
|
66
|
-
name
|
|
109
|
+
name, and so is a value, a class, `export { … }` or `export *`. Types are fine.
|
|
67
110
|
|
|
68
|
-
**Pass data across, not elements.**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
**Pass data across, not elements.** Create the template inside the module from
|
|
112
|
+
the arguments: `renderOtpEmail(code)`, not `render(<OtpEmail />)` from the
|
|
113
|
+
caller. An element built where server components render carries components
|
|
114
|
+
from that side's `react`, and they would render with no hooks.
|
|
72
115
|
|
|
73
116
|
**The module's imports belong to the ssr side.** `@react-email/components`,
|
|
74
|
-
`react-dom/server`, a PDF renderer
|
|
75
|
-
resolved and bundled for the ssr environment. A database client works
|
|
76
|
-
too, but belongs on the calling side
|
|
117
|
+
`react-dom/server`, a PDF renderer or a Markdown library that uses React are
|
|
118
|
+
all resolved and bundled for the ssr environment. A database client works
|
|
119
|
+
there too, but it belongs on the calling side. Keep the module to rendering.
|
|
77
120
|
|
|
78
|
-
## If you import
|
|
121
|
+
## If you import react-dom/server directly
|
|
79
122
|
|
|
80
|
-
`react-dom/server` imported where server components render
|
|
81
|
-
library,
|
|
82
|
-
refusal:
|
|
123
|
+
`react-dom/server` imported where server components render, usually through a
|
|
124
|
+
library, fails with the fix in the message instead of React's refusal:
|
|
83
125
|
|
|
84
126
|
```
|
|
85
127
|
react-dom/server cannot run where server components render … Imported by
|
|
@@ -87,16 +129,25 @@ src/lib/nodemailer.ts. Put the rendering — the template and the call — in a
|
|
|
87
129
|
module that starts with "use ssr" …
|
|
88
130
|
```
|
|
89
131
|
|
|
90
|
-
A build prints the same once, as a warning
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
132
|
+
A build prints the same message once, as a warning naming the file, and still
|
|
133
|
+
succeeds. The refusal belongs to the call, not the import: every export of the
|
|
134
|
+
stub throws it when called, so a server doesn't fail to boot over an action
|
|
135
|
+
nobody has run yet.
|
|
94
136
|
|
|
95
|
-
A dependency whose imports the build never looks inside
|
|
96
|
-
imported from an action,
|
|
97
|
-
the same way, naming the app file and the package:
|
|
137
|
+
A dependency whose imports the build never looks inside, such as
|
|
138
|
+
`@react-email/render` imported from an action, is read once for the import and
|
|
139
|
+
warned about the same way, naming the app file and the package:
|
|
98
140
|
|
|
99
141
|
```
|
|
100
142
|
src/actions/send-otp.ts imports @react-email/render, which imports
|
|
101
143
|
react-dom/server, and that cannot run where server components render …
|
|
102
144
|
```
|
|
145
|
+
|
|
146
|
+
## How it works
|
|
147
|
+
|
|
148
|
+
A `"use ssr"` module runs in the ssr environment, in the same process. Where
|
|
149
|
+
server components render, the build replaces it with proxies of its exports
|
|
150
|
+
that call across. It's what `"use client"` does for a component, in the other
|
|
151
|
+
direction. In development, the proxy calls into the ssr module runner. In a
|
|
152
|
+
build, the module is part of the ssr bundle, and the proxies import it from
|
|
153
|
+
there.
|
package/guides/errors.md
CHANGED
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
> What a visitor sees when a page throws, or asks for a url nothing answers.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
An `error.tsx` is what a visitor sees when a page throws, and a `not-found.tsx`
|
|
6
|
+
is what they see for a page that doesn't exist. Both are optional, and the one
|
|
7
|
+
nearest the page wins.
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
nothing — React unmounted the document on hydration, a black page with the
|
|
15
|
-
cause nowhere near it.
|
|
9
|
+
```text
|
|
10
|
+
src/app/
|
|
11
|
+
not-found.tsx any url no route matches
|
|
12
|
+
orders/
|
|
13
|
+
error.tsx anything under /orders that throws
|
|
14
|
+
```
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
## Showing an error page
|
|
18
17
|
|
|
19
|
-
Put an `error.tsx` in the
|
|
18
|
+
Put an `error.tsx` in the folder you want to cover:
|
|
20
19
|
|
|
21
20
|
```tsx title="src/app/orders/error.tsx"
|
|
22
21
|
'use client'
|
|
@@ -35,42 +34,42 @@ export default function OrdersError({ error, reset }: RouteErrorProps) {
|
|
|
35
34
|
```
|
|
36
35
|
|
|
37
36
|
Anything below it that throws renders this instead. The layouts above stay on
|
|
38
|
-
screen
|
|
37
|
+
screen; only the part that failed is replaced.
|
|
38
|
+
|
|
39
|
+
It must start with `'use client'`, or the build refuses it. Catching a render
|
|
40
|
+
error happens in the browser, and `reset` is a callback the browser calls.
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
not call `refresh()` beside it or reload the document. Navigating away clears
|
|
45
|
-
the error on its own.
|
|
42
|
+
Without an `error.tsx`, a page that throws shows the engine's error page where
|
|
43
|
+
the page was, with the layouts around it kept and a **Try again** button. In
|
|
44
|
+
development it shows the message and stack; in production, "Something went
|
|
45
|
+
wrong" and the digest to search the server log for.
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
`'use client'` at the top, or the build refuses it. Catching a render error is
|
|
49
|
-
a class component's job, it runs in the browser, and `reset` is a callback the
|
|
50
|
-
browser calls — none of which a server component can do.
|
|
51
|
-
:::
|
|
47
|
+
### Trying again
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
`reset()` asks the server for the page again and renders the answer. It suits
|
|
50
|
+
a failure that might not happen twice, such as a service that was down for a
|
|
51
|
+
moment. The error stays on screen until the new page arrives, and shows again
|
|
52
|
+
if the page fails again. Don't call `refresh()` beside it or reload the
|
|
53
|
+
document. Navigating away clears the error too.
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
That is React, not this package: the real message could name a table, a query or
|
|
57
|
-
a path, and none of that should reach a browser.
|
|
55
|
+
### The message in production
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
React replaces `error.message` with a generic sentence and puts a hash on
|
|
58
|
+
`error.digest`, so a message naming a table, a query or a path never reaches a
|
|
59
|
+
browser. Log the digest where you log the error, and the two line up.
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### What it doesn't catch
|
|
62
62
|
|
|
63
|
-
- **
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- **
|
|
67
|
-
|
|
68
|
-
goes wrong, not a page that is broken.
|
|
63
|
+
- **A layout above it that throws.** The boundary sits inside that layout, so
|
|
64
|
+
put an `error.tsx` a folder higher. The engine's own error page is outermost
|
|
65
|
+
and catches those too.
|
|
66
|
+
- **A page that throws every time it renders.** That fails the build instead of
|
|
67
|
+
shipping a stored error page.
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
## Handling a refusal in a server component
|
|
71
70
|
|
|
72
|
-
A
|
|
73
|
-
|
|
71
|
+
A refused `rpc()` throws an error you can check for, so a server component can
|
|
72
|
+
show something else instead of failing:
|
|
74
73
|
|
|
75
74
|
```tsx
|
|
76
75
|
import { ServerAuthenticationError } from '@rsc-kit/core/errors'
|
|
@@ -85,46 +84,20 @@ async function Invite({ token }: { token: string }) {
|
|
|
85
84
|
}
|
|
86
85
|
```
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
handle, so a not-found or a redirect still does what it should.
|
|
87
|
+
| Error | When |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `ServerAuthenticationError` | the backend answered 401 |
|
|
90
|
+
| `ServerAuthorizationError` | the backend answered 403 |
|
|
93
91
|
|
|
94
|
-
|
|
92
|
+
A refusal with a status of its own (`abort(429)`, Go's `Refuse(503, …)`)
|
|
93
|
+
carries it as `error.refusalStatus`, beside the backend's message. Left
|
|
94
|
+
uncaught, the page answers with that status.
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
which is imported by src/app/teams/controls.tsx
|
|
100
|
-
```
|
|
96
|
+
Rethrow what you don't handle, so a not-found or a redirect still works.
|
|
97
|
+
|
|
98
|
+
## Showing a 404 page
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
imports reaches `request`, `redirect`, `revalidate`, `cache`, `section`, or
|
|
104
|
-
anything else of this package that only makes sense on a server. The usual
|
|
105
|
-
cause is a helper file that two kinds of code share: a page calls its
|
|
106
|
-
`redirect()`, and a client component imports its `label()`. The import loads,
|
|
107
|
-
nothing in the browser calls it, and the only trace used to be Vite saying a
|
|
108
|
-
Node builtin had been "externalized for browser compatibility" — while the
|
|
109
|
-
server's request-scope code shipped to every visitor.
|
|
110
|
-
|
|
111
|
-
Split the file. What needs the server module goes in one only server components
|
|
112
|
-
import; what a client component needs goes in the other. A type-only import is
|
|
113
|
-
erased and never counts.
|
|
114
|
-
|
|
115
|
-
Mark your own server-only files the same way, with `import 'server-only'`.
|
|
116
|
-
The build honours it the same way: a client file that reaches it fails with
|
|
117
|
-
the files that brought it there. (This package cannot put that import in its own
|
|
118
|
-
modules, because the real package throws under any runtime that is not a
|
|
119
|
-
server-components build — a unit test of anything calling `cookies()` included.)
|
|
120
|
-
|
|
121
|
-
## When nothing answers the url
|
|
122
|
-
|
|
123
|
-
`src/app/not-found.tsx` is rendered for any url no route matches — and a
|
|
124
|
-
client-side navigation to one renders it in place, layout kept, url changed,
|
|
125
|
-
status still 404, the way Next.js does once the page is overridden. Without
|
|
126
|
-
the file, a navigation to a missing url is a full document load of a plain
|
|
127
|
-
"Not found":
|
|
100
|
+
`src/app/not-found.tsx` renders for any url no route matches:
|
|
128
101
|
|
|
129
102
|
```tsx title="src/app/not-found.tsx"
|
|
130
103
|
import Link from '@rsc-kit/core/Link'
|
|
@@ -139,31 +112,28 @@ export default function NotFound() {
|
|
|
139
112
|
}
|
|
140
113
|
```
|
|
141
114
|
|
|
142
|
-
It renders
|
|
143
|
-
|
|
144
|
-
|
|
115
|
+
- It renders inside your root layout, with a real **404** status, so search
|
|
116
|
+
engines don't index it.
|
|
117
|
+
- It is a server component, so it can be `async` and read cookies.
|
|
118
|
+
- A client-side navigation to a missing url renders it in place, with the
|
|
119
|
+
layout kept and the url changed.
|
|
145
120
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
`Not found` string.
|
|
121
|
+
Without one, an unmatched url gets a plain `Not found`, and a navigation to it
|
|
122
|
+
is a full page load.
|
|
149
123
|
|
|
150
|
-
Only a request that can show a page gets it
|
|
151
|
-
|
|
152
|
-
|
|
124
|
+
Only a request that can show a page gets it. A missing image, script, font or
|
|
125
|
+
stylesheet - a browser's `/favicon.ico` - gets a plain 404 at once. This holds
|
|
126
|
+
under a dynamic route like `/[team]` too: a request the browser marks as one of
|
|
127
|
+
those (`Sec-Fetch-Dest`) gets a plain 404 before any of the route's middleware
|
|
128
|
+
runs. A `route.ts` still answers it, since an image endpoint is a route, not a
|
|
129
|
+
page.
|
|
153
130
|
|
|
154
|
-
|
|
155
|
-
a page never answers an image, a script, a stylesheet or a font: a request the
|
|
156
|
-
browser marks as one (`Sec-Fetch-Dest`) gets a plain 404 before any of the
|
|
157
|
-
route's middleware runs. A `route.ts` still answers such a request — an image
|
|
158
|
-
endpoint is a route, not a page — and a navigation, a `fetch()`, or a client
|
|
159
|
-
that does not say, gets the page as always.
|
|
131
|
+
### A 404 page for one part of the site
|
|
160
132
|
|
|
161
|
-
|
|
133
|
+
A `not-found.tsx` beside a layout answers `notFound()` from every page under
|
|
134
|
+
it, inside that layout:
|
|
162
135
|
|
|
163
|
-
|
|
164
|
-
it, inside that layout, the way an `error.tsx` catches what fails under it:
|
|
165
|
-
|
|
166
|
-
```
|
|
136
|
+
```text
|
|
167
137
|
src/app/
|
|
168
138
|
layout.tsx
|
|
169
139
|
not-found.tsx ← an unmatched url, and anything outside the shop
|
|
@@ -173,17 +143,15 @@ src/app/
|
|
|
173
143
|
c/[category]/[sub]/[product]/page.tsx
|
|
174
144
|
```
|
|
175
145
|
|
|
176
|
-
The nearest one above the page that said so wins
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
under, so only the root `not-found.tsx` answers it: a section's does not leak
|
|
181
|
-
out to the whole site.
|
|
146
|
+
The nearest one above the page that said so wins, whether `notFound()` came
|
|
147
|
+
from the page's body, a read under `<Suspense>` or a `middleware.ts`. An url no
|
|
148
|
+
route owns has no page to be under, so only the root `not-found.tsx` answers
|
|
149
|
+
it.
|
|
182
150
|
|
|
183
|
-
|
|
151
|
+
## When the page has to decide
|
|
184
152
|
|
|
185
|
-
|
|
186
|
-
|
|
153
|
+
`/posts/42` matches a route, but there may be no post 42. Call `notFound()`
|
|
154
|
+
from the page:
|
|
187
155
|
|
|
188
156
|
```tsx title="src/app/posts/[slug]/page.tsx"
|
|
189
157
|
import { notFound } from '@rsc-kit/core/not-found'
|
|
@@ -197,35 +165,46 @@ export default async function PostPage({ params }) {
|
|
|
197
165
|
}
|
|
198
166
|
```
|
|
199
167
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
168
|
+
It throws, so nothing after it runs. If you wrap it in a `try`/`catch`, rethrow
|
|
169
|
+
what you don't recognise, or the missing page becomes a blank region.
|
|
170
|
+
|
|
171
|
+
### Where you call it decides the status
|
|
172
|
+
|
|
173
|
+
- **Above every `<Suspense>`** - at the top of a page, or in a layout - nothing
|
|
174
|
+
has been sent yet, and the response is a real 404.
|
|
175
|
+
- **Inside a `<Suspense>` boundary**, the page has already started streaming
|
|
176
|
+
with a `200`. The browser then shows your `not-found.tsx` where the page was,
|
|
177
|
+
with the layouts above it kept and the url unchanged, and adds
|
|
178
|
+
`<meta name="robots" content="noindex">` so search engines skip it.
|
|
179
|
+
|
|
180
|
+
Search engines and link-preview scrapers always get the real status: they are
|
|
181
|
+
answered once the whole page has rendered, so `notFound()` is a 404 and
|
|
182
|
+
`redirect()` a redirect wherever they were called. The engine recognises them
|
|
183
|
+
by user agent - Googlebot, Bingbot, Applebot, DuckDuckBot, Yandex, Baidu, and
|
|
184
|
+
the preview fetchers of Facebook, X, LinkedIn, Slack, Discord, WhatsApp,
|
|
185
|
+
Telegram and others.
|
|
186
|
+
|
|
187
|
+
A page under a `loading.tsx` is always inside a boundary. When a person must
|
|
188
|
+
get a real 404 - a record their account can't see - check in a `middleware.ts`
|
|
189
|
+
beside the page. It runs before anything is sent, even for a page the build
|
|
190
|
+
stored. Its argument is the route's params as a plain object: `{ slug: '42' }`.
|
|
191
|
+
|
|
192
|
+
## A server module in the browser bundle
|
|
193
|
+
|
|
194
|
+
```txt
|
|
195
|
+
[rsc-kit] '@rsc-kit/core/redirect' is for the server, and ended up in the browser bundle:
|
|
196
|
+
imported by src/lib/team.ts
|
|
197
|
+
which is imported by src/app/teams/controls.tsx
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The build stops, and in development the module fails to load, when a file the
|
|
201
|
+
browser imports reaches `request`, `redirect`, `revalidate`, `cache`,
|
|
202
|
+
`section`, or any other part of this package that only works on a server.
|
|
203
|
+
|
|
204
|
+
The usual cause is a helper file shared by both kinds of code: a page calls its
|
|
205
|
+
`redirect()`, and a client component imports its `label()`. Split it into two
|
|
206
|
+
files - one only server components import, one the client can. A type-only
|
|
207
|
+
import doesn't count.
|
|
208
|
+
|
|
209
|
+
Mark your own server-only files with `import 'server-only'`. A client file that
|
|
210
|
+
reaches one fails the same way, naming the files that brought it there.
|