@rsc-kit/mcp 0.46.1 → 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 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
 
@@ -98,10 +105,13 @@ A field is checked when it is LEFT, not as it is typed (the form listens for
98
105
  focusout, so uncontrolled fields are covered), and on submit. So error() has
99
106
  nothing for a field nobody reached - there is no "touched" to check first.
100
107
 
101
- CHECKED BY THE SERVER BEFORE SUBMIT: when a field is left having CHANGED, the
102
- form also asks the action - marked as a check, so its guards and validation run
103
- and its body does NOT. Automatic; nothing to opt into, and NO hook to add. It
104
- asks only an action that can stop before its body: createActionClient() with
108
+ CHECKED BY THE SERVER BEFORE SUBMIT: on <Form action={a} precognitive>, when a
109
+ field is left having CHANGED, the form also asks the action - marked as a check,
110
+ so its guards and validation run and its body does NOT. OFF without the prop:
111
+ the server then hears only the submit and validate() (a schema still checks on
112
+ blur - it is the browser's). A check passes the guards, so a throttle counts it;
113
+ let checks through in the limiter (Laravel: $request->isPrecognitive() ?
114
+ Limit::none() : Limit::perMinute(5)->by($request->ip())). It asks only an action that can stop before its body: createActionClient() with
105
115
  .input(schema), or a backend function listed in rsc-host.json "validates"
106
116
  (Laravel: one whose first parameter is a FormRequest - Precognition's rules,
107
117
  filtered to the field). A plain "use server" function is never called to check.
@@ -1406,10 +1416,8 @@ IMPORTS
1406
1416
  export const viewport as-is; charset + viewport tags are written for you)
1407
1417
  app/robots.ts, app/sitemap.ts -> the same files and shapes; app/llms.ts beside them (how_to seo-files)
1408
1418
  middleware.ts subdomain rewrite -> nothing: a host is a route segment (how_to domains)
1409
- flags/next (Vercel Flags SDK) -> unchanged: the build aliases next/headers to @rsc-kit/core/request
1410
- (how_to feature-flags); precompute() does not carry over. bun test is
1411
- not built: tests/preload.ts needs
1412
- 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
1413
1421
  next/font -> Fontsource (how_to fonts)
1414
1422
  next/image -> unpic or vite-imagetools (how_to images)
1415
1423
  next/script -> a <script> tag (how_to scripts)
@@ -1541,40 +1549,6 @@ again -> browser. Drop @inertiajs/react, laravel-vite-plugin and ziggy from
1541
1549
  package.json when the last import is gone.
1542
1550
 
1543
1551
  Full guide: read_guide({ slug: 'coming-from-inertia' }).`,
1544
- },
1545
- {
1546
- topic: 'feature-flags',
1547
- summary: "Vercel's Flags SDK (flags/next) runs unchanged: next/headers is answered by headers()/cookies() here",
1548
- body: `bun add flags. Then flags/next as written for Next:
1549
-
1550
- import { flag, dedupe } from 'flags/next'
1551
- const visitor = dedupe(async ({ cookies, headers }) => ({ id: cookies.get('visitor')?.value ?? 'anon' }))
1552
- export const showBanner = flag<boolean, { id: string }>({ key: 'show-banner', identify: visitor, decide: ({ entities }) => entities?.id === 'ada' })
1553
-
1554
- // page.tsx (server component)
1555
- const on = await showBanner()
1556
-
1557
- The build aliases next/headers to @rsc-kit/core/request - same names, same
1558
- shapes (cookies().get(name)?.value), one object per request, which the SDK's
1559
- dedupe keys on. Nothing to configure in the app, no shim to write.
1560
-
1561
- bun test is not built, so the alias is not there: flags/next finds Next's own
1562
- next/headers (a monorepo often has one) and throws "headers was called
1563
- outside a request scope". One line in tests/preload.ts (the scaffold ships it):
1564
-
1565
- mock.module('next/headers', () => import('@rsc-kit/core/request'))
1566
-
1567
- Then a flag evaluates inside withRequest(), as in the app.
1568
-
1569
- A flag reads the request, so the page renders per visitor: put a <Suspense>
1570
- or loading.tsx above the read and the build stores the rest as a shell (the
1571
- table says "headers() in run, cookies() in run stream per request").
1572
-
1573
- Discovery endpoint: a route.ts -
1574
- export const GET = createFlagsDiscoveryEndpoint(async () => getProviderData(flags))
1575
- export const openapi = false
1576
- precompute() does NOT carry over (it rewrites urls in Next middleware); read
1577
- the flag in the page.`,
1578
1552
  },
1579
1553
  {
1580
1554
  topic: 'emails',
@@ -2920,6 +2894,52 @@ across navigations.
2920
2894
  There is no Script component to import. The only case needing one - a script
2921
2895
  that touches DOM React rendered, or an onLoad callback - is a client component
2922
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' }).`,
2923
2943
  },
2924
2944
  {
2925
2945
  topic: 'testing',
@@ -2949,9 +2969,6 @@ import { withRequest } from '@rsc-kit/core/request'
2949
2969
  await withRequest(new Request('https://app.test/', { headers: { Cookie: 'session=abc' } }), currentUser)
2950
2970
  \`\`\`
2951
2971
 
2952
- A library written for Next that reads next/headers (flags/next) needs the
2953
- build's alias in tests/preload.ts: mock.module('next/headers', () => import('@rsc-kit/core/request')).
2954
-
2955
2972
  **The whole app as Request -> Response, no port:**
2956
2973
 
2957
2974
  \`\`\`ts