@cedarjs/vite 1.0.0-canary.12748 → 1.0.0-rc.26
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/bundled/react-server-dom-webpack.server.js +28517 -1379
- package/dist/cjs/devFeServer.js +15 -265
- package/dist/cjs/lib/registerFwGlobalsAndShims.js +0 -9
- package/dist/cjs/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/cjs/plugins/vite-plugin-rsc-transform-server.js +0 -4
- package/dist/cjs/rsc/rscRenderer.js +9 -23
- package/dist/cjs/rsc/rscRequestHandler.js +6 -6
- package/dist/cjs/runFeServer.js +22 -3
- package/dist/cjs/streaming/createReactStreamingHandler.js +10 -13
- package/dist/cjs/streaming/streamHelpers.js +30 -49
- package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
- package/dist/devFeServer.js +16 -265
- package/dist/lib/registerFwGlobalsAndShims.js +0 -9
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-ssr-router-import.js +2 -2
- package/dist/plugins/vite-plugin-rsc-transform-server.d.ts.map +1 -1
- package/dist/plugins/vite-plugin-rsc-transform-server.js +0 -4
- package/dist/rsc/rscRenderer.d.ts.map +1 -1
- package/dist/rsc/rscRenderer.js +5 -19
- package/dist/rsc/rscRequestHandler.d.ts +2 -2
- package/dist/rsc/rscRequestHandler.d.ts.map +1 -1
- package/dist/rsc/rscRequestHandler.js +4 -4
- package/dist/runFeServer.js +21 -2
- package/dist/streaming/createReactStreamingHandler.d.ts +1 -1
- package/dist/streaming/createReactStreamingHandler.d.ts.map +1 -1
- package/dist/streaming/createReactStreamingHandler.js +10 -13
- package/dist/streaming/streamHelpers.d.ts +2 -2
- package/dist/streaming/streamHelpers.d.ts.map +1 -1
- package/dist/streaming/streamHelpers.js +29 -49
- package/dist/streaming/triggerRouteHooks.d.ts +2 -2
- package/dist/streaming/triggerRouteHooks.d.ts.map +1 -1
- package/dist/streaming/triggerRouteHooks.js +3 -3
- package/package.json +12 -12
- package/dist/cjs/rsc/rscWebSocketServer.js +0 -56
- package/dist/cjs/rsc/utils.js +0 -56
- package/dist/rsc/rscWebSocketServer.d.ts +0 -2
- package/dist/rsc/rscWebSocketServer.d.ts.map +0 -1
- package/dist/rsc/rscWebSocketServer.js +0 -22
- package/dist/rsc/utils.d.ts +0 -10
- package/dist/rsc/utils.d.ts.map +0 -1
- package/dist/rsc/utils.js +0 -21
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var streamHelpers_exports = {};
|
|
30
30
|
__export(streamHelpers_exports, {
|
|
31
|
+
importModule: () => importModule,
|
|
31
32
|
reactRenderToStreamResponse: () => reactRenderToStreamResponse
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(streamHelpers_exports);
|
|
@@ -61,7 +62,7 @@ globalThis.__webpack_require__ ||= (id) => {
|
|
|
61
62
|
return globalThis.__rw_module_cache__.get(id)
|
|
62
63
|
};
|
|
63
64
|
`;
|
|
64
|
-
async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions
|
|
65
|
+
async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions) {
|
|
65
66
|
const { waitForAllReady = false } = streamOptions;
|
|
66
67
|
const {
|
|
67
68
|
ServerEntry,
|
|
@@ -83,13 +84,13 @@ async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions,
|
|
|
83
84
|
meta: metaTags
|
|
84
85
|
});
|
|
85
86
|
const rscEnabled = (0, import_project_config.getConfig)().experimental?.rsc?.enabled;
|
|
86
|
-
const { createElement } = rscEnabled ? await importModule("__rwjs__react"
|
|
87
|
+
const { createElement } = rscEnabled ? await importModule("__rwjs__react") : await import("react");
|
|
87
88
|
const {
|
|
88
89
|
createInjector,
|
|
89
90
|
ServerHtmlProvider,
|
|
90
91
|
ServerInjectedHtml
|
|
91
|
-
} = rscEnabled ? await importModule("__rwjs__server_inject"
|
|
92
|
-
const { renderToString } = rscEnabled ? await importModule("rd-server"
|
|
92
|
+
} = rscEnabled ? await importModule("__rwjs__server_inject") : await import("@cedarjs/web/serverInject");
|
|
93
|
+
const { renderToString } = rscEnabled ? await importModule("rd-server") : await import("react-dom/server");
|
|
93
94
|
const { injectionState, injectToPage } = createInjector();
|
|
94
95
|
const bufferTransform = (0, import_bufferedTransform.createBufferedTransformStream)();
|
|
95
96
|
const serverInjectionTransform = (0, import_serverInjectionTransform.createServerInjectionTransform)({
|
|
@@ -104,8 +105,8 @@ async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions,
|
|
|
104
105
|
controller.abort();
|
|
105
106
|
}, 1e4);
|
|
106
107
|
const timeoutTransform = (0, import_cancelTimeoutTransform.createTimeoutTransform)(timeoutHandle);
|
|
107
|
-
const { ServerAuthProvider } = rscEnabled ? await importModule("__rwjs__server_auth_provider"
|
|
108
|
-
const { LocationProvider } = rscEnabled ? await importModule("__rwjs__location"
|
|
108
|
+
const { ServerAuthProvider } = rscEnabled ? await importModule("__rwjs__server_auth_provider") : await import("@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js");
|
|
109
|
+
const { LocationProvider } = rscEnabled ? await importModule("__rwjs__location") : await import("@cedarjs/router/location");
|
|
109
110
|
const renderRoot = (url) => {
|
|
110
111
|
return createElement(
|
|
111
112
|
ServerAuthProvider,
|
|
@@ -137,7 +138,7 @@ async function reactRenderToStreamResponse(mwRes, renderOptions, streamOptions,
|
|
|
137
138
|
),
|
|
138
139
|
bootstrapModules: jsBundles
|
|
139
140
|
};
|
|
140
|
-
const { renderToReadableStream } = rscEnabled ? await importModule("rd-server"
|
|
141
|
+
const { renderToReadableStream } = rscEnabled ? await importModule("rd-server") : await import("react-dom/server.edge");
|
|
141
142
|
try {
|
|
142
143
|
let didErrorOutsideShell = false;
|
|
143
144
|
const renderToStreamOptions = {
|
|
@@ -196,52 +197,32 @@ function applyStreamTransforms(reactStream, transformsToApply) {
|
|
|
196
197
|
}
|
|
197
198
|
return outputStream;
|
|
198
199
|
}
|
|
199
|
-
async function importModule(mod
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const reactPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "__rwjs__react.mjs"));
|
|
221
|
-
const locationPath = (0, import_utils.makeFilePath)(
|
|
222
|
-
import_node_path.default.join(distSsr, "__rwjs__location.mjs")
|
|
223
|
-
);
|
|
224
|
-
const serverAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
225
|
-
import_node_path.default.join(distSsr, "__rwjs__server_auth_provider.mjs")
|
|
226
|
-
);
|
|
227
|
-
const serverInjectPath = (0, import_utils.makeFilePath)(
|
|
228
|
-
import_node_path.default.join(distSsr, "__rwjs__server_inject.mjs")
|
|
229
|
-
);
|
|
230
|
-
if (mod === "rd-server") {
|
|
231
|
-
return (await import(rdServerPath)).default;
|
|
232
|
-
} else if (mod === "__rwjs__react") {
|
|
233
|
-
return (await import(reactPath)).default;
|
|
234
|
-
} else if (mod === "__rwjs__location") {
|
|
235
|
-
return await import(locationPath);
|
|
236
|
-
} else if (mod === "__rwjs__server_auth_provider") {
|
|
237
|
-
return await import(serverAuthProviderPath);
|
|
238
|
-
} else if (mod === "__rwjs__server_inject") {
|
|
239
|
-
return await import(serverInjectPath);
|
|
240
|
-
}
|
|
200
|
+
async function importModule(mod) {
|
|
201
|
+
const distSsr = (0, import_project_config.getPaths)().web.distSsr;
|
|
202
|
+
const rdServerPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "rd-server.mjs"));
|
|
203
|
+
const reactPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "__rwjs__react.mjs"));
|
|
204
|
+
const locationPath = (0, import_utils.makeFilePath)(import_node_path.default.join(distSsr, "__rwjs__location.mjs"));
|
|
205
|
+
const ServerAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
206
|
+
import_node_path.default.join(distSsr, "__rwjs__server_auth_provider.mjs")
|
|
207
|
+
);
|
|
208
|
+
const ServerInjectPath = (0, import_utils.makeFilePath)(
|
|
209
|
+
import_node_path.default.join(distSsr, "__rwjs__server_inject.mjs")
|
|
210
|
+
);
|
|
211
|
+
if (mod === "rd-server") {
|
|
212
|
+
return (await import(rdServerPath)).default;
|
|
213
|
+
} else if (mod === "__rwjs__react") {
|
|
214
|
+
return (await import(reactPath)).default;
|
|
215
|
+
} else if (mod === "__rwjs__location") {
|
|
216
|
+
return await import(locationPath);
|
|
217
|
+
} else if (mod === "__rwjs__server_auth_provider") {
|
|
218
|
+
return await import(ServerAuthProviderPath);
|
|
219
|
+
} else if (mod === "__rwjs__server_inject") {
|
|
220
|
+
return await import(ServerInjectPath);
|
|
241
221
|
}
|
|
242
222
|
throw new Error("Unknown module " + mod);
|
|
243
223
|
}
|
|
244
224
|
// Annotate the CommonJS export names for ESM import in node:
|
|
245
225
|
0 && (module.exports = {
|
|
226
|
+
importModule,
|
|
246
227
|
reactRenderToStreamResponse
|
|
247
228
|
});
|
|
@@ -55,11 +55,11 @@ const defaultRouteHookOutput = {
|
|
|
55
55
|
const loadAndRunRouteHooks = async ({
|
|
56
56
|
paths = [],
|
|
57
57
|
reqMeta,
|
|
58
|
-
|
|
58
|
+
viteDevServer,
|
|
59
59
|
previousOutput = defaultRouteHookOutput
|
|
60
60
|
}) => {
|
|
61
61
|
const loadModule = async (path) => {
|
|
62
|
-
return
|
|
62
|
+
return viteDevServer ? viteDevServer.ssrLoadModule(path) : import(path);
|
|
63
63
|
};
|
|
64
64
|
let currentRouteHooks;
|
|
65
65
|
let rhOutput = defaultRouteHookOutput;
|
|
@@ -79,7 +79,7 @@ const loadAndRunRouteHooks = async ({
|
|
|
79
79
|
paths,
|
|
80
80
|
reqMeta,
|
|
81
81
|
previousOutput: rhOutput,
|
|
82
|
-
|
|
82
|
+
viteDevServer
|
|
83
83
|
});
|
|
84
84
|
} else {
|
|
85
85
|
return rhOutput;
|
package/dist/devFeServer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import http from "node:http";
|
|
2
1
|
import { createServerAdapter } from "@whatwg-node/server";
|
|
3
2
|
import express from "express";
|
|
4
|
-
import { createServer as createViteServer
|
|
3
|
+
import { createServer as createViteServer } from "vite";
|
|
5
4
|
import { cjsInterop } from "vite-plugin-cjs-interop";
|
|
6
5
|
import { getProjectRoutes } from "@cedarjs/internal/dist/routes.js";
|
|
7
6
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
@@ -10,10 +9,6 @@ import { registerFwGlobalsAndShims } from "./lib/registerFwGlobalsAndShims.js";
|
|
|
10
9
|
import { invoke } from "./middleware/invokeMiddleware.js";
|
|
11
10
|
import { createMiddlewareRouter } from "./middleware/register.js";
|
|
12
11
|
import { rscRoutesAutoLoader } from "./plugins/vite-plugin-rsc-routes-auto-loader.js";
|
|
13
|
-
import { rscRoutesImports } from "./plugins/vite-plugin-rsc-routes-imports.js";
|
|
14
|
-
import { rscSsrRouterImport } from "./plugins/vite-plugin-rsc-ssr-router-import.js";
|
|
15
|
-
import { rscTransformUseServerPlugin } from "./plugins/vite-plugin-rsc-transform-server.js";
|
|
16
|
-
import { createWebSocketServer } from "./rsc/rscWebSocketServer.js";
|
|
17
12
|
import { collectCssPaths, componentsModules } from "./streaming/collectCss.js";
|
|
18
13
|
import { createReactStreamingHandler } from "./streaming/createReactStreamingHandler.js";
|
|
19
14
|
import {
|
|
@@ -22,13 +17,10 @@ import {
|
|
|
22
17
|
getFullUrl
|
|
23
18
|
} from "./utils.js";
|
|
24
19
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
25
|
-
globalThis.__rwjs__vite_ssr_runtime = void 0;
|
|
26
|
-
globalThis.__rwjs__vite_rsc_runtime = void 0;
|
|
27
20
|
async function createServer() {
|
|
28
21
|
ensureProcessDirWeb();
|
|
29
22
|
registerFwGlobalsAndShims();
|
|
30
23
|
const app = express();
|
|
31
|
-
const server = http.createServer(app);
|
|
32
24
|
const rwPaths = getPaths();
|
|
33
25
|
const rscEnabled = getConfig().experimental.rsc?.enabled ?? false;
|
|
34
26
|
const serverStorage = createServerStorage();
|
|
@@ -51,76 +43,8 @@ async function createServer() {
|
|
|
51
43
|
"Vite config not found. You need to setup your project with Vite using `yarn rw setup vite`"
|
|
52
44
|
);
|
|
53
45
|
}
|
|
54
|
-
const
|
|
46
|
+
const vite = await createViteServer({
|
|
55
47
|
configFile: rwPaths.web.viteConfig,
|
|
56
|
-
envFile: false,
|
|
57
|
-
define: {
|
|
58
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
59
|
-
},
|
|
60
|
-
ssr: {
|
|
61
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
62
|
-
// inline dependencies in the server build. This gets round runtime
|
|
63
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
64
|
-
//
|
|
65
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
66
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
67
|
-
// noExternal: true,
|
|
68
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
69
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
70
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
71
|
-
// we wanted to go that route.
|
|
72
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
73
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
74
|
-
// (css pre-init failure)
|
|
75
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
76
|
-
external: [
|
|
77
|
-
"@prisma/client",
|
|
78
|
-
"@prisma/fetch-engine",
|
|
79
|
-
"@prisma/internals",
|
|
80
|
-
"@cedarjs/auth-dbauth-api",
|
|
81
|
-
"@cedarjs/cookie-jar",
|
|
82
|
-
"@cedarjs/server-store",
|
|
83
|
-
"@simplewebauthn/server",
|
|
84
|
-
"graphql-scalars",
|
|
85
|
-
"minimatch",
|
|
86
|
-
"playwright",
|
|
87
|
-
"react-dom"
|
|
88
|
-
],
|
|
89
|
-
resolve: {
|
|
90
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
91
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
92
|
-
// dependencies apart from node built-ins.
|
|
93
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
94
|
-
// `externalConditions`? When is one used over the other?
|
|
95
|
-
// conditions: ['react-server'],
|
|
96
|
-
// externalConditions: ['react-server'],
|
|
97
|
-
},
|
|
98
|
-
optimizeDeps: {
|
|
99
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
100
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
101
|
-
// include: [
|
|
102
|
-
// 'react/**/*',
|
|
103
|
-
// 'react-dom/server',
|
|
104
|
-
// 'react-dom/server.edge',
|
|
105
|
-
// 'rehackt',
|
|
106
|
-
// 'react-server-dom-webpack/server',
|
|
107
|
-
// 'react-server-dom-webpack/client',
|
|
108
|
-
// '@apollo/client/cache/*',
|
|
109
|
-
// '@apollo/client/utilities/*',
|
|
110
|
-
// '@apollo/client/react/hooks/*',
|
|
111
|
-
// 'react-fast-compare',
|
|
112
|
-
// 'invariant',
|
|
113
|
-
// 'shallowequal',
|
|
114
|
-
// 'graphql/language/*',
|
|
115
|
-
// 'stacktracey',
|
|
116
|
-
// 'deepmerge',
|
|
117
|
-
// 'fast-glob',
|
|
118
|
-
// ],
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
resolve: {
|
|
122
|
-
// conditions: ['react-server'],
|
|
123
|
-
},
|
|
124
48
|
plugins: [
|
|
125
49
|
cjsInterop({
|
|
126
50
|
dependencies: [
|
|
@@ -134,182 +58,16 @@ async function createServer() {
|
|
|
134
58
|
"@cedarjs/auth-!(dbauth)-web"
|
|
135
59
|
]
|
|
136
60
|
}),
|
|
137
|
-
rscEnabled && rscRoutesAutoLoader()
|
|
138
|
-
rscEnabled && rscSsrRouterImport()
|
|
61
|
+
rscEnabled && rscRoutesAutoLoader()
|
|
139
62
|
],
|
|
140
63
|
server: { middlewareMode: true },
|
|
141
64
|
logLevel: "info",
|
|
142
65
|
clearScreen: false,
|
|
143
66
|
appType: "custom"
|
|
144
67
|
});
|
|
145
|
-
globalThis.__rwjs__vite_ssr_runtime = await createViteRuntime(viteSsrDevServer);
|
|
146
|
-
globalThis.__rwjs__client_references = /* @__PURE__ */ new Set();
|
|
147
|
-
globalThis.__rwjs__server_references = /* @__PURE__ */ new Set();
|
|
148
|
-
const viteRscServer = await createViteServer({
|
|
149
|
-
envFile: false,
|
|
150
|
-
define: {
|
|
151
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
152
|
-
},
|
|
153
|
-
ssr: {
|
|
154
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
155
|
-
// inline dependencies in the server build. This gets round runtime
|
|
156
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
157
|
-
//
|
|
158
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
159
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
160
|
-
noExternal: true,
|
|
161
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
162
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
163
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
164
|
-
// we wanted to go that route.
|
|
165
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
166
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
167
|
-
// (css pre-init failure)
|
|
168
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
169
|
-
external: [
|
|
170
|
-
"@prisma/client",
|
|
171
|
-
"@prisma/fetch-engine",
|
|
172
|
-
"@prisma/internals",
|
|
173
|
-
"@cedarjs/auth-dbauth-api",
|
|
174
|
-
"@cedarjs/cookie-jar",
|
|
175
|
-
"@cedarjs/server-store",
|
|
176
|
-
"@cedarjs/structure",
|
|
177
|
-
"@simplewebauthn/server",
|
|
178
|
-
"graphql-scalars",
|
|
179
|
-
"minimatch",
|
|
180
|
-
"playwright",
|
|
181
|
-
"react-dom"
|
|
182
|
-
],
|
|
183
|
-
resolve: {
|
|
184
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
185
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
186
|
-
// dependencies apart from node built-ins.
|
|
187
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
188
|
-
// `externalConditions`? When is one used over the other?
|
|
189
|
-
conditions: ["react-server"],
|
|
190
|
-
externalConditions: ["react-server"]
|
|
191
|
-
},
|
|
192
|
-
optimizeDeps: {
|
|
193
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
194
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
195
|
-
include: [
|
|
196
|
-
"react/**/*",
|
|
197
|
-
"react-dom/server",
|
|
198
|
-
"react-dom/server.edge",
|
|
199
|
-
"rehackt",
|
|
200
|
-
"react-server-dom-webpack/server",
|
|
201
|
-
"react-server-dom-webpack/server.edge",
|
|
202
|
-
"react-server-dom-webpack/client",
|
|
203
|
-
"react-server-dom-webpack/client.edge",
|
|
204
|
-
"@apollo/client/cache/*",
|
|
205
|
-
"@apollo/client/utilities/*",
|
|
206
|
-
"@apollo/client/react/hooks/*",
|
|
207
|
-
"react-fast-compare",
|
|
208
|
-
"invariant",
|
|
209
|
-
"shallowequal",
|
|
210
|
-
"graphql/language/*",
|
|
211
|
-
"stacktracey",
|
|
212
|
-
"deepmerge",
|
|
213
|
-
"fast-glob",
|
|
214
|
-
"@whatwg-node/fetch",
|
|
215
|
-
"busboy",
|
|
216
|
-
"cookie"
|
|
217
|
-
],
|
|
218
|
-
// Without excluding `util` we get "TypeError: util.TextEncoder is not
|
|
219
|
-
// a constructor" in react-server-dom-webpack.server because it'll try
|
|
220
|
-
// to use Browserify's `util` instead of Node's. And Browserify's
|
|
221
|
-
// polyfill is missing TextEncoder+TextDecoder. The reason it's using
|
|
222
|
-
// the Browserify polyfill is because we have
|
|
223
|
-
// `vite-plugin-node-polyfills` as a dependency, and that'll add
|
|
224
|
-
// Browserify's `node-util` to `node_modules`, so when Vite goes to
|
|
225
|
-
// resolve `import { TextEncoder } from 'util` it'll find the one in
|
|
226
|
-
// `node_modules` instead of Node's internal version.
|
|
227
|
-
// We only see this in dev, and not in prod. I'm not entirely sure why
|
|
228
|
-
// but I have two guesses: 1. When RSC is enabled we don't actually use
|
|
229
|
-
// `vite-plugin-node-polyfill`, so some kind of tree shaking is
|
|
230
|
-
// happening, which prevents the issue from occurring. 2. In prod we
|
|
231
|
-
// only use Node's dependency resolution. Vite is not involved. And
|
|
232
|
-
// that difference in resolution is what prevents the issue from
|
|
233
|
-
// occurring.
|
|
234
|
-
exclude: ["util"]
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
resolve: {
|
|
238
|
-
conditions: ["react-server"]
|
|
239
|
-
},
|
|
240
|
-
plugins: [
|
|
241
|
-
{
|
|
242
|
-
name: "rsc-record-and-tranform-use-client-plugin",
|
|
243
|
-
transform(code, id, _options) {
|
|
244
|
-
globalThis.__rwjs__client_references?.delete(id);
|
|
245
|
-
if (!/^(["'])use client\1/.test(code)) {
|
|
246
|
-
return void 0;
|
|
247
|
-
}
|
|
248
|
-
console.log(
|
|
249
|
-
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
250
|
-
id
|
|
251
|
-
);
|
|
252
|
-
globalThis.__rwjs__client_references?.add(id);
|
|
253
|
-
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
254
|
-
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
255
|
-
const names = [...fns, ...consts].map(([, name]) => name);
|
|
256
|
-
const result = [
|
|
257
|
-
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
258
|
-
"",
|
|
259
|
-
...names.map((name) => {
|
|
260
|
-
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
261
|
-
})
|
|
262
|
-
].join("\n");
|
|
263
|
-
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
264
|
-
console.log(
|
|
265
|
-
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
266
|
-
);
|
|
267
|
-
return { code: result, map: null };
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
rscTransformUseServerPlugin("", {}),
|
|
271
|
-
// The rscTransformUseClientPlugin maps paths like
|
|
272
|
-
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
273
|
-
// to
|
|
274
|
-
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
275
|
-
// That's why it needs the `clientEntryFiles` data
|
|
276
|
-
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
277
|
-
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
278
|
-
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
279
|
-
rscRoutesImports(),
|
|
280
|
-
{
|
|
281
|
-
name: "rsc-hot-update",
|
|
282
|
-
handleHotUpdate(ctx) {
|
|
283
|
-
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
284
|
-
return [];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
],
|
|
288
|
-
build: {
|
|
289
|
-
ssr: true
|
|
290
|
-
},
|
|
291
|
-
server: {
|
|
292
|
-
// We never call `viteRscServer.listen()`, so we should run this in
|
|
293
|
-
// middleware mode
|
|
294
|
-
middlewareMode: true,
|
|
295
|
-
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
296
|
-
// the other Vite server. So we can either disable it or run it on a
|
|
297
|
-
// different port.
|
|
298
|
-
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
299
|
-
// port
|
|
300
|
-
ws: false
|
|
301
|
-
// hmr: {
|
|
302
|
-
// port: 24679,
|
|
303
|
-
// },
|
|
304
|
-
},
|
|
305
|
-
appType: "custom",
|
|
306
|
-
// Using a unique cache dir here to not clash with our other vite server
|
|
307
|
-
cacheDir: "../node_modules/.vite-rsc"
|
|
308
|
-
});
|
|
309
|
-
globalThis.__rwjs__vite_rsc_runtime = await createViteRuntime(viteRscServer);
|
|
310
68
|
const handleWithMiddleware = (route) => {
|
|
311
69
|
return createServerAdapter(async (req) => {
|
|
312
|
-
const middlewareRouter = await createMiddlewareRouter(
|
|
70
|
+
const middlewareRouter = await createMiddlewareRouter(vite);
|
|
313
71
|
const middleware = middlewareRouter.find(
|
|
314
72
|
req.method,
|
|
315
73
|
req.url
|
|
@@ -319,22 +77,19 @@ async function createServer() {
|
|
|
319
77
|
}
|
|
320
78
|
const [mwRes] = await invoke(req, middleware, {
|
|
321
79
|
route,
|
|
322
|
-
|
|
80
|
+
viteDevServer: vite
|
|
323
81
|
});
|
|
324
82
|
return mwRes.toResponse();
|
|
325
83
|
});
|
|
326
84
|
};
|
|
327
|
-
app.use(
|
|
85
|
+
app.use(vite.middlewares);
|
|
328
86
|
if (rscEnabled) {
|
|
329
|
-
|
|
330
|
-
const { createRscRequestHandler } = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(
|
|
331
|
-
new URL("./rsc/rscRequestHandler.js", import.meta.url).pathname
|
|
332
|
-
);
|
|
87
|
+
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
333
88
|
app.use(
|
|
334
89
|
"/rw-rsc",
|
|
335
|
-
|
|
336
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
337
|
-
|
|
90
|
+
createRscRequestHandler({
|
|
91
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(vite),
|
|
92
|
+
viteDevServer: vite
|
|
338
93
|
})
|
|
339
94
|
);
|
|
340
95
|
}
|
|
@@ -344,22 +99,18 @@ async function createServer() {
|
|
|
344
99
|
routes,
|
|
345
100
|
clientEntryPath: rwPaths.web.entryClient,
|
|
346
101
|
getStylesheetLinks: (route) => {
|
|
347
|
-
return getCssLinks({
|
|
348
|
-
rwPaths,
|
|
349
|
-
route,
|
|
350
|
-
viteSsrDevServer
|
|
351
|
-
});
|
|
102
|
+
return getCssLinks({ rwPaths, route, vite });
|
|
352
103
|
},
|
|
353
104
|
// Recreate middleware router on each request in dev
|
|
354
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
105
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(vite)
|
|
355
106
|
},
|
|
356
|
-
|
|
107
|
+
vite
|
|
357
108
|
);
|
|
358
109
|
app.get("*", createServerAdapter(routeHandler));
|
|
359
110
|
app.post("*", handleWithMiddleware());
|
|
360
111
|
const port = getConfig().web.port;
|
|
361
112
|
console.log(`Started server on http://localhost:${port}`);
|
|
362
|
-
return
|
|
113
|
+
return app.listen(port);
|
|
363
114
|
}
|
|
364
115
|
let devApp = createServer();
|
|
365
116
|
process.stdin.on("data", async (data) => {
|
|
@@ -374,11 +125,11 @@ process.stdin.on("data", async (data) => {
|
|
|
374
125
|
function getCssLinks({
|
|
375
126
|
rwPaths,
|
|
376
127
|
route,
|
|
377
|
-
|
|
128
|
+
vite
|
|
378
129
|
}) {
|
|
379
130
|
const appAndRouteModules = componentsModules(
|
|
380
131
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
381
|
-
|
|
132
|
+
vite
|
|
382
133
|
);
|
|
383
134
|
const collectedCss = collectCssPaths(appAndRouteModules);
|
|
384
135
|
const cssLinks = Array.from(collectedCss);
|
|
@@ -54,15 +54,6 @@ function registerFwShims() {
|
|
|
54
54
|
globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
|
|
55
55
|
globalThis.__webpack_chunk_load__ ||= async (id) => {
|
|
56
56
|
console.log("registerFwShims chunk load id", id);
|
|
57
|
-
if (globalThis.__rwjs__vite_ssr_runtime) {
|
|
58
|
-
return globalThis.__rwjs__vite_ssr_runtime?.executeUrl(id).then((mod) => {
|
|
59
|
-
console.log("registerFwShims chunk load mod", mod);
|
|
60
|
-
if (mod.default && typeof mod.default === "object") {
|
|
61
|
-
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
62
|
-
}
|
|
63
|
-
return globalThis.__rw_module_cache__.set(id, mod);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
57
|
return import(id).then((mod) => {
|
|
67
58
|
console.log("registerFwShims chunk load mod", mod);
|
|
68
59
|
if (mod.default && typeof mod.default === "object") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-rsc-ssr-router-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-ssr-router-import.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"vite-plugin-rsc-ssr-router-import.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-ssr-router-import.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAKlC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAqC3C"}
|
|
@@ -11,8 +11,8 @@ function rscSsrRouterImport() {
|
|
|
11
11
|
const routesFileId = normalizePath(getPaths().web.routes);
|
|
12
12
|
return {
|
|
13
13
|
name: "rsc-ssr-router-import",
|
|
14
|
-
transform: async function(code, id
|
|
15
|
-
if (
|
|
14
|
+
transform: async function(code, id) {
|
|
15
|
+
if (id !== routesFileId) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
const ext = path.extname(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-rsc-transform-server.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-transform-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,MAAM,
|
|
1
|
+
{"version":3,"file":"vite-plugin-rsc-transform-server.d.ts","sourceRoot":"","sources":["../../src/plugins/vite-plugin-rsc-transform-server.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,MAAM,CA8GR"}
|
|
@@ -8,10 +8,6 @@ function rscTransformUseServerPlugin(outDir, serverEntryFiles) {
|
|
|
8
8
|
if (!code.includes("use server")) {
|
|
9
9
|
return code;
|
|
10
10
|
}
|
|
11
|
-
if (id.includes("node_modules/.vite") || id.includes("/react-server-dom-webpack/") || id.includes("/react-server-dom-webpack.server")) {
|
|
12
|
-
console.log("vite-plugin-rsc-transform-server.ts: Skipping", id);
|
|
13
|
-
return code;
|
|
14
|
-
}
|
|
15
11
|
let mod;
|
|
16
12
|
const isTypescript = id.endsWith(".ts") || id.endsWith(".tsx");
|
|
17
13
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rscRenderer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRenderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"rscRenderer.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRenderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAWrD,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;CAC7B,CAAA;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAE7E;AAyBD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA2BtD"}
|
package/dist/rsc/rscRenderer.js
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { renderToReadableStream } from "react-server-dom-webpack/server.edge";
|
|
2
4
|
import { getPaths } from "@cedarjs/project-config";
|
|
3
5
|
import { getEntriesFromDist } from "../lib/entries.js";
|
|
4
6
|
import { StatusError } from "../lib/StatusError.js";
|
|
5
|
-
import { importRscReact, importRsdwServer } from "./utils.js";
|
|
6
7
|
let absoluteClientEntries = {};
|
|
7
|
-
|
|
8
|
+
function renderRscToStream(input) {
|
|
8
9
|
return input.rscId ? renderRsc(input) : executeRsa(input);
|
|
9
10
|
}
|
|
10
11
|
async function loadServerFile(filePath) {
|
|
11
12
|
console.log("rscRenderer.ts loadServerFile filePath", filePath);
|
|
12
|
-
if (globalThis.__rwjs__vite_rsc_runtime) {
|
|
13
|
-
const serverMod = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(filePath);
|
|
14
|
-
return serverMod.default ? serverMod.default : serverMod;
|
|
15
|
-
}
|
|
16
13
|
return import(`file://${filePath}`);
|
|
17
14
|
}
|
|
18
15
|
const getRoutesComponent = async () => {
|
|
19
|
-
if (globalThis.__rwjs__vite_rsc_runtime) {
|
|
20
|
-
const routesPath2 = getPaths().web.routes;
|
|
21
|
-
const routesMod = await globalThis.__rwjs__vite_rsc_runtime.executeUrl(routesPath2);
|
|
22
|
-
return routesMod.default;
|
|
23
|
-
}
|
|
24
16
|
const serverEntries = await getEntriesFromDist();
|
|
25
17
|
console.log("rscRenderer.ts serverEntries", serverEntries);
|
|
26
18
|
const routesPath = path.join(
|
|
@@ -61,12 +53,10 @@ function getBundlerConfig() {
|
|
|
61
53
|
{},
|
|
62
54
|
{
|
|
63
55
|
get(_target, encodedId) {
|
|
64
|
-
console.log("
|
|
56
|
+
console.log("Proxy get encodedId", encodedId);
|
|
65
57
|
const [filePath, name] = encodedId.split("#");
|
|
66
|
-
console.log("filePath", filePath);
|
|
67
|
-
console.log("name", name);
|
|
68
58
|
const filePathSlash = filePath.replaceAll("\\", "/");
|
|
69
|
-
const id =
|
|
59
|
+
const id = absoluteClientEntries[filePathSlash];
|
|
70
60
|
console.log("absoluteClientEntries", absoluteClientEntries);
|
|
71
61
|
console.log("filePath", filePathSlash);
|
|
72
62
|
if (!id) {
|
|
@@ -89,8 +79,6 @@ async function renderRsc(input) {
|
|
|
89
79
|
throw new Error("Unexpected input. Missing rscId or props.");
|
|
90
80
|
}
|
|
91
81
|
console.log("renderRsc input", input);
|
|
92
|
-
const { createElement } = await importRscReact();
|
|
93
|
-
const { renderToReadableStream } = await importRsdwServer();
|
|
94
82
|
const serverRoutes = await getRoutesComponent();
|
|
95
83
|
const model = {
|
|
96
84
|
__rwjs__Routes: createElement(serverRoutes)
|
|
@@ -127,8 +115,6 @@ async function executeRsa(input) {
|
|
|
127
115
|
console.log("rscRenderer.ts args", ...input.args);
|
|
128
116
|
const data = await method(...input.args);
|
|
129
117
|
console.log("rscRenderer.ts rsa return data", data);
|
|
130
|
-
const { createElement } = await importRscReact();
|
|
131
|
-
const { renderToReadableStream } = await importRsdwServer();
|
|
132
118
|
const serverRoutes = await getRoutesComponent();
|
|
133
119
|
console.log("rscRenderer.ts executeRsa serverRoutes", serverRoutes);
|
|
134
120
|
const model = {
|
|
@@ -3,8 +3,8 @@ import type Router from 'find-my-way';
|
|
|
3
3
|
import type { ViteDevServer } from 'vite';
|
|
4
4
|
interface CreateRscRequestHandlerOptions {
|
|
5
5
|
getMiddlewareRouter: () => Promise<Router.Instance<any>>;
|
|
6
|
-
|
|
6
|
+
viteDevServer?: ViteDevServer;
|
|
7
7
|
}
|
|
8
|
-
export declare function createRscRequestHandler(options: CreateRscRequestHandlerOptions):
|
|
8
|
+
export declare function createRscRequestHandler(options: CreateRscRequestHandlerOptions): (req: ExpressRequest, res: ExpressResponse, next: () => void) => Promise<void>;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=rscRequestHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rscRequestHandler.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRequestHandler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAC5B,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"rscRequestHandler.d.ts","sourceRoot":"","sources":["../../src/rsc/rscRequestHandler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,OAAO,IAAI,cAAc,EACzB,QAAQ,IAAI,eAAe,EAC5B,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAgBzC,UAAU,8BAA8B;IACtC,mBAAmB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAA;IACxD,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,IAMrC,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,MAAM,MAAM,IAAI,mBAqHnB"}
|