@cedarjs/vite 4.0.0-canary.13803 → 4.0.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/cjs/devFeServer.js +15 -280
- 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 +32 -49
- package/dist/cjs/streaming/triggerRouteHooks.js +3 -3
- package/dist/devFeServer.js +16 -284
- 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 +31 -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 +11 -11
|
@@ -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("__cedarjs__react"
|
|
87
|
+
const { createElement } = rscEnabled ? await importModule("__cedarjs__react") : await import("react");
|
|
87
88
|
const {
|
|
88
89
|
createInjector,
|
|
89
90
|
ServerHtmlProvider,
|
|
90
91
|
ServerInjectedHtml
|
|
91
|
-
} = rscEnabled ? await importModule("__cedarjs__server_inject"
|
|
92
|
-
const { renderToString } = rscEnabled ? await importModule("rd-server"
|
|
92
|
+
} = rscEnabled ? await importModule("__cedarjs__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("__cedarjs__server_auth_provider"
|
|
108
|
-
const { LocationProvider } = rscEnabled ? await importModule("__cedarjs__location"
|
|
108
|
+
const { ServerAuthProvider } = rscEnabled ? await importModule("__cedarjs__server_auth_provider") : await import("@cedarjs/auth/dist/AuthProvider/ServerAuthProvider.js");
|
|
109
|
+
const { LocationProvider } = rscEnabled ? await importModule("__cedarjs__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,34 @@ 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
|
-
|
|
221
|
-
|
|
222
|
-
import_node_path.default.join(distSsr, "__cedarjs__location.mjs")
|
|
223
|
-
);
|
|
224
|
-
const serverAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
225
|
-
import_node_path.default.join(distSsr, "__cedarjs__server_auth_provider.mjs")
|
|
226
|
-
);
|
|
227
|
-
const serverInjectPath = (0, import_utils.makeFilePath)(
|
|
228
|
-
import_node_path.default.join(distSsr, "__cedarjs__server_inject.mjs")
|
|
229
|
-
);
|
|
230
|
-
if (mod === "rd-server") {
|
|
231
|
-
return (await import(rdServerPath)).default;
|
|
232
|
-
} else if (mod === "__cedarjs__react") {
|
|
233
|
-
return (await import(reactPath)).default;
|
|
234
|
-
} else if (mod === "__cedarjs__location") {
|
|
235
|
-
return await import(locationPath);
|
|
236
|
-
} else if (mod === "__cedarjs__server_auth_provider") {
|
|
237
|
-
return await import(serverAuthProviderPath);
|
|
238
|
-
} else if (mod === "__cedarjs__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, "__cedarjs__react.mjs"));
|
|
204
|
+
const locationPath = (0, import_utils.makeFilePath)(
|
|
205
|
+
import_node_path.default.join(distSsr, "__cedarjs__location.mjs")
|
|
206
|
+
);
|
|
207
|
+
const ServerAuthProviderPath = (0, import_utils.makeFilePath)(
|
|
208
|
+
import_node_path.default.join(distSsr, "__cedarjs__server_auth_provider.mjs")
|
|
209
|
+
);
|
|
210
|
+
const ServerInjectPath = (0, import_utils.makeFilePath)(
|
|
211
|
+
import_node_path.default.join(distSsr, "__cedarjs__server_inject.mjs")
|
|
212
|
+
);
|
|
213
|
+
if (mod === "rd-server") {
|
|
214
|
+
return (await import(rdServerPath)).default;
|
|
215
|
+
} else if (mod === "__cedarjs__react") {
|
|
216
|
+
return (await import(reactPath)).default;
|
|
217
|
+
} else if (mod === "__cedarjs__location") {
|
|
218
|
+
return await import(locationPath);
|
|
219
|
+
} else if (mod === "__cedarjs__server_auth_provider") {
|
|
220
|
+
return await import(ServerAuthProviderPath);
|
|
221
|
+
} else if (mod === "__cedarjs__server_inject") {
|
|
222
|
+
return await import(ServerInjectPath);
|
|
241
223
|
}
|
|
242
224
|
throw new Error("Unknown module " + mod);
|
|
243
225
|
}
|
|
244
226
|
// Annotate the CommonJS export names for ESM import in node:
|
|
245
227
|
0 && (module.exports = {
|
|
228
|
+
importModule,
|
|
246
229
|
reactRenderToStreamResponse
|
|
247
230
|
});
|
|
@@ -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,11 +1,6 @@
|
|
|
1
|
-
import http from "node:http";
|
|
2
1
|
import { createServerAdapter } from "@whatwg-node/server";
|
|
3
2
|
import express from "express";
|
|
4
|
-
import {
|
|
5
|
-
createServer as createViteServer,
|
|
6
|
-
createServerModuleRunner,
|
|
7
|
-
defaultServerConditions
|
|
8
|
-
} from "vite";
|
|
3
|
+
import { createServer as createViteServer } from "vite";
|
|
9
4
|
import { cjsInterop } from "vite-plugin-cjs-interop";
|
|
10
5
|
import { getProjectRoutes } from "@cedarjs/internal/dist/routes.js";
|
|
11
6
|
import { getConfig, getPaths } from "@cedarjs/project-config";
|
|
@@ -14,10 +9,6 @@ import { registerFwGlobalsAndShims } from "./lib/registerFwGlobalsAndShims.js";
|
|
|
14
9
|
import { invoke } from "./middleware/invokeMiddleware.js";
|
|
15
10
|
import { createMiddlewareRouter } from "./middleware/register.js";
|
|
16
11
|
import { rscRoutesAutoLoader } from "./plugins/vite-plugin-rsc-routes-auto-loader.js";
|
|
17
|
-
import { rscRoutesImports } from "./plugins/vite-plugin-rsc-routes-imports.js";
|
|
18
|
-
import { rscSsrRouterImport } from "./plugins/vite-plugin-rsc-ssr-router-import.js";
|
|
19
|
-
import { rscTransformUseServerPlugin } from "./plugins/vite-plugin-rsc-transform-server.js";
|
|
20
|
-
import { createWebSocketServer } from "./rsc/rscWebSocketServer.js";
|
|
21
12
|
import { collectCssPaths, componentsModules } from "./streaming/collectCss.js";
|
|
22
13
|
import { createReactStreamingHandler } from "./streaming/createReactStreamingHandler.js";
|
|
23
14
|
import {
|
|
@@ -26,13 +17,10 @@ import {
|
|
|
26
17
|
getFullUrl
|
|
27
18
|
} from "./utils.js";
|
|
28
19
|
globalThis.__REDWOOD__PRERENDER_PAGES = {};
|
|
29
|
-
globalThis.__cedarjs__vite_ssr_runtime = void 0;
|
|
30
|
-
globalThis.__cedarjs__vite_rsc_runtime = void 0;
|
|
31
20
|
async function createServer() {
|
|
32
21
|
ensureProcessDirWeb();
|
|
33
22
|
registerFwGlobalsAndShims();
|
|
34
23
|
const app = express();
|
|
35
|
-
const server = http.createServer(app);
|
|
36
24
|
const rwPaths = getPaths();
|
|
37
25
|
const rscEnabled = getConfig().experimental.rsc?.enabled ?? false;
|
|
38
26
|
const serverStorage = createServerStorage();
|
|
@@ -55,78 +43,8 @@ async function createServer() {
|
|
|
55
43
|
"Vite config not found. You need to setup your project with Vite using `yarn cedar setup vite`"
|
|
56
44
|
);
|
|
57
45
|
}
|
|
58
|
-
const
|
|
46
|
+
const vite = await createViteServer({
|
|
59
47
|
configFile: rwPaths.web.viteConfig,
|
|
60
|
-
envFile: false,
|
|
61
|
-
define: {
|
|
62
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
63
|
-
},
|
|
64
|
-
ssr: {
|
|
65
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
66
|
-
// inline dependencies in the server build. This gets round runtime
|
|
67
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
68
|
-
//
|
|
69
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
70
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
71
|
-
// noExternal: true,
|
|
72
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
73
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
74
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
75
|
-
// we wanted to go that route.
|
|
76
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
77
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
78
|
-
// (css pre-init failure)
|
|
79
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
80
|
-
external: [
|
|
81
|
-
"@prisma/client",
|
|
82
|
-
"@prisma/adapter-better-sqlite3",
|
|
83
|
-
"@prisma/fetch-engine",
|
|
84
|
-
"@prisma/internals",
|
|
85
|
-
"better-sqlite3",
|
|
86
|
-
"@cedarjs/auth-dbauth-api",
|
|
87
|
-
"@cedarjs/cookie-jar",
|
|
88
|
-
"@cedarjs/server-store",
|
|
89
|
-
"@simplewebauthn/server",
|
|
90
|
-
"graphql-scalars",
|
|
91
|
-
"minimatch",
|
|
92
|
-
"playwright",
|
|
93
|
-
"react-dom"
|
|
94
|
-
],
|
|
95
|
-
resolve: {
|
|
96
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
97
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
98
|
-
// dependencies apart from node built-ins.
|
|
99
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
100
|
-
// `externalConditions`? When is one used over the other?
|
|
101
|
-
// conditions: ['react-server'],
|
|
102
|
-
// externalConditions: ['react-server'],
|
|
103
|
-
},
|
|
104
|
-
optimizeDeps: {
|
|
105
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
106
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
107
|
-
// include: [
|
|
108
|
-
// 'react/**/*',
|
|
109
|
-
// 'react-dom/server',
|
|
110
|
-
// 'react-dom/server.edge',
|
|
111
|
-
// 'rehackt',
|
|
112
|
-
// 'react-server-dom-webpack/server',
|
|
113
|
-
// 'react-server-dom-webpack/client',
|
|
114
|
-
// '@apollo/client/cache/*',
|
|
115
|
-
// '@apollo/client/utilities/*',
|
|
116
|
-
// '@apollo/client/react/hooks/*',
|
|
117
|
-
// 'react-fast-compare',
|
|
118
|
-
// 'invariant',
|
|
119
|
-
// 'shallowequal',
|
|
120
|
-
// 'graphql/language/*',
|
|
121
|
-
// 'stacktracey',
|
|
122
|
-
// 'deepmerge',
|
|
123
|
-
// 'fast-glob',
|
|
124
|
-
// ],
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
resolve: {
|
|
128
|
-
// conditions: ['react-server'],
|
|
129
|
-
},
|
|
130
48
|
plugins: [
|
|
131
49
|
cjsInterop({
|
|
132
50
|
dependencies: [
|
|
@@ -140,195 +58,16 @@ async function createServer() {
|
|
|
140
58
|
"@cedarjs/auth-!(dbauth)-web"
|
|
141
59
|
]
|
|
142
60
|
}),
|
|
143
|
-
rscEnabled && rscRoutesAutoLoader()
|
|
144
|
-
rscEnabled && rscSsrRouterImport()
|
|
61
|
+
rscEnabled && rscRoutesAutoLoader()
|
|
145
62
|
],
|
|
146
63
|
server: { middlewareMode: true },
|
|
147
64
|
logLevel: "info",
|
|
148
65
|
clearScreen: false,
|
|
149
66
|
appType: "custom"
|
|
150
67
|
});
|
|
151
|
-
globalThis.__cedarjs__vite_ssr_runtime = createServerModuleRunner(
|
|
152
|
-
viteSsrDevServer.environments.ssr
|
|
153
|
-
);
|
|
154
|
-
globalThis.__cedarjs__client_references = /* @__PURE__ */ new Set();
|
|
155
|
-
globalThis.__cedarjs__server_references = /* @__PURE__ */ new Set();
|
|
156
|
-
const viteRscServer = await createViteServer({
|
|
157
|
-
envFile: false,
|
|
158
|
-
define: {
|
|
159
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
160
|
-
},
|
|
161
|
-
ssr: {
|
|
162
|
-
// Inline every file apart from node built-ins. We want vite/rollup to
|
|
163
|
-
// inline dependencies in the server build. This gets round runtime
|
|
164
|
-
// importing of "server-only" and other packages with poisoned imports.
|
|
165
|
-
//
|
|
166
|
-
// Files included in `noExternal` are files we want Vite to analyze
|
|
167
|
-
// As of vite 5.2 `true` here means "all except node built-ins"
|
|
168
|
-
noExternal: true,
|
|
169
|
-
// TODO (RSC): Other frameworks build for RSC without `noExternal: true`.
|
|
170
|
-
// What are we missing here? When/why is that a better choice? I know
|
|
171
|
-
// we would have to explicitly add a bunch of packages to noExternal, if
|
|
172
|
-
// we wanted to go that route.
|
|
173
|
-
// noExternal: ['@tobbe.dev/rsc-test'],
|
|
174
|
-
// Can't inline prisma client (db calls fail at runtime) or react-dom
|
|
175
|
-
// (css pre-init failure)
|
|
176
|
-
// Server store has to be externalized, because it's a singleton (shared between FW and App)
|
|
177
|
-
external: [
|
|
178
|
-
"@prisma/client",
|
|
179
|
-
"@prisma/adapter-better-sqlite3",
|
|
180
|
-
"@prisma/fetch-engine",
|
|
181
|
-
"@prisma/internals",
|
|
182
|
-
"better-sqlite3",
|
|
183
|
-
"@cedarjs/auth-dbauth-api",
|
|
184
|
-
"@cedarjs/cookie-jar",
|
|
185
|
-
"@cedarjs/server-store",
|
|
186
|
-
"@cedarjs/structure",
|
|
187
|
-
"@simplewebauthn/server",
|
|
188
|
-
"graphql-scalars",
|
|
189
|
-
"minimatch",
|
|
190
|
-
"playwright",
|
|
191
|
-
"react-dom"
|
|
192
|
-
],
|
|
193
|
-
resolve: {
|
|
194
|
-
// These conditions are used in the plugin pipeline, and only affect non-externalized
|
|
195
|
-
// dependencies during the SSR build. Which because of `noExternal: true` means all
|
|
196
|
-
// dependencies apart from node built-ins.
|
|
197
|
-
// TODO (RSC): What's the difference between `conditions` and
|
|
198
|
-
// `externalConditions`? When is one used over the other?
|
|
199
|
-
// In Vite 6, we must include `defaultServerConditions` alongside
|
|
200
|
-
// `react-server` so that nested condition maps (e.g. the `node`
|
|
201
|
-
// sub-condition inside `react-server-dom-webpack/server`'s exports)
|
|
202
|
-
// can still be resolved. Without `node` (or another environment
|
|
203
|
-
// condition), the resolver throws "No known conditions for
|
|
204
|
-
// './server' specifier in 'react-server-dom-webpack' package".
|
|
205
|
-
conditions: ["react-server", ...defaultServerConditions],
|
|
206
|
-
externalConditions: ["react-server", ...defaultServerConditions]
|
|
207
|
-
},
|
|
208
|
-
optimizeDeps: {
|
|
209
|
-
// We need Vite to optimize these dependencies so that they are resolved
|
|
210
|
-
// with the correct conditions. And so that CJS modules work correctly.
|
|
211
|
-
include: [
|
|
212
|
-
"react/**/*",
|
|
213
|
-
"react-dom/server",
|
|
214
|
-
"react-dom/server.edge",
|
|
215
|
-
"rehackt",
|
|
216
|
-
"react-server-dom-webpack/server",
|
|
217
|
-
"react-server-dom-webpack/server.edge",
|
|
218
|
-
"react-server-dom-webpack/client",
|
|
219
|
-
"react-server-dom-webpack/client.edge",
|
|
220
|
-
"@apollo/client/cache/*",
|
|
221
|
-
"@apollo/client/utilities/*",
|
|
222
|
-
"@apollo/client/react/hooks/*",
|
|
223
|
-
"react-fast-compare",
|
|
224
|
-
"invariant",
|
|
225
|
-
"shallowequal",
|
|
226
|
-
"graphql/language/*",
|
|
227
|
-
"stacktracey",
|
|
228
|
-
"deepmerge",
|
|
229
|
-
"fast-glob",
|
|
230
|
-
"@whatwg-node/fetch",
|
|
231
|
-
"busboy",
|
|
232
|
-
"cookie"
|
|
233
|
-
],
|
|
234
|
-
// Without excluding `util` we get "TypeError: util.TextEncoder is not
|
|
235
|
-
// a constructor" in react-server-dom-webpack.server because it'll try
|
|
236
|
-
// to use Browserify's `util` instead of Node's. And Browserify's
|
|
237
|
-
// polyfill is missing TextEncoder+TextDecoder. The reason it's using
|
|
238
|
-
// the Browserify polyfill is because we have
|
|
239
|
-
// `vite-plugin-node-polyfills` as a dependency, and that'll add
|
|
240
|
-
// Browserify's `node-util` to `node_modules`, so when Vite goes to
|
|
241
|
-
// resolve `import { TextEncoder } from 'util` it'll find the one in
|
|
242
|
-
// `node_modules` instead of Node's internal version.
|
|
243
|
-
// We only see this in dev, and not in prod. I'm not entirely sure why
|
|
244
|
-
// but I have two guesses: 1. When RSC is enabled we don't actually use
|
|
245
|
-
// `vite-plugin-node-polyfill`, so some kind of tree shaking is
|
|
246
|
-
// happening, which prevents the issue from occurring. 2. In prod we
|
|
247
|
-
// only use Node's dependency resolution. Vite is not involved. And
|
|
248
|
-
// that difference in resolution is what prevents the issue from
|
|
249
|
-
// occurring.
|
|
250
|
-
exclude: ["util"]
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
resolve: {
|
|
254
|
-
// See comment above in ssr.resolve for why we include defaultServerConditions.
|
|
255
|
-
conditions: ["react-server", ...defaultServerConditions]
|
|
256
|
-
},
|
|
257
|
-
plugins: [
|
|
258
|
-
{
|
|
259
|
-
name: "rsc-record-and-tranform-use-client-plugin",
|
|
260
|
-
transform(code, id, _options) {
|
|
261
|
-
globalThis.__cedarjs__client_references?.delete(id);
|
|
262
|
-
if (!/^(["'])use client\1/.test(code)) {
|
|
263
|
-
return void 0;
|
|
264
|
-
}
|
|
265
|
-
console.log(
|
|
266
|
-
"rsc-record-and-transform-use-client-plugin: adding client reference",
|
|
267
|
-
id
|
|
268
|
-
);
|
|
269
|
-
globalThis.__cedarjs__client_references?.add(id);
|
|
270
|
-
const fns = code.matchAll(/export function (\w+)\(/g);
|
|
271
|
-
const consts = code.matchAll(/export const (\w+) = \(/g);
|
|
272
|
-
const names = [...fns, ...consts].map(([, name]) => name);
|
|
273
|
-
const result = [
|
|
274
|
-
`import { registerClientReference } from "react-server-dom-webpack/server.edge";`,
|
|
275
|
-
"",
|
|
276
|
-
...names.map((name) => {
|
|
277
|
-
return name === "default" ? `export default registerClientReference({}, "${id}", "${name}");` : `export const ${name} = registerClientReference({}, "${id}", "${name}");`;
|
|
278
|
-
})
|
|
279
|
-
].join("\n");
|
|
280
|
-
console.log("rsc-record-and-transform-use-client-plugin result");
|
|
281
|
-
console.log(
|
|
282
|
-
result.split("\n").map((line, i) => ` ${i + 1}: ${line}`).join("\n")
|
|
283
|
-
);
|
|
284
|
-
return { code: result, map: null };
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
rscTransformUseServerPlugin("", {}),
|
|
288
|
-
// The rscTransformUseClientPlugin maps paths like
|
|
289
|
-
// /Users/tobbe/.../rw-app/node_modules/@tobbe.dev/rsc-test/dist/rsc-test.es.js
|
|
290
|
-
// to
|
|
291
|
-
// /Users/tobbe/.../rw-app/web/dist/ssr/assets/rsc0.js
|
|
292
|
-
// That's why it needs the `clientEntryFiles` data
|
|
293
|
-
// (It does other things as well, but that's why it needs clientEntryFiles)
|
|
294
|
-
// rscTransformUseClientPlugin(clientEntryFiles),
|
|
295
|
-
// rscTransformUseServerPlugin(outDir, serverEntryFiles),
|
|
296
|
-
rscRoutesImports(),
|
|
297
|
-
{
|
|
298
|
-
name: "rsc-hot-update",
|
|
299
|
-
handleHotUpdate(ctx) {
|
|
300
|
-
console.log("rsc-hot-update ctx.modules", ctx.modules);
|
|
301
|
-
return [];
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
],
|
|
305
|
-
build: {
|
|
306
|
-
ssr: true
|
|
307
|
-
},
|
|
308
|
-
server: {
|
|
309
|
-
// We never call `viteRscServer.listen()`, so we should run this in
|
|
310
|
-
// middleware mode
|
|
311
|
-
middlewareMode: true,
|
|
312
|
-
// The hmr/fast-refresh websocket in this server collides with the one in
|
|
313
|
-
// the other Vite server. So we can either disable it or run it on a
|
|
314
|
-
// different port.
|
|
315
|
-
// TODO (RSC): Figure out if we should disable or just pick a different
|
|
316
|
-
// port
|
|
317
|
-
ws: false
|
|
318
|
-
// hmr: {
|
|
319
|
-
// port: 24679,
|
|
320
|
-
// },
|
|
321
|
-
},
|
|
322
|
-
appType: "custom",
|
|
323
|
-
// Using a unique cache dir here to not clash with our other vite server
|
|
324
|
-
cacheDir: "../node_modules/.vite-rsc"
|
|
325
|
-
});
|
|
326
|
-
globalThis.__cedarjs__vite_rsc_runtime = createServerModuleRunner(
|
|
327
|
-
viteRscServer.environments.ssr
|
|
328
|
-
);
|
|
329
68
|
const handleWithMiddleware = (route) => {
|
|
330
69
|
return createServerAdapter(async (req) => {
|
|
331
|
-
const middlewareRouter = await createMiddlewareRouter(
|
|
70
|
+
const middlewareRouter = await createMiddlewareRouter(vite);
|
|
332
71
|
const middleware = middlewareRouter.find(
|
|
333
72
|
req.method,
|
|
334
73
|
req.url
|
|
@@ -338,22 +77,19 @@ async function createServer() {
|
|
|
338
77
|
}
|
|
339
78
|
const [mwRes] = await invoke(req, middleware, {
|
|
340
79
|
route,
|
|
341
|
-
|
|
80
|
+
viteDevServer: vite
|
|
342
81
|
});
|
|
343
82
|
return mwRes.toResponse();
|
|
344
83
|
});
|
|
345
84
|
};
|
|
346
|
-
app.use(
|
|
85
|
+
app.use(vite.middlewares);
|
|
347
86
|
if (rscEnabled) {
|
|
348
|
-
|
|
349
|
-
const { createRscRequestHandler } = await globalThis.__cedarjs__vite_rsc_runtime.import(
|
|
350
|
-
new URL("./rsc/rscRequestHandler.js", import.meta.url).pathname
|
|
351
|
-
);
|
|
87
|
+
const { createRscRequestHandler } = await import("./rsc/rscRequestHandler.js");
|
|
352
88
|
app.use(
|
|
353
89
|
"/rw-rsc",
|
|
354
|
-
|
|
355
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
356
|
-
|
|
90
|
+
createRscRequestHandler({
|
|
91
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(vite),
|
|
92
|
+
viteDevServer: vite
|
|
357
93
|
})
|
|
358
94
|
);
|
|
359
95
|
}
|
|
@@ -363,22 +99,18 @@ async function createServer() {
|
|
|
363
99
|
routes,
|
|
364
100
|
clientEntryPath: rwPaths.web.entryClient,
|
|
365
101
|
getStylesheetLinks: (route) => {
|
|
366
|
-
return getCssLinks({
|
|
367
|
-
rwPaths,
|
|
368
|
-
route,
|
|
369
|
-
viteSsrDevServer
|
|
370
|
-
});
|
|
102
|
+
return getCssLinks({ rwPaths, route, vite });
|
|
371
103
|
},
|
|
372
104
|
// Recreate middleware router on each request in dev
|
|
373
|
-
getMiddlewareRouter: async () => createMiddlewareRouter(
|
|
105
|
+
getMiddlewareRouter: async () => createMiddlewareRouter(vite)
|
|
374
106
|
},
|
|
375
|
-
|
|
107
|
+
vite
|
|
376
108
|
);
|
|
377
109
|
app.get("*", createServerAdapter(routeHandler));
|
|
378
110
|
app.post("*", handleWithMiddleware());
|
|
379
111
|
const port = getConfig().web.port;
|
|
380
112
|
console.log(`Started server on http://localhost:${port}`);
|
|
381
|
-
return
|
|
113
|
+
return app.listen(port);
|
|
382
114
|
}
|
|
383
115
|
let devApp = createServer();
|
|
384
116
|
process.stdin.on("data", async (data) => {
|
|
@@ -393,11 +125,11 @@ process.stdin.on("data", async (data) => {
|
|
|
393
125
|
function getCssLinks({
|
|
394
126
|
rwPaths,
|
|
395
127
|
route,
|
|
396
|
-
|
|
128
|
+
vite
|
|
397
129
|
}) {
|
|
398
130
|
const appAndRouteModules = componentsModules(
|
|
399
131
|
[rwPaths.web.app, route?.filePath].filter(Boolean),
|
|
400
|
-
|
|
132
|
+
vite
|
|
401
133
|
);
|
|
402
134
|
const collectedCss = collectCssPaths(appAndRouteModules);
|
|
403
135
|
const cssLinks = Array.from(collectedCss);
|
|
@@ -55,15 +55,6 @@ function registerFwShims() {
|
|
|
55
55
|
globalThis.__rw_module_cache__ ||= /* @__PURE__ */ new Map();
|
|
56
56
|
globalThis.__webpack_chunk_load__ ||= async (id) => {
|
|
57
57
|
console.log("registerFwShims chunk load id", id);
|
|
58
|
-
if (globalThis.__cedarjs__vite_ssr_runtime) {
|
|
59
|
-
return globalThis.__cedarjs__vite_ssr_runtime?.import(id).then((mod) => {
|
|
60
|
-
console.log("registerFwShims chunk load mod", mod);
|
|
61
|
-
if (mod.default && typeof mod.default === "object") {
|
|
62
|
-
return globalThis.__rw_module_cache__.set(id, mod.default);
|
|
63
|
-
}
|
|
64
|
-
return globalThis.__rw_module_cache__.set(id, mod);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
58
|
return import(id).then((mod) => {
|
|
68
59
|
console.log("registerFwShims chunk load mod", mod);
|
|
69
60
|
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.__cedarjs__vite_rsc_runtime) {
|
|
13
|
-
const serverMod = await globalThis.__cedarjs__vite_rsc_runtime.import(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.__cedarjs__vite_rsc_runtime) {
|
|
20
|
-
const routesPath2 = getPaths().web.routes;
|
|
21
|
-
const routesMod = await globalThis.__cedarjs__vite_rsc_runtime.import(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
|
__cedarjs__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 = {
|