@rsc-kit/mcp 0.30.53 → 0.31.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 +71 -2
- package/dist/recipes.js.map +1 -1
- package/guides/content-security-policy.md +119 -0
- package/guides/deployment.md +33 -2
- package/guides/edge-caching.md +9 -0
- package/guides/go.md +14 -1
- package/guides/index.json +5 -0
- package/guides/isr.md +3 -1
- package/guides/laravel.md +3 -1
- package/guides/response-headers.md +5 -5
- package/guides/your-own-backend.md +17 -3
- package/package.json +2 -2
package/dist/recipes.js
CHANGED
|
@@ -710,7 +710,8 @@ not prerendered.
|
|
|
710
710
|
|
|
711
711
|
FOR AN EDGE THAT CACHES PAGES: rsc-kit implements the edge contract (v2,
|
|
712
712
|
docs: reference/edge-contract). Every server build writes .output/edge.json -
|
|
713
|
-
{ v: 2, build, shells, static, bypass }
|
|
713
|
+
{ v: 2, build, shells, static, bypass } (+ nonceShells under a
|
|
714
|
+
contentSecurityPolicy) - whose shells are url patterns ("/",
|
|
714
715
|
"/[team]/[app]", "/docs/[...slug]"), the ◐ pages, and whose static are
|
|
715
716
|
concrete paths, the ○ pages at the path each was rendered at: both less every
|
|
716
717
|
page with middleware (middleware.ts or the host's export const middleware) or
|
|
@@ -1672,6 +1673,63 @@ that strips framework identifiers; X-RSC-Kit stays. Do not strip X-RSC-Kit
|
|
|
1672
1673
|
at the proxy - it is what tells you whether a stored page was served.
|
|
1673
1674
|
|
|
1674
1675
|
Full guide: read_guide({ slug: 'response-headers' }).`,
|
|
1676
|
+
},
|
|
1677
|
+
{
|
|
1678
|
+
topic: 'content-security-policy',
|
|
1679
|
+
summary: 'A strict Content-Security-Policy on every page - rscKit({ contentSecurityPolicy }) adds each page\'s hashes, and a nonce where it streams',
|
|
1680
|
+
body: `\`\`\`ts title="vite.config.ts"
|
|
1681
|
+
rscKit({ contentSecurityPolicy: {} }) // strict default
|
|
1682
|
+
rscKit({
|
|
1683
|
+
contentSecurityPolicy: {
|
|
1684
|
+
directives: { 'default-src': ["'self'"], 'img-src': ["'self'", 'data:'], 'frame-ancestors': ["'none'"] },
|
|
1685
|
+
reportOnly: false, // true: Content-Security-Policy-Report-Only
|
|
1686
|
+
},
|
|
1687
|
+
})
|
|
1688
|
+
\`\`\`
|
|
1689
|
+
|
|
1690
|
+
{} is: default-src 'self'; base-uri 'self'; object-src 'none'; style-src-attr
|
|
1691
|
+
'unsafe-inline'. The engine adds a script-src and style-src naming the page's
|
|
1692
|
+
OWN inline code - the boot script, React's streaming scripts - so the policy
|
|
1693
|
+
needs no 'unsafe-inline'. How, by page:
|
|
1694
|
+
|
|
1695
|
+
- stored at build, or kept by revalidate: the hash of each inline script and
|
|
1696
|
+
style; no nonce, so caches still share it
|
|
1697
|
+
- a PPR shell: the shell's hashes plus a nonce for the holes resumed into it
|
|
1698
|
+
- rendered per request: a nonce, new per response, which React puts on every
|
|
1699
|
+
script it writes
|
|
1700
|
+
|
|
1701
|
+
The payload a page hydrates from is <script type="application/json"> data
|
|
1702
|
+
blocks: never run, never judged by the policy. A directive you wrote with
|
|
1703
|
+
'unsafe-inline' is left alone (a hash beside it would switch it off).
|
|
1704
|
+
|
|
1705
|
+
YOUR OWN inline code: a <script> or <style> in a stored page or shell is hashed
|
|
1706
|
+
and runs. One inside a <Suspense> hole, on a per-request page, or brought by a
|
|
1707
|
+
navigation is REFUSED - put CSS in a stylesheet and code in a module, or add
|
|
1708
|
+
'unsafe-inline' to style-src. Keep style-src-attr 'unsafe-inline': React's
|
|
1709
|
+
style={{...}} is an attribute, which no hash or nonce can allow.
|
|
1710
|
+
|
|
1711
|
+
Everywhere: Node, Bun, Docker, Workers, functions. A static export carries a
|
|
1712
|
+
<meta http-equiv="Content-Security-Policy"> per page (no frame-ancestors,
|
|
1713
|
+
report-uri, report-to, sandbox or report-only in a meta). An edge gets each
|
|
1714
|
+
static page's policy with its hashes. Under a policy edge.json moves the shells
|
|
1715
|
+
to nonceShells: an edge serves them only if it mints a nonce per response
|
|
1716
|
+
(Edge-Accept: nonce, the {edge-nonce} placeholder in the page's policy,
|
|
1717
|
+
Edge-Nonce on the resume); any other edge leaves them to the origin.
|
|
1718
|
+
|
|
1719
|
+
In vite dev the same policy is sent, plus 'unsafe-eval' (React's development
|
|
1720
|
+
build) and the dev server's origin when the page comes from another one. Every
|
|
1721
|
+
dev page renders per request, so it runs by nonce - Vite's CSS updates and
|
|
1722
|
+
error overlay included - and your own inline <script>/<style> is refused there
|
|
1723
|
+
even on a page the build stores. A refusal shows in dev first, never only in
|
|
1724
|
+
production. Never 'unsafe-eval' in a build.
|
|
1725
|
+
|
|
1726
|
+
Do NOT also put a Content-Security-Policy in rscKit({ headers }) - the build
|
|
1727
|
+
refuses both. Do NOT set a nonce policy in a middleware or in the backend in
|
|
1728
|
+
front (a Laravel CSP package): React never sees that nonce, so every streamed
|
|
1729
|
+
page is refused, and two policies are both enforced. A middleware that does set
|
|
1730
|
+
one keeps it, and the engine adds nothing.
|
|
1731
|
+
|
|
1732
|
+
Full guide: read_guide({ slug: 'content-security-policy' }).`,
|
|
1675
1733
|
},
|
|
1676
1734
|
{
|
|
1677
1735
|
topic: 'backend',
|
|
@@ -1738,6 +1796,14 @@ BAP vs Inertia for a Laravel team: read_guide bap-vs-inertia.
|
|
|
1738
1796
|
A backend in another language answers that ONE endpoint, POST /__rsc/host-call,
|
|
1739
1797
|
and the renderer wires itself from two variables in .env: RSC_BACKEND (a
|
|
1740
1798
|
Laravel app's APP_URL counts) and RSC_HOST_CALL_SECRET. Both or neither.
|
|
1799
|
+
A refused connection is tried again for up to 2s (nothing was sent, so nothing
|
|
1800
|
+
runs twice): a backend started beside the renderer may come up second. Nothing
|
|
1801
|
+
else is retried.
|
|
1802
|
+
RSC_BACKEND_HEADERS={"X-Preview-Token":"..."} (JSON object) puts fixed headers
|
|
1803
|
+
on every request to RSC_BACKEND, host calls and forwarded urls alike, never to
|
|
1804
|
+
another origin; read once at startup; malformed stops the server, naming the
|
|
1805
|
+
variable but not the value. For a platform that admits the renderer by a
|
|
1806
|
+
header (a private preview).
|
|
1741
1807
|
|
|
1742
1808
|
A url the route tree does not own goes to the backend (/login, a webhook, an
|
|
1743
1809
|
OAuth callback). One that it DOES match does not: a dynamic root route such as
|
|
@@ -2192,7 +2258,10 @@ PRODUCTION - in the platform's environment settings, never in git:
|
|
|
2192
2258
|
- read at runtime, so one build deploys anywhere (except the action key).
|
|
2193
2259
|
|
|
2194
2260
|
ROTATING is a deploy:
|
|
2195
|
-
- host-call:
|
|
2261
|
+
- host-call: the backend first. Give it the new value and the old one as
|
|
2262
|
+
RSC_HOST_CALL_SECRET_PREVIOUS (it answers either), then the renderer the new
|
|
2263
|
+
value, then remove RSC_HOST_CALL_SECRET_PREVIOUS. No call is refused. Before
|
|
2264
|
+
core 0.30.54 / go v0.17.0 / laravel 0.21, change both together.
|
|
2196
2265
|
- signing: open pages stop refreshing until reloaded; nothing else breaks.
|
|
2197
2266
|
- action key: actions from pages loaded before the change fail.
|
|
2198
2267
|
|