rsbuild-plugin-react-router 0.6.4 → 0.6.6
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/README.md +23 -0
- package/dist/index.cjs +11 -4
- package/dist/index.js +25 -18
- package/dist/mode-plan.d.ts +1 -0
- package/dist/rsc-virtual-modules.d.ts +3 -1
- package/dist/templates/entry.rsc.js +2 -2
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/manifest.ts +2 -1
- package/src/mode-plan.ts +5 -1
- package/src/rsc-runtime.d.ts +11 -0
- package/src/rsc-virtual-modules.ts +11 -1
- package/src/templates/entry.rsc.tsx +1 -1
package/README.md
CHANGED
|
@@ -465,6 +465,29 @@ and every configured bundle are
|
|
|
465
465
|
evaluated and published as one generation; one failing bundle keeps the whole
|
|
466
466
|
previous generation active.
|
|
467
467
|
|
|
468
|
+
### Sharing `createContext()` instances with a custom server
|
|
469
|
+
|
|
470
|
+
React Router middleware contexts are matched by identity, so a custom server's
|
|
471
|
+
`getLoadContext` must use the same `createContext()` instance the routes import.
|
|
472
|
+
With a bundled server build that instance lives inside the build. Re-export it
|
|
473
|
+
from `app/entry.server.tsx` and read it from `build.entry.module`:
|
|
474
|
+
|
|
475
|
+
```ts
|
|
476
|
+
// app/entry.server.tsx
|
|
477
|
+
export { valueContext } from './context';
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
```js
|
|
481
|
+
// server.js
|
|
482
|
+
getLoadContext: async () => {
|
|
483
|
+
const { valueContext } = (await build()).entry.module;
|
|
484
|
+
return new RouterContextProvider([[valueContext, 'value']]);
|
|
485
|
+
},
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
This works in development through `loadReactRouterServerBuild` and in
|
|
489
|
+
production through `resolveReactRouterServerBuild`.
|
|
490
|
+
|
|
468
491
|
`resolveReactRouterServerBuild` accepts an imported production server module,
|
|
469
492
|
normalizes ESM and CommonJS namespace shapes, resolves supported asynchronous
|
|
470
493
|
build exports, and validates the result before it reaches React Router.
|
package/dist/index.cjs
CHANGED
|
@@ -11962,7 +11962,7 @@ function generateReactRouterManifestForDevEffect(routes, clientStats, context, a
|
|
|
11962
11962
|
css: entryCssAssets.map((asset)=>combineURLs(assetPrefix, asset))
|
|
11963
11963
|
},
|
|
11964
11964
|
routes: result
|
|
11965
|
-
}, version = (0, external_node_crypto_namespaceObject.createHash)('
|
|
11965
|
+
}, version = (0, external_node_crypto_namespaceObject.createHash)('sha256').update(JSON.stringify(fingerprintedValues)).digest('hex').slice(0, 8), manifestPath = getReactRouterManifestPath({
|
|
11966
11966
|
version,
|
|
11967
11967
|
isBuild,
|
|
11968
11968
|
entryModulePath: entryJsAssets[0]
|
|
@@ -14691,7 +14691,11 @@ export {
|
|
|
14691
14691
|
'react-router-serve-config',
|
|
14692
14692
|
"bootstrap-scripts",
|
|
14693
14693
|
'server-manifest'
|
|
14694
|
-
], createReactRouterRscResolveAliases = (rootPath)=>({
|
|
14694
|
+
], createReactRouterRscResolveAliases = (rootPath, options = {})=>({
|
|
14695
|
+
...options.entrySsrPath ? {
|
|
14696
|
+
'virtual:react-router/unstable_rsc/entry-ssr': options.entrySsrPath,
|
|
14697
|
+
'virtual/react-router/unstable_rsc/entry-ssr': options.entrySsrPath
|
|
14698
|
+
} : {},
|
|
14695
14699
|
...Object.fromEntries(RSC_VIRTUAL_ALIAS_IDS.flatMap((id)=>{
|
|
14696
14700
|
let moduleId = `virtual/react-router/unstable_rsc/${id}`, modulePath = (0, external_pathe_namespaceObject.resolve)(rootPath, getVirtualModuleFilePath(moduleId));
|
|
14697
14701
|
return [
|
|
@@ -15559,7 +15563,7 @@ export {
|
|
|
15559
15563
|
'react-router/dom$': reactRouterDomPath
|
|
15560
15564
|
} : {}
|
|
15561
15565
|
};
|
|
15562
|
-
}, createRscModePlan = async ({ allowedActionOriginsForBuild, api, appDirectory, basename, buildDirectory, customServer, finalEntryRscClientPath, finalEntryRscPath, isBuild, outputClientPath, pluginName, prerenderConfig, routeConfig, routeDiscovery, routes, rootRouteFile, serverBuildFile, splitRouteModules, ssr })=>{
|
|
15566
|
+
}, createRscModePlan = async ({ allowedActionOriginsForBuild, api, appDirectory, basename, buildDirectory, customServer, finalEntryRscClientPath, finalEntryRscPath, finalEntryRscSsrPath, isBuild, outputClientPath, pluginName, prerenderConfig, routeConfig, routeDiscovery, routes, rootRouteFile, serverBuildFile, splitRouteModules, ssr })=>{
|
|
15563
15567
|
let rscServerEntryName = (serverBuildFile || 'index.js').replace(/\.js$/, '');
|
|
15564
15568
|
return {
|
|
15565
15569
|
kind: 'rsc',
|
|
@@ -15605,7 +15609,9 @@ export {
|
|
|
15605
15609
|
(0, external_pathe_namespaceObject.resolve)(rootPath, 'node_modules'),
|
|
15606
15610
|
'node_modules'
|
|
15607
15611
|
],
|
|
15608
|
-
alias: createReactRouterRscResolveAliases(rootPath
|
|
15612
|
+
alias: createReactRouterRscResolveAliases(rootPath, {
|
|
15613
|
+
entrySsrPath: finalEntryRscSsrPath
|
|
15614
|
+
})
|
|
15609
15615
|
}),
|
|
15610
15616
|
server: customServer ? void 0 : {
|
|
15611
15617
|
setup: createReactRouterRscDevServerSetup({
|
|
@@ -15964,6 +15970,7 @@ export {
|
|
|
15964
15970
|
buildDirectory,
|
|
15965
15971
|
finalEntryRscClientPath,
|
|
15966
15972
|
finalEntryRscPath,
|
|
15973
|
+
finalEntryRscSsrPath,
|
|
15967
15974
|
outputClientPath,
|
|
15968
15975
|
pluginName: PLUGIN_NAME,
|
|
15969
15976
|
serverBuildFile
|
package/dist/index.js
CHANGED
|
@@ -7517,7 +7517,7 @@ async function generateReactRouterManifestForDev(routes, _options, clientStats,
|
|
|
7517
7517
|
css: entryCssAssets.map((asset)=>combineURLs(assetPrefix, asset))
|
|
7518
7518
|
},
|
|
7519
7519
|
routes: result
|
|
7520
|
-
}, version = createHash('
|
|
7520
|
+
}, version = createHash('sha256').update(JSON.stringify(fingerprintedValues)).digest('hex').slice(0, 8), manifestPath = getReactRouterManifestPath({
|
|
7521
7521
|
version,
|
|
7522
7522
|
isBuild,
|
|
7523
7523
|
entryModulePath: entryJsAssets[0]
|
|
@@ -9500,7 +9500,7 @@ export function EnsureClientRouteModuleForHMR___() { return ___EnsureClientRoute
|
|
|
9500
9500
|
routesByServerBundleId,
|
|
9501
9501
|
serverBundleEntries: serverBuildPlan.serverBundleEntries
|
|
9502
9502
|
};
|
|
9503
|
-
}, RSC_LAYERS = rspack.experiments.rsc.Layers, createRscModePlan = async ({ allowedActionOriginsForBuild, api, appDirectory, basename, buildDirectory, customServer, finalEntryRscClientPath, finalEntryRscPath, isBuild, outputClientPath, pluginName, prerenderConfig, routeConfig, routeDiscovery, routes, rootRouteFile, serverBuildFile, splitRouteModules, ssr })=>{
|
|
9503
|
+
}, RSC_LAYERS = rspack.experiments.rsc.Layers, createRscModePlan = async ({ allowedActionOriginsForBuild, api, appDirectory, basename, buildDirectory, customServer, finalEntryRscClientPath, finalEntryRscPath, finalEntryRscSsrPath, isBuild, outputClientPath, pluginName, prerenderConfig, routeConfig, routeDiscovery, routes, rootRouteFile, serverBuildFile, splitRouteModules, ssr })=>{
|
|
9504
9504
|
let rscServerEntryName = (serverBuildFile || 'index.js').replace(/\.js$/, '');
|
|
9505
9505
|
return {
|
|
9506
9506
|
kind: 'rsc',
|
|
@@ -9679,22 +9679,28 @@ export {
|
|
|
9679
9679
|
external_pathe_resolve(rootPath, 'node_modules'),
|
|
9680
9680
|
'node_modules'
|
|
9681
9681
|
],
|
|
9682
|
-
alias: {
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9682
|
+
alias: ((rootPath, options = {})=>({
|
|
9683
|
+
...options.entrySsrPath ? {
|
|
9684
|
+
'virtual:react-router/unstable_rsc/entry-ssr': options.entrySsrPath,
|
|
9685
|
+
'virtual/react-router/unstable_rsc/entry-ssr': options.entrySsrPath
|
|
9686
|
+
} : {},
|
|
9687
|
+
...Object.fromEntries(RSC_VIRTUAL_ALIAS_IDS.flatMap((id)=>{
|
|
9688
|
+
let moduleId = `virtual/react-router/unstable_rsc/${id}`, modulePath = external_pathe_resolve(rootPath, getVirtualModuleFilePath(moduleId));
|
|
9689
|
+
return [
|
|
9690
|
+
[
|
|
9691
|
+
`virtual:react-router/unstable_rsc/${id}`,
|
|
9692
|
+
modulePath
|
|
9693
|
+
],
|
|
9694
|
+
[
|
|
9695
|
+
moduleId,
|
|
9696
|
+
modulePath
|
|
9697
|
+
]
|
|
9698
|
+
];
|
|
9699
|
+
})),
|
|
9700
|
+
'react-router/internal/react-server-client': external_pathe_resolve(rootPath, getVirtualModuleFilePath('virtual/react-router/rsc-internal-client'))
|
|
9701
|
+
}))(rootPath, {
|
|
9702
|
+
entrySsrPath: finalEntryRscSsrPath
|
|
9703
|
+
})
|
|
9698
9704
|
}),
|
|
9699
9705
|
server: customServer ? void 0 : {
|
|
9700
9706
|
setup: function({ entryName, pluginName }) {
|
|
@@ -10501,6 +10507,7 @@ export {
|
|
|
10501
10507
|
buildDirectory,
|
|
10502
10508
|
finalEntryRscClientPath,
|
|
10503
10509
|
finalEntryRscPath,
|
|
10510
|
+
finalEntryRscSsrPath,
|
|
10504
10511
|
outputClientPath,
|
|
10505
10512
|
pluginName: PLUGIN_NAME,
|
|
10506
10513
|
serverBuildFile
|
package/dist/mode-plan.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ type CreateRscModePlanOptions = ModePlanContext & {
|
|
|
69
69
|
buildDirectory: string;
|
|
70
70
|
finalEntryRscClientPath: string;
|
|
71
71
|
finalEntryRscPath: string;
|
|
72
|
+
finalEntryRscSsrPath: string;
|
|
72
73
|
outputClientPath: string;
|
|
73
74
|
pluginName: string;
|
|
74
75
|
serverBuildFile: string | undefined;
|
|
@@ -14,6 +14,8 @@ type RscVirtualModulesOptions = {
|
|
|
14
14
|
routes: Record<string, Route>;
|
|
15
15
|
ssr: boolean;
|
|
16
16
|
};
|
|
17
|
-
export declare const createReactRouterRscResolveAliases: (rootPath: string
|
|
17
|
+
export declare const createReactRouterRscResolveAliases: (rootPath: string, options?: {
|
|
18
|
+
entrySsrPath?: string;
|
|
19
|
+
}) => Record<string, string>;
|
|
18
20
|
export declare const createReactRouterRscVirtualModules: ({ allowedActionOrigins, appDirectory, basename, buildDirectory, isBuild, jsDistPath, outputClientPath, publicPath, routeDiscovery, routes, ssr, }: RscVirtualModulesOptions) => Record<string, string>;
|
|
19
21
|
export {};
|
|
@@ -5,9 +5,9 @@ import route_discovery from "virtual/react-router/unstable_rsc/route-discovery";
|
|
|
5
5
|
import basename from "virtual/react-router/unstable_rsc/basename";
|
|
6
6
|
import allowed_action_origins from "virtual/react-router/unstable_rsc/allowed-action-origins";
|
|
7
7
|
import client_version from "virtual/react-router/unstable_rsc/client-version";
|
|
8
|
-
import
|
|
8
|
+
import { generateHTML } from "virtual/react-router/unstable_rsc/entry-ssr";
|
|
9
9
|
import bootstrap_scripts from "virtual/react-router/unstable_rsc/bootstrap-scripts";
|
|
10
|
-
import
|
|
10
|
+
import server_manifest from "virtual/react-router/unstable_rsc/server-manifest";
|
|
11
11
|
function fetchServer(request, requestContext) {
|
|
12
12
|
return unstable_matchRSCServerRequest({
|
|
13
13
|
allowedActionOrigins: allowed_action_origins,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/manifest.ts
CHANGED
|
@@ -609,7 +609,8 @@ function generateReactRouterManifestForDevEffect(
|
|
|
609
609
|
// compares the browser's manifest version with the pinned server build's,
|
|
610
610
|
// and a random per-compilation version made unchanged manifests differ
|
|
611
611
|
// whenever a web compilation completed without a new server pin.
|
|
612
|
-
|
|
612
|
+
// sha256 rather than md5: md5 is unavailable on FIPS-enabled hosts (#124).
|
|
613
|
+
const version = createHash('sha256')
|
|
613
614
|
.update(JSON.stringify(fingerprintedValues))
|
|
614
615
|
.digest('hex')
|
|
615
616
|
.slice(0, 8);
|
package/src/mode-plan.ts
CHANGED
|
@@ -104,6 +104,7 @@ type CreateRscModePlanOptions = ModePlanContext & {
|
|
|
104
104
|
buildDirectory: string;
|
|
105
105
|
finalEntryRscClientPath: string;
|
|
106
106
|
finalEntryRscPath: string;
|
|
107
|
+
finalEntryRscSsrPath: string;
|
|
107
108
|
outputClientPath: string;
|
|
108
109
|
pluginName: string;
|
|
109
110
|
serverBuildFile: string | undefined;
|
|
@@ -133,6 +134,7 @@ const createRscModePlan = async ({
|
|
|
133
134
|
customServer,
|
|
134
135
|
finalEntryRscClientPath,
|
|
135
136
|
finalEntryRscPath,
|
|
137
|
+
finalEntryRscSsrPath,
|
|
136
138
|
isBuild,
|
|
137
139
|
outputClientPath,
|
|
138
140
|
pluginName,
|
|
@@ -197,7 +199,9 @@ const createRscModePlan = async ({
|
|
|
197
199
|
}),
|
|
198
200
|
createResolveConfig: (rootPath: string) => ({
|
|
199
201
|
modules: [resolve(rootPath, 'node_modules'), 'node_modules'],
|
|
200
|
-
alias: createReactRouterRscResolveAliases(rootPath
|
|
202
|
+
alias: createReactRouterRscResolveAliases(rootPath, {
|
|
203
|
+
entrySsrPath: finalEntryRscSsrPath,
|
|
204
|
+
}),
|
|
201
205
|
}),
|
|
202
206
|
server: !customServer
|
|
203
207
|
? {
|
package/src/rsc-runtime.d.ts
CHANGED
|
@@ -99,6 +99,17 @@ declare module 'virtual/react-router/unstable_rsc/react-router-serve-config' {
|
|
|
99
99
|
|
|
100
100
|
declare module 'virtual/react-router/unstable_rsc/inject-hmr-runtime' {}
|
|
101
101
|
|
|
102
|
+
declare module 'virtual/react-router/unstable_rsc/entry-ssr' {
|
|
103
|
+
export function generateHTML(
|
|
104
|
+
request: Request,
|
|
105
|
+
serverResponse: Response,
|
|
106
|
+
options?: {
|
|
107
|
+
bootstrapScripts?: string[];
|
|
108
|
+
bootstrapModules?: string[];
|
|
109
|
+
}
|
|
110
|
+
): Promise<Response>;
|
|
111
|
+
}
|
|
112
|
+
|
|
102
113
|
declare module 'virtual/react-router/unstable_rsc/bootstrap-scripts' {
|
|
103
114
|
const bootstrapScripts: string[];
|
|
104
115
|
export default bootstrapScripts;
|
|
@@ -39,8 +39,18 @@ type RscVirtualModulesOptions = {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export const createReactRouterRscResolveAliases = (
|
|
42
|
-
rootPath: string
|
|
42
|
+
rootPath: string,
|
|
43
|
+
options: { entrySsrPath?: string } = {}
|
|
43
44
|
): Record<string, string> => ({
|
|
45
|
+
// The RSC entry template imports the SSR entry through this alias so a
|
|
46
|
+
// user-provided `app/entry.ssr.tsx` replaces the template inside the SSR
|
|
47
|
+
// layer instead of leaving the template to be compiled as server code.
|
|
48
|
+
...(options.entrySsrPath
|
|
49
|
+
? {
|
|
50
|
+
'virtual:react-router/unstable_rsc/entry-ssr': options.entrySsrPath,
|
|
51
|
+
'virtual/react-router/unstable_rsc/entry-ssr': options.entrySsrPath,
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
44
54
|
...Object.fromEntries(
|
|
45
55
|
RSC_VIRTUAL_ALIAS_IDS.flatMap(id => {
|
|
46
56
|
const moduleId = `virtual/react-router/unstable_rsc/${id}`;
|
|
@@ -19,7 +19,7 @@ import clientVersion from 'virtual/react-router/unstable_rsc/client-version';
|
|
|
19
19
|
import unstable_reactRouterServeConfig from 'virtual/react-router/unstable_rsc/react-router-serve-config';
|
|
20
20
|
import bootstrapScripts from 'virtual/react-router/unstable_rsc/bootstrap-scripts';
|
|
21
21
|
import getServerManifest from 'virtual/react-router/unstable_rsc/server-manifest';
|
|
22
|
-
import { generateHTML } from '
|
|
22
|
+
import { generateHTML } from 'virtual/react-router/unstable_rsc/entry-ssr';
|
|
23
23
|
|
|
24
24
|
export { unstable_reactRouterServeConfig };
|
|
25
25
|
|