-
Notifications
You must be signed in to change notification settings - Fork 12
test: reach parity with upstream React Router corpus coverage #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| 'rsbuild-plugin-react-router': patch | ||
| --- | ||
|
|
||
| Honor a user-provided `app/entry.ssr.tsx` in RSC framework mode. The RSC entry | ||
| template imported its own SSR template directly, so an override was placed in | ||
| the SSR layer while the template kept being compiled as React Server code and | ||
| failed the build on `react-dom/server`. The template now imports the resolved | ||
| SSR entry through `virtual/react-router/unstable_rsc/entry-ssr`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -465,6 +465,29 @@ and every configured bundle are | |
| evaluated and published as one generation; one failing bundle keeps the whole | ||
| previous generation active. | ||
|
|
||
| ### Sharing `createContext()` instances with a custom server | ||
|
|
||
| React Router middleware contexts are matched by identity, so a custom server's | ||
| `getLoadContext` must use the same `createContext()` instance the routes import. | ||
| With a bundled server build that instance lives inside the build. Re-export it | ||
| from `app/entry.server.tsx` and read it from `build.entry.module`: | ||
|
|
||
| ```ts | ||
| // app/entry.server.tsx | ||
| export { valueContext } from './context'; | ||
| ``` | ||
|
|
||
| ```js | ||
| // server.js | ||
| getLoadContext: async () => { | ||
| const { valueContext } = (await build()).entry.module; | ||
| return new RouterContextProvider([[valueContext, 'value']]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When users add this fragment to the custom-server example immediately above, handling a request fails with Useful? React with 👍 / 👎. |
||
| }, | ||
| ``` | ||
|
|
||
| This works in development through `loadReactRouterServerBuild` and in | ||
| production through `resolveReactRouterServerBuild`. | ||
|
|
||
| `resolveReactRouterServerBuild` accepts an imported production server module, | ||
| normalizes ESM and CommonJS namespace shapes, resolves supported asynchronous | ||
| build exports, and validates the result before it reaches React Router. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { test, expect } from "@playwright/test"; | ||
| import dedent from "dedent"; | ||
|
|
||
| import { createProject, build, reactRouterConfig } from "./helpers/rsbuild.js"; | ||
|
|
||
| // Adapted from upstream `vite-plugin-order-validation-test.ts`. The Vite cases | ||
| // about `@vitejs/plugin-rsc` ordering have no Rsbuild equivalent; the MDX rule | ||
| // is the one this plugin enforces. | ||
| test.describe("Rsbuild plugin order validation", () => { | ||
| test("Framework Mode with MDX plugin after React Router plugin", async () => { | ||
| let cwd = await createProject({ | ||
| "rsbuild.config.ts": dedent` | ||
| import { defineConfig } from "@rsbuild/core"; | ||
| import { pluginMdx } from "@rsbuild/plugin-mdx"; | ||
| import { pluginReact } from "@rsbuild/plugin-react"; | ||
| import { pluginReactRouter } from "rsbuild-plugin-react-router"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [pluginReact(), pluginReactRouter(), pluginMdx()], | ||
| }); | ||
| `, | ||
| }); | ||
|
|
||
| let buildResult = build({ cwd }); | ||
| expect(buildResult.stderr.toString()).toContain( | ||
| 'The "rsbuild:mdx" plugin should be placed before the React Router plugin', | ||
| ); | ||
| expect(buildResult.status).not.toBe(0); | ||
| }); | ||
|
|
||
| test("RSC Framework Mode with MDX plugin after React Router plugin", async () => { | ||
| let cwd = await createProject( | ||
| { | ||
| "rsbuild.config.ts": dedent` | ||
| import { defineConfig } from "@rsbuild/core"; | ||
| import { pluginMdx } from "@rsbuild/plugin-mdx"; | ||
| import { pluginReact } from "@rsbuild/plugin-react"; | ||
| import { pluginReactRouterRSC } from "rsbuild-plugin-react-router"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [pluginReact(), pluginReactRouterRSC(), pluginMdx()], | ||
| }); | ||
| `, | ||
| "react-router.config.ts": reactRouterConfig(), | ||
| }, | ||
| "rsc-framework", | ||
| ); | ||
|
|
||
| let buildResult = build({ cwd }); | ||
| expect(buildResult.stderr.toString()).toContain( | ||
| 'The "rsbuild:mdx" plugin should be placed before the React Router plugin', | ||
| ); | ||
| expect(buildResult.status).not.toBe(0); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildcallable in productionWhen this
getLoadContextis added to the complete custom-server example above and the documented production start command is used,buildis the resolvedServerBuildobject assigned on lines 426–428, not a function, so the first request throwsTypeError: build is not a function. Keep the production value behind the same callable interface used in development, as the new integration fixture does, or branch here before accessingentry.module.Useful? React with 👍 / 👎.