Skip to content

fix(rsc): add basename support #13926

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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api/rsc/matchRSCServerRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Matches the given routes to a Request and returns a RSC Response encoding an `RS

## Options

### basename

The basename to use when matching the request.

### decodeAction

Your `react-server-dom-xyz/server`'s `decodeAction` function, responsible for loading a server action.
Expand Down
2 changes: 2 additions & 0 deletions integration/helpers/rsc-parcel/src/config/basename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// THIS FILE IS DESIGNED TO BE OVERRIDDEN IN TESTS IF NEEDED
export const basename = undefined;
4 changes: 3 additions & 1 deletion integration/helpers/rsc-parcel/src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
// Import the prerender function from the client environment
import { prerender } from "./prerender" with { env: "react-client" };
import { routes } from "./routes";
import { assets } from "./parcel-entry-wrapper"
import { assets } from "./parcel-entry-wrapper";
import { basename } from "./config/basename";

function fetchServer(request: Request) {
return matchRSCServerRequest({
Expand All @@ -28,6 +29,7 @@ function fetchServer(request: Request) {
request,
// The app routes.
routes,
basename,
// Encode the match with the React Server implementation.
generateResponse(match, options) {
return new Response(renderToReadableStream(match.payload, options), {
Expand Down
2 changes: 2 additions & 0 deletions integration/helpers/rsc-vite/src/config/basename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// THIS FILE IS DESIGNED TO BE OVERRIDDEN IN TESTS IF NEEDED
export const basename = undefined;
2 changes: 2 additions & 0 deletions integration/helpers/rsc-vite/src/entry.rsc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
renderToReadableStream,
} from "@hiogawa/vite-rsc/rsc";
import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
import { basename } from "./config/basename";

import { routes } from "./routes";

Expand All @@ -17,6 +18,7 @@ export async function fetchServer(request: Request) {
loadServerAction,
request,
routes,
basename,
generateResponse(match, options) {
return new Response(renderToReadableStream(match.payload, options), {
status: match.statusCode,
Expand Down
Loading