@rsc-kit/mcp 0.47.0 → 0.49.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,14 @@ 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(); Go: reg.CheckInBrowser(name), from the struct's
98
+ validate tags). Loaded lazily by the action's id - nothing in the
99
+ page, works for a client-imported or a server-passed action - and a blank
100
+ optional field is not posted, since the backend's rules read "" as a value.
101
+
94
102
  A schema on the server (\`client.input(schema)\`) does NOT give you client-side
95
103
  validation. Pass it to the form as well — the same schema is fine.
96
104
 
@@ -1409,10 +1417,8 @@ IMPORTS
1409
1417
  export const viewport as-is; charset + viewport tags are written for you)
1410
1418
  app/robots.ts, app/sitemap.ts -> the same files and shapes; app/llms.ts beside them (how_to seo-files)
1411
1419
  middleware.ts subdomain rewrite -> nothing: a host is a route segment (how_to domains)
1412
- flags/next (Vercel Flags SDK) -> unchanged: the build aliases next/headers to @rsc-kit/core/request
1413
- (how_to feature-flags); precompute() does not carry over. bun test is
1414
- not built: tests/preload.ts needs
1415
- mock.module('next/headers', () => import('@rsc-kit/core/request'))
1420
+ flags/next (Vercel Flags SDK) -> OpenFeature (how_to feature-flags): @openfeature/server-sdk, context
1421
+ from cookies(); Pennant on Laravel. Nothing aliases next/headers any more
1416
1422
  next/font -> Fontsource (how_to fonts)
1417
1423
  next/image -> unpic or vite-imagetools (how_to images)
1418
1424
  next/script -> a <script> tag (how_to scripts)
@@ -1544,40 +1550,6 @@ again -> browser. Drop @inertiajs/react, laravel-vite-plugin and ziggy from
1544
1550
  package.json when the last import is gone.
1545
1551
 
1546
1552
  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
1553
  },
1582
1554
  {
1583
1555
  topic: 'emails',
@@ -2923,6 +2895,52 @@ across navigations.
2923
2895
  There is no Script component to import. The only case needing one - a script
2924
2896
  that touches DOM React rendered, or an onLoad callback - is a client component
2925
2897
  with useEffect that creates the tag. Ten lines of the user's own.`,
2898
+ },
2899
+ {
2900
+ topic: 'feature-flags',
2901
+ summary: 'OpenFeature in a server component; Pennant on Laravel and the OpenFeature Go SDK on Go, read with rpc()',
2902
+ body: `JS app: bun add @openfeature/server-sdk @openfeature/core. One module, src/server/flags.ts:
2903
+
2904
+ import { cache } from 'react'
2905
+ import { OpenFeature, InMemoryProvider } from '@openfeature/server-sdk'
2906
+ import { cookies } from '@rsc-kit/core/request'
2907
+
2908
+ await OpenFeature.setProviderAndWait(new InMemoryProvider({
2909
+ 'new-banner': { variants: { on: true, off: false }, defaultVariant: 'off', disabled: false,
2910
+ contextEvaluator: (c) => (c.targetingKey === 'ada' ? 'on' : 'off') },
2911
+ }))
2912
+ const client = OpenFeature.getClient()
2913
+ const visitor = cache(async () => ({ targetingKey: (await cookies()).get('user')?.value ?? 'anonymous' }))
2914
+ export const newBanner = cache(async () => client.getBooleanValue('new-banner', false, await visitor()))
2915
+
2916
+ React cache() evaluates once per render. The evaluation context is passed with
2917
+ every call - not set globally, not a transaction context. Swap InMemoryProvider
2918
+ for the flag service's provider (openfeature.dev/ecosystem); the calls stay.
2919
+ An evaluation never throws: a failure answers the default. setProviderAndWait
2920
+ rejects if the provider cannot start; setProvider does not wait.
2921
+
2922
+ A flag read from cookies() is per visitor: render it in its own async component
2923
+ under <Suspense> so the rest of the page is still stored. A flag with no
2924
+ context reads nothing and the page is stored whole.
2925
+
2926
+ Laravel: Pennant, as its docs show. Feature::define('new-banner', fn (User $user) => ...)
2927
+ in a provider, and a class under app/Rsc returns Feature::active('new-banner');
2928
+ the page reads rpc('Flags.newBanner'). Pennant's default scope is the signed-in
2929
+ user, so the build leaves the call to the request (Suspense as above);
2930
+ Feature::for(null) is answered at build and stored.
2931
+
2932
+ Go: github.com/open-feature/go-sdk in a handler -
2933
+ client.BooleanValue(ctx, "new-banner", false, openfeature.NewEvaluationContext(id, nil)).
2934
+ The SDK reads its own context value, which the build counts as a visitor read,
2935
+ so nothing is stored. An app that never sets OpenFeature's transaction context:
2936
+ reg.ServeCalls(os.Stdin, os.Stdout, rsckit.NotTheVisitor("github.com/open-feature/go-sdk/openfeature")).
2937
+
2938
+ Test: await withRequest(new Request(url, { headers: { Cookie: 'user=ada' } }), newBanner).
2939
+
2940
+ Not flags/next: it reads the request through Next, and 4.5.2 added a
2941
+ next/navigation import that broke every page reading a flag.
2942
+
2943
+ Full guide: read_guide({ slug: 'feature-flags' }).`,
2926
2944
  },
2927
2945
  {
2928
2946
  topic: 'testing',
@@ -2952,9 +2970,6 @@ import { withRequest } from '@rsc-kit/core/request'
2952
2970
  await withRequest(new Request('https://app.test/', { headers: { Cookie: 'session=abc' } }), currentUser)
2953
2971
  \`\`\`
2954
2972
 
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
2973
  **The whole app as Request -> Response, no port:**
2959
2974
 
2960
2975
  \`\`\`ts