@rsc-kit/mcp
Version:
An MCP server over what an rsc-kit build decided: the routes, why each one is static or not, and what it costs the browser.
119 lines (89 loc) • 5.21 kB
Markdown
# A page with no JavaScript
> The default is none. A client component is how a page asks for it.
A page ships no JavaScript until something on it needs some. A marketing page,
a changelog, an article or a policy is stored as HTML, with no React and no
router. The build says so on the route's line:
```
○ /about no js
no client components, so ships no javascript; stylesheet inlined
```
## When a page gets JavaScript
A page gets the runtime when its tree has one of these:
- a client component (`"use client"`), such as a counter, a `<Link>` or an
update prompt
- a form with a server action, `<form action={serverFn}>`
- a Suspense boundary left to fill after the page arrives
There is no setting for it in either direction. The check reads the rendered
tree, not the source, so a client component in a shared layout counts. Most
pages under a layout with a `<Link>` in its header keep the runtime. A
[route group](/guides/routing#route-groups) with its own plain layout drops it.
Only a page stored whole can have none. A partial prerender has holes to fill
after the shell arrives, and a page rendered per request is not stored, so both
keep the runtime.
## Keeping a page this way
To make sure a page stays without JavaScript, check the build report in CI. A
route's `clientJs` in `build-report.json` is `null` when it shipped none.
## Stylesheets
A page's stylesheet is inlined into the document when it is at most 10 kB
gzipped, so the first paint waits for nothing but the document. The build says
so on the route's line. Change it with one setting:
```ts title="vite.config.ts"
rscKit({ inlineStylesheets: 'auto' }) // the default: when at most 10 kB gzipped
rscKit({ inlineStylesheets: false }) // never — keep the link, cache one file
rscKit({ inlineStylesheets: true }) // always, whatever the size
rscKit({ inlineStylesheets: 24_000 }) // your own cap, in gzipped bytes
```
A site of many small pages, such as a blog or documentation, may prefer one
stylesheet the browser caches once to the same 4 kB in every document.
- Every stored page is inlined, shells included.
- A page that hydrates keeps its `<link>` too, as `media="print"`: React looks
for its stylesheets by href and would otherwise fetch the file again. The
browser loads it at the lowest priority and never applies it on screen.
- A page rendered per request keeps its link.
Fonts are left to you, since only you know which face the first paint needs.
The [fonts guide](/guides/fonts) shows the two-line preload.
## What still works
- **The [service worker](/guides/offline) registers** when the app has one. Its
one-line registration is inlined, so a visitor who lands here first still
gets the worker. The update prompt is a client component, so a page that
shows it has the runtime.
- **Navigation works both ways.** The page's own links are ordinary anchors,
which load the next page in full. A `<Link>` on another page that points here
still navigates to it without a reload.
## A visitor with JavaScript turned off
A visitor with JavaScript turned off still gets what is inside a `<Suspense>`,
`loading.tsx` included. They see the fallback first, then the page loads once
more with everything in place.
React streams the inside of a boundary after its fallback and moves it into
place with a small inline script, which never runs for this visitor. So a
streamed page that left a boundary waiting carries one tag:
```html
<noscript><meta http-equiv="refresh" content="0;url='/reset-password/abc?_nojs=1'"></noscript>
```
A browser that runs scripts never reads it. One that does not follows it when
the document has loaded, and the marked url is answered the way a
[crawler](/guides/errors) is: once every boundary has rendered, each in its
place, with no tag on it. Your page never sees `_nojs`; `searchParams` and
`url()` are the page's own.
What it costs, and who pays:
- Only that visitor pays. The page loads twice, and the second answer waits
for its slowest read, so they wait about twice as long as the stream took.
- A visitor with JavaScript gets about 80 bytes of HTML and nothing else.
The client runtime is unchanged.
- A page with nothing waiting when its shell leaves carries no tag and loads
once.
- The marked url is another url to every cache, and is sent
`X-Robots-Tag: noindex`.
- A [partially prerendered](/guides/ppr) shell carries the tag too, whether the
renderer serves it or an [edge](/reference/edge-contract) serves it from its
cache, and one stored for a pattern such as `/docs/[slug]` names the url it
was served at. A shell from an edge names the path without its query, since
an edge serves one only to a url whose query is empty or campaign tags such
as `utm_source`; those are not carried to the second load.
A form posted without JavaScript is answered whole to begin with, so the
refusal beside a field is there on the first load.
Two things are not covered:
- A browser or extension that blocks a meta refresh keeps the fallback.
- JavaScript that is on but failed to load. `<noscript>` does not apply.
A page that must not load twice for these visitors keeps what matters outside
any boundary.