Skip to content

Commit 58439e3

Browse files
Fix custom SSR build input with serverBundles (#13107)
1 parent 2c5d54d commit 58439e3

File tree

4 files changed

+268
-215
lines changed

4 files changed

+268
-215
lines changed

.changeset/pretty-flies-crash.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
Fix support for custom SSR build input when `serverBundles` option has been configured
6+
7+
Note that for consumers using the `future.unstable_viteEnvironmentApi` and `serverBundles` options together, hyphens are no longer supported in server bundle IDs since they also need to be valid Vite environment names.

integration/vite-server-bundles-test.ts

Lines changed: 122 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ const TEST_ROUTES = [
5757
"_index.tsx",
5858

5959
// Bundle A has an index route
60-
"bundle-a.tsx",
61-
"bundle-a._index.tsx",
62-
"bundle-a.route-a.tsx",
63-
"bundle-a.route-b.tsx",
60+
"bundle_a.tsx",
61+
"bundle_a._index.tsx",
62+
"bundle_a.route_a.tsx",
63+
"bundle_a.route_b.tsx",
6464

6565
// Bundle B doesn't have an index route
66-
"bundle-b.tsx",
67-
"bundle-b.route-a.tsx",
68-
"bundle-b.route-b.tsx",
66+
"bundle_b.tsx",
67+
"bundle_b.route_a.tsx",
68+
"bundle_b.route_b.tsx",
6969

7070
// Bundle C is nested in a pathless route
7171
"_pathless.tsx",
72-
"_pathless.bundle-c.tsx",
73-
"_pathless.bundle-c.route-a.tsx",
74-
"_pathless.bundle-c.route-b.tsx",
72+
"_pathless.bundle_c.tsx",
73+
"_pathless.bundle_c.route_a.tsx",
74+
"_pathless.bundle_c.route_b.tsx",
7575
];
7676

7777
const files = {
@@ -151,16 +151,16 @@ test.describe("Server bundles", () => {
151151
return "root";
152152
}
153153
154-
if (branch.some((route) => route.id === "routes/bundle-a")) {
155-
return "bundle-a";
154+
if (branch.some((route) => route.id === "routes/bundle_a")) {
155+
return "bundle_a";
156156
}
157157
158-
if (branch.some((route) => route.id === "routes/bundle-b")) {
159-
return "bundle-b";
158+
if (branch.some((route) => route.id === "routes/bundle_b")) {
159+
return "bundle_b";
160160
}
161161
162-
if (branch.some((route) => route.id === "routes/_pathless.bundle-c")) {
163-
return "bundle-c";
162+
if (branch.some((route) => route.id === "routes/_pathless.bundle_c")) {
163+
return "bundle_c";
164164
}
165165
166166
throw new Error("No bundle defined for route " + branch[branch.length - 1].id);
@@ -199,19 +199,19 @@ test.describe("Server bundles", () => {
199199
await page.goto(`http://localhost:${port}/`);
200200
await expectRenderedRoutes(page, ["_index.tsx"]);
201201

202-
await page.goto(`http://localhost:${port}/bundle-a`);
202+
await page.goto(`http://localhost:${port}/bundle_a`);
203203
await expectRenderedRoutes(page, [
204-
"bundle-a.tsx",
205-
"bundle-a._index.tsx",
204+
"bundle_a.tsx",
205+
"bundle_a._index.tsx",
206206
]);
207207

208-
await page.goto(`http://localhost:${port}/bundle-b`);
209-
await expectRenderedRoutes(page, ["bundle-b.tsx"]);
208+
await page.goto(`http://localhost:${port}/bundle_b`);
209+
await expectRenderedRoutes(page, ["bundle_b.tsx"]);
210210

211-
await page.goto(`http://localhost:${port}/bundle-c`);
211+
await page.goto(`http://localhost:${port}/bundle_c`);
212212
await expectRenderedRoutes(page, [
213213
"_pathless.tsx",
214-
"_pathless.bundle-c.tsx",
214+
"_pathless.bundle_c.tsx",
215215
]);
216216

217217
expect(pageErrors).toEqual([]);
@@ -243,84 +243,84 @@ test.describe("Server bundles", () => {
243243
await page.goto(`http://localhost:${port}/`);
244244
await expectRenderedRoutes(page, ["_index.tsx"]);
245245

246-
let _404s = ["/bundle-a", "/bundle-b", "/bundle-c"];
246+
let _404s = ["/bundle_a", "/bundle_b", "/bundle_c"];
247247
for (let path of _404s) {
248248
let response = await page.goto(`http://localhost:${port}${path}`);
249249
expect(response?.status()).toBe(404);
250250
}
251251
});
252252

253-
await withBundleServer(cwd, "bundle-a", async (port) => {
254-
await page.goto(`http://localhost:${port}/bundle-a`);
253+
await withBundleServer(cwd, "bundle_a", async (port) => {
254+
await page.goto(`http://localhost:${port}/bundle_a`);
255255
await expectRenderedRoutes(page, [
256-
"bundle-a.tsx",
257-
"bundle-a._index.tsx",
256+
"bundle_a.tsx",
257+
"bundle_a._index.tsx",
258258
]);
259259

260-
await page.goto(`http://localhost:${port}/bundle-a/route-a`);
260+
await page.goto(`http://localhost:${port}/bundle_a/route_a`);
261261
await expectRenderedRoutes(page, [
262-
"bundle-a.tsx",
263-
"bundle-a.route-a.tsx",
262+
"bundle_a.tsx",
263+
"bundle_a.route_a.tsx",
264264
]);
265265

266-
await page.goto(`http://localhost:${port}/bundle-a/route-b`);
266+
await page.goto(`http://localhost:${port}/bundle_a/route_b`);
267267
await expectRenderedRoutes(page, [
268-
"bundle-a.tsx",
269-
"bundle-a.route-b.tsx",
268+
"bundle_a.tsx",
269+
"bundle_a.route_b.tsx",
270270
]);
271271

272-
let _404s = ["/bundle-b", "/bundle-c"];
272+
let _404s = ["/bundle_b", "/bundle_c"];
273273
for (let path of _404s) {
274274
let response = await page.goto(`http://localhost:${port}${path}`);
275275
expect(response?.status()).toBe(404);
276276
}
277277
});
278278

279-
await withBundleServer(cwd, "bundle-b", async (port) => {
280-
await page.goto(`http://localhost:${port}/bundle-b`);
281-
await expectRenderedRoutes(page, ["bundle-b.tsx"]);
279+
await withBundleServer(cwd, "bundle_b", async (port) => {
280+
await page.goto(`http://localhost:${port}/bundle_b`);
281+
await expectRenderedRoutes(page, ["bundle_b.tsx"]);
282282

283-
await page.goto(`http://localhost:${port}/bundle-b/route-a`);
283+
await page.goto(`http://localhost:${port}/bundle_b/route_a`);
284284
await expectRenderedRoutes(page, [
285-
"bundle-b.tsx",
286-
"bundle-b.route-a.tsx",
285+
"bundle_b.tsx",
286+
"bundle_b.route_a.tsx",
287287
]);
288288

289-
await page.goto(`http://localhost:${port}/bundle-b/route-b`);
289+
await page.goto(`http://localhost:${port}/bundle_b/route_b`);
290290
await expectRenderedRoutes(page, [
291-
"bundle-b.tsx",
292-
"bundle-b.route-b.tsx",
291+
"bundle_b.tsx",
292+
"bundle_b.route_b.tsx",
293293
]);
294294

295-
let _404s = ["/bundle-a", "/bundle-c"];
295+
let _404s = ["/bundle_a", "/bundle_c"];
296296
for (let path of _404s) {
297297
let response = await page.goto(`http://localhost:${port}${path}`);
298298
expect(response?.status()).toBe(404);
299299
}
300300
});
301301

302-
await withBundleServer(cwd, "bundle-c", async (port) => {
303-
await page.goto(`http://localhost:${port}/bundle-c`);
302+
await withBundleServer(cwd, "bundle_c", async (port) => {
303+
await page.goto(`http://localhost:${port}/bundle_c`);
304304
await expectRenderedRoutes(page, [
305305
"_pathless.tsx",
306-
"_pathless.bundle-c.tsx",
306+
"_pathless.bundle_c.tsx",
307307
]);
308308

309-
await page.goto(`http://localhost:${port}/bundle-c/route-a`);
309+
await page.goto(`http://localhost:${port}/bundle_c/route_a`);
310310
await expectRenderedRoutes(page, [
311311
"_pathless.tsx",
312-
"_pathless.bundle-c.tsx",
313-
"_pathless.bundle-c.route-a.tsx",
312+
"_pathless.bundle_c.tsx",
313+
"_pathless.bundle_c.route_a.tsx",
314314
]);
315315

316-
await page.goto(`http://localhost:${port}/bundle-c/route-b`);
316+
await page.goto(`http://localhost:${port}/bundle_c/route_b`);
317317
await expectRenderedRoutes(page, [
318318
"_pathless.tsx",
319-
"_pathless.bundle-c.tsx",
320-
"_pathless.bundle-c.route-b.tsx",
319+
"_pathless.bundle_c.tsx",
320+
"_pathless.bundle_c.route_b.tsx",
321321
]);
322322

323-
let _404s = ["/bundle-a", "/bundle-b"];
323+
let _404s = ["/bundle_a", "/bundle_b"];
324324
for (let path of _404s) {
325325
let response = await page.goto(`http://localhost:${port}${path}`);
326326
expect(response?.status()).toBe(404);
@@ -344,9 +344,9 @@ test.describe("Server bundles", () => {
344344
test("Vite manifests", () => {
345345
[
346346
["client"],
347-
["server", "bundle-a"],
348-
["server", "bundle-b"],
349-
["server", "bundle-c"],
347+
["server", "bundle_a"],
348+
["server", "bundle_b"],
349+
["server", "bundle_c"],
350350
["server", "root"],
351351
].forEach((buildPaths) => {
352352
let viteManifestFiles = fs.readdirSync(
@@ -360,33 +360,33 @@ test.describe("Server bundles", () => {
360360
let manifestPath = path.join(cwd, "build", "test-manifest.json");
361361
expect(JSON.parse(fs.readFileSync(manifestPath, "utf8"))).toEqual({
362362
serverBundles: {
363-
"bundle-c": {
364-
id: "bundle-c",
365-
file: "build/server/bundle-c/index.js",
363+
bundle_c: {
364+
id: "bundle_c",
365+
file: "build/server/bundle_c/index.js",
366366
},
367-
"bundle-a": {
368-
id: "bundle-a",
369-
file: "build/server/bundle-a/index.js",
367+
bundle_a: {
368+
id: "bundle_a",
369+
file: "build/server/bundle_a/index.js",
370370
},
371-
"bundle-b": {
372-
id: "bundle-b",
373-
file: "build/server/bundle-b/index.js",
371+
bundle_b: {
372+
id: "bundle_b",
373+
file: "build/server/bundle_b/index.js",
374374
},
375375
root: {
376376
id: "root",
377377
file: "build/server/root/index.js",
378378
},
379379
},
380380
routeIdToServerBundleId: {
381-
"routes/_pathless.bundle-c.route-a": "bundle-c",
382-
"routes/_pathless.bundle-c.route-b": "bundle-c",
383-
"routes/_pathless.bundle-c": "bundle-c",
384-
"routes/bundle-a.route-a": "bundle-a",
385-
"routes/bundle-a.route-b": "bundle-a",
386-
"routes/bundle-b.route-a": "bundle-b",
387-
"routes/bundle-b.route-b": "bundle-b",
388-
"routes/bundle-a._index": "bundle-a",
389-
"routes/bundle-b": "bundle-b",
381+
"routes/_pathless.bundle_c.route_a": "bundle_c",
382+
"routes/_pathless.bundle_c.route_b": "bundle_c",
383+
"routes/_pathless.bundle_c": "bundle_c",
384+
"routes/bundle_a.route_a": "bundle_a",
385+
"routes/bundle_a.route_b": "bundle_a",
386+
"routes/bundle_b.route_a": "bundle_b",
387+
"routes/bundle_b.route_b": "bundle_b",
388+
"routes/bundle_a._index": "bundle_a",
389+
"routes/bundle_b": "bundle_b",
390390
"routes/_index": "root",
391391
},
392392
routes: {
@@ -395,69 +395,69 @@ test.describe("Server bundles", () => {
395395
id: "root",
396396
file: "app/root.tsx",
397397
},
398-
"routes/_pathless.bundle-c.route-a": {
399-
file: "app/routes/_pathless.bundle-c.route-a.tsx",
400-
id: "routes/_pathless.bundle-c.route-a",
401-
path: "route-a",
402-
parentId: "routes/_pathless.bundle-c",
398+
"routes/_pathless.bundle_c.route_a": {
399+
file: "app/routes/_pathless.bundle_c.route_a.tsx",
400+
id: "routes/_pathless.bundle_c.route_a",
401+
path: "route_a",
402+
parentId: "routes/_pathless.bundle_c",
403403
},
404-
"routes/_pathless.bundle-c.route-b": {
405-
file: "app/routes/_pathless.bundle-c.route-b.tsx",
406-
id: "routes/_pathless.bundle-c.route-b",
407-
path: "route-b",
408-
parentId: "routes/_pathless.bundle-c",
404+
"routes/_pathless.bundle_c.route_b": {
405+
file: "app/routes/_pathless.bundle_c.route_b.tsx",
406+
id: "routes/_pathless.bundle_c.route_b",
407+
path: "route_b",
408+
parentId: "routes/_pathless.bundle_c",
409409
},
410-
"routes/_pathless.bundle-c": {
411-
file: "app/routes/_pathless.bundle-c.tsx",
412-
id: "routes/_pathless.bundle-c",
413-
path: "bundle-c",
410+
"routes/_pathless.bundle_c": {
411+
file: "app/routes/_pathless.bundle_c.tsx",
412+
id: "routes/_pathless.bundle_c",
413+
path: "bundle_c",
414414
parentId: "routes/_pathless",
415415
},
416-
"routes/bundle-a.route-a": {
417-
file: "app/routes/bundle-a.route-a.tsx",
418-
id: "routes/bundle-a.route-a",
419-
path: "route-a",
420-
parentId: "routes/bundle-a",
416+
"routes/bundle_a.route_a": {
417+
file: "app/routes/bundle_a.route_a.tsx",
418+
id: "routes/bundle_a.route_a",
419+
path: "route_a",
420+
parentId: "routes/bundle_a",
421421
},
422-
"routes/bundle-a.route-b": {
423-
file: "app/routes/bundle-a.route-b.tsx",
424-
id: "routes/bundle-a.route-b",
425-
path: "route-b",
426-
parentId: "routes/bundle-a",
422+
"routes/bundle_a.route_b": {
423+
file: "app/routes/bundle_a.route_b.tsx",
424+
id: "routes/bundle_a.route_b",
425+
path: "route_b",
426+
parentId: "routes/bundle_a",
427427
},
428-
"routes/bundle-b.route-a": {
429-
file: "app/routes/bundle-b.route-a.tsx",
430-
id: "routes/bundle-b.route-a",
431-
path: "route-a",
432-
parentId: "routes/bundle-b",
428+
"routes/bundle_b.route_a": {
429+
file: "app/routes/bundle_b.route_a.tsx",
430+
id: "routes/bundle_b.route_a",
431+
path: "route_a",
432+
parentId: "routes/bundle_b",
433433
},
434-
"routes/bundle-b.route-b": {
435-
file: "app/routes/bundle-b.route-b.tsx",
436-
id: "routes/bundle-b.route-b",
437-
path: "route-b",
438-
parentId: "routes/bundle-b",
434+
"routes/bundle_b.route_b": {
435+
file: "app/routes/bundle_b.route_b.tsx",
436+
id: "routes/bundle_b.route_b",
437+
path: "route_b",
438+
parentId: "routes/bundle_b",
439439
},
440-
"routes/bundle-a._index": {
441-
file: "app/routes/bundle-a._index.tsx",
442-
id: "routes/bundle-a._index",
440+
"routes/bundle_a._index": {
441+
file: "app/routes/bundle_a._index.tsx",
442+
id: "routes/bundle_a._index",
443443
index: true,
444-
parentId: "routes/bundle-a",
444+
parentId: "routes/bundle_a",
445445
},
446446
"routes/_pathless": {
447447
file: "app/routes/_pathless.tsx",
448448
id: "routes/_pathless",
449449
parentId: "root",
450450
},
451-
"routes/bundle-a": {
452-
file: "app/routes/bundle-a.tsx",
453-
id: "routes/bundle-a",
454-
path: "bundle-a",
451+
"routes/bundle_a": {
452+
file: "app/routes/bundle_a.tsx",
453+
id: "routes/bundle_a",
454+
path: "bundle_a",
455455
parentId: "root",
456456
},
457-
"routes/bundle-b": {
458-
file: "app/routes/bundle-b.tsx",
459-
id: "routes/bundle-b",
460-
path: "bundle-b",
457+
"routes/bundle_b": {
458+
file: "app/routes/bundle_b.tsx",
459+
id: "routes/bundle_b",
460+
path: "bundle_b",
461461
parentId: "root",
462462
},
463463
"routes/_index": {

0 commit comments

Comments
 (0)