@rsc-kit/mcp 0.47.0 → 0.48.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 +55 -41
- package/dist/recipes.js.map +1 -1
- package/guides/coming-from-next.md +1 -1
- package/guides/feature-flags.md +173 -87
- package/guides/index.json +1 -1
- package/guides/testing.md +2 -9
- package/guides/validation.md +32 -0
- package/package.json +2 -2
package/dist/recipes.js
CHANGED
|
@@ -91,6 +91,13 @@ Passing \`schema\` validates in the browser BEFORE the action is called, so a
|
|
|
91
91
|
mistake costs no round trip. It is a courtesy, never a control: the action is a
|
|
92
92
|
public endpoint reachable without your form, so the server must check too.
|
|
93
93
|
|
|
94
|
+
A BACKEND ACTION WITH A SCHEMA needs no \`schema\` prop: when rsc-host.json has
|
|
95
|
+
"schemas": { "Signup.store": { schema, messages } }, <Form action={store}> checks
|
|
96
|
+
it in the browser with the backend's own messages, on blur and submit (Laravel:
|
|
97
|
+
a FormRequest's schema()). Loaded lazily by the action's id - nothing in the
|
|
98
|
+
page, works for a client-imported or a server-passed action - and a blank
|
|
99
|
+
optional field is not posted, since the backend's rules read "" as a value.
|
|
100
|
+
|
|
94
101
|
A schema on the server (\`client.input(schema)\`) does NOT give you client-side
|
|
95
102
|
validation. Pass it to the form as well — the same schema is fine.
|
|
96
103
|
|
|
@@ -1409,10 +1416,8 @@ IMPORTS
|
|
|
1409
1416
|
export const viewport as-is; charset + viewport tags are written for you)
|
|
1410
1417
|
app/robots.ts, app/sitemap.ts -> the same files and shapes; app/llms.ts beside them (how_to seo-files)
|
|
1411
1418
|
middleware.ts subdomain rewrite -> nothing: a host is a route segment (how_to domains)
|
|
1412
|
-
flags/next (Vercel Flags SDK) ->
|
|
1413
|
-
(
|
|
1414
|
-
not built: tests/preload.ts needs
|
|
1415
|
-
mock.module('next/headers', () => import('@rsc-kit/core/request'))
|
|
1419
|
+
flags/next (Vercel Flags SDK) -> OpenFeature (how_to feature-flags): @openfeature/server-sdk, context
|
|
1420
|
+
from cookies(); Pennant on Laravel. Nothing aliases next/headers any more
|
|
1416
1421
|
next/font -> Fontsource (how_to fonts)
|
|
1417
1422
|
next/image -> unpic or vite-imagetools (how_to images)
|
|
1418
1423
|
next/script -> a <script> tag (how_to scripts)
|
|
@@ -1544,40 +1549,6 @@ again -> browser. Drop @inertiajs/react, laravel-vite-plugin and ziggy from
|
|
|
1544
1549
|
package.json when the last import is gone.
|
|
1545
1550
|
|
|
1546
1551
|
Full guide: read_guide({ slug: 'coming-from-inertia' }).`,
|
|
1547
|
-
},
|
|
1548
|
-
{
|
|
1549
|
-
topic: 'feature-flags',
|
|
1550
|
-
summary: "Vercel's Flags SDK (flags/next) runs unchanged: next/headers is answered by headers()/cookies() here",
|
|
1551
|
-
body: `bun add flags. Then flags/next as written for Next:
|
|
1552
|
-
|
|
1553
|
-
import { flag, dedupe } from 'flags/next'
|
|
1554
|
-
const visitor = dedupe(async ({ cookies, headers }) => ({ id: cookies.get('visitor')?.value ?? 'anon' }))
|
|
1555
|
-
export const showBanner = flag<boolean, { id: string }>({ key: 'show-banner', identify: visitor, decide: ({ entities }) => entities?.id === 'ada' })
|
|
1556
|
-
|
|
1557
|
-
// page.tsx (server component)
|
|
1558
|
-
const on = await showBanner()
|
|
1559
|
-
|
|
1560
|
-
The build aliases next/headers to @rsc-kit/core/request - same names, same
|
|
1561
|
-
shapes (cookies().get(name)?.value), one object per request, which the SDK's
|
|
1562
|
-
dedupe keys on. Nothing to configure in the app, no shim to write.
|
|
1563
|
-
|
|
1564
|
-
bun test is not built, so the alias is not there: flags/next finds Next's own
|
|
1565
|
-
next/headers (a monorepo often has one) and throws "headers was called
|
|
1566
|
-
outside a request scope". One line in tests/preload.ts (the scaffold ships it):
|
|
1567
|
-
|
|
1568
|
-
mock.module('next/headers', () => import('@rsc-kit/core/request'))
|
|
1569
|
-
|
|
1570
|
-
Then a flag evaluates inside withRequest(), as in the app.
|
|
1571
|
-
|
|
1572
|
-
A flag reads the request, so the page renders per visitor: put a <Suspense>
|
|
1573
|
-
or loading.tsx above the read and the build stores the rest as a shell (the
|
|
1574
|
-
table says "headers() in run, cookies() in run stream per request").
|
|
1575
|
-
|
|
1576
|
-
Discovery endpoint: a route.ts -
|
|
1577
|
-
export const GET = createFlagsDiscoveryEndpoint(async () => getProviderData(flags))
|
|
1578
|
-
export const openapi = false
|
|
1579
|
-
precompute() does NOT carry over (it rewrites urls in Next middleware); read
|
|
1580
|
-
the flag in the page.`,
|
|
1581
1552
|
},
|
|
1582
1553
|
{
|
|
1583
1554
|
topic: 'emails',
|
|
@@ -2923,6 +2894,52 @@ across navigations.
|
|
|
2923
2894
|
There is no Script component to import. The only case needing one - a script
|
|
2924
2895
|
that touches DOM React rendered, or an onLoad callback - is a client component
|
|
2925
2896
|
with useEffect that creates the tag. Ten lines of the user's own.`,
|
|
2897
|
+
},
|
|
2898
|
+
{
|
|
2899
|
+
topic: 'feature-flags',
|
|
2900
|
+
summary: 'OpenFeature in a server component; Pennant on Laravel and the OpenFeature Go SDK on Go, read with rpc()',
|
|
2901
|
+
body: `JS app: bun add @openfeature/server-sdk @openfeature/core. One module, src/server/flags.ts:
|
|
2902
|
+
|
|
2903
|
+
import { cache } from 'react'
|
|
2904
|
+
import { OpenFeature, InMemoryProvider } from '@openfeature/server-sdk'
|
|
2905
|
+
import { cookies } from '@rsc-kit/core/request'
|
|
2906
|
+
|
|
2907
|
+
await OpenFeature.setProviderAndWait(new InMemoryProvider({
|
|
2908
|
+
'new-banner': { variants: { on: true, off: false }, defaultVariant: 'off', disabled: false,
|
|
2909
|
+
contextEvaluator: (c) => (c.targetingKey === 'ada' ? 'on' : 'off') },
|
|
2910
|
+
}))
|
|
2911
|
+
const client = OpenFeature.getClient()
|
|
2912
|
+
const visitor = cache(async () => ({ targetingKey: (await cookies()).get('user')?.value ?? 'anonymous' }))
|
|
2913
|
+
export const newBanner = cache(async () => client.getBooleanValue('new-banner', false, await visitor()))
|
|
2914
|
+
|
|
2915
|
+
React cache() evaluates once per render. The evaluation context is passed with
|
|
2916
|
+
every call - not set globally, not a transaction context. Swap InMemoryProvider
|
|
2917
|
+
for the flag service's provider (openfeature.dev/ecosystem); the calls stay.
|
|
2918
|
+
An evaluation never throws: a failure answers the default. setProviderAndWait
|
|
2919
|
+
rejects if the provider cannot start; setProvider does not wait.
|
|
2920
|
+
|
|
2921
|
+
A flag read from cookies() is per visitor: render it in its own async component
|
|
2922
|
+
under <Suspense> so the rest of the page is still stored. A flag with no
|
|
2923
|
+
context reads nothing and the page is stored whole.
|
|
2924
|
+
|
|
2925
|
+
Laravel: Pennant, as its docs show. Feature::define('new-banner', fn (User $user) => ...)
|
|
2926
|
+
in a provider, and a class under app/Rsc returns Feature::active('new-banner');
|
|
2927
|
+
the page reads rpc('Flags.newBanner'). Pennant's default scope is the signed-in
|
|
2928
|
+
user, so the build leaves the call to the request (Suspense as above);
|
|
2929
|
+
Feature::for(null) is answered at build and stored.
|
|
2930
|
+
|
|
2931
|
+
Go: github.com/open-feature/go-sdk in a handler -
|
|
2932
|
+
client.BooleanValue(ctx, "new-banner", false, openfeature.NewEvaluationContext(id, nil)).
|
|
2933
|
+
The SDK reads its own context value, which the build counts as a visitor read,
|
|
2934
|
+
so nothing is stored. An app that never sets OpenFeature's transaction context:
|
|
2935
|
+
reg.ServeCalls(os.Stdin, os.Stdout, rsckit.NotTheVisitor("github.com/open-feature/go-sdk/openfeature")).
|
|
2936
|
+
|
|
2937
|
+
Test: await withRequest(new Request(url, { headers: { Cookie: 'user=ada' } }), newBanner).
|
|
2938
|
+
|
|
2939
|
+
Not flags/next: it reads the request through Next, and 4.5.2 added a
|
|
2940
|
+
next/navigation import that broke every page reading a flag.
|
|
2941
|
+
|
|
2942
|
+
Full guide: read_guide({ slug: 'feature-flags' }).`,
|
|
2926
2943
|
},
|
|
2927
2944
|
{
|
|
2928
2945
|
topic: 'testing',
|
|
@@ -2952,9 +2969,6 @@ import { withRequest } from '@rsc-kit/core/request'
|
|
|
2952
2969
|
await withRequest(new Request('https://app.test/', { headers: { Cookie: 'session=abc' } }), currentUser)
|
|
2953
2970
|
\`\`\`
|
|
2954
2971
|
|
|
2955
|
-
A library written for Next that reads next/headers (flags/next) needs the
|
|
2956
|
-
build's alias in tests/preload.ts: mock.module('next/headers', () => import('@rsc-kit/core/request')).
|
|
2957
|
-
|
|
2958
2972
|
**The whole app as Request -> Response, no port:**
|
|
2959
2973
|
|
|
2960
2974
|
\`\`\`ts
|