@react-router/dev 7.8.1 → 7.8.2-pre.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # `@react-router/dev`
2
2
 
3
+ ## 7.8.2-pre.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: memory leak in default entry.server ([#14200](https://github.com/remix-run/react-router/pull/14200))
8
+ - Updated dependencies:
9
+ - `react-router@7.8.2-pre.0`
10
+ - `@react-router/node@7.8.2-pre.0`
11
+ - `@react-router/serve@7.8.2-pre.0`
12
+
3
13
  ## 7.8.1
4
14
 
5
15
  ### Patch Changes
@@ -718,7 +728,6 @@
718
728
  ```
719
729
 
720
730
  This initial implementation targets type inference for:
721
-
722
731
  - `Params` : Path parameters from your routing config in `routes.ts` including file-based routing
723
732
  - `LoaderData` : Loader data from `loader` and/or `clientLoader` within your route module
724
733
  - `ActionData` : Action data from `action` and/or `clientAction` within your route module
@@ -733,7 +742,6 @@
733
742
  ```
734
743
 
735
744
  Check out our docs for more:
736
-
737
745
  - [_Explanations > Type Safety_](https://reactrouter.com/dev/guides/explanation/type-safety)
738
746
  - [_How-To > Setting up type safety_](https://reactrouter.com/dev/guides/how-to/setting-up-type-safety)
739
747
 
@@ -933,7 +941,6 @@
933
941
  - Vite: Provide `Unstable_ServerBundlesFunction` and `Unstable_VitePluginConfig` types ([#8654](https://github.com/remix-run/remix/pull/8654))
934
942
 
935
943
  - Vite: add `--sourcemapClient` and `--sourcemapServer` flags to `remix vite:build` ([#8613](https://github.com/remix-run/remix/pull/8613))
936
-
937
944
  - `--sourcemapClient`
938
945
 
939
946
  - `--sourcemapClient=inline`
@@ -1270,7 +1277,6 @@
1270
1277
  - Add support for `clientLoader`/`clientAction`/`HydrateFallback` route exports ([RFC](https://github.com/remix-run/remix/discussions/7634)) ([#8173](https://github.com/remix-run/remix/pull/8173))
1271
1278
 
1272
1279
  Remix now supports loaders/actions that run on the client (in addition to, or instead of the loader/action that runs on the server). While we still recommend server loaders/actions for the majority of your data needs in a Remix app - these provide some levers you can pull for more advanced use-cases such as:
1273
-
1274
1280
  - Leveraging a data source local to the browser (i.e., `localStorage`)
1275
1281
  - Managing a client-side cache of server data (like `IndexedDB`)
1276
1282
  - Bypassing the Remix server in a BFF setup and hitting your API directly from the browser
@@ -1674,7 +1680,6 @@
1674
1680
  - Output esbuild metafiles for bundle analysis ([#6772](https://github.com/remix-run/remix/pull/6772))
1675
1681
 
1676
1682
  Written to server build directory (`build/` by default):
1677
-
1678
1683
  - `metafile.css.json`
1679
1684
  - `metafile.js.json` (browser JS)
1680
1685
  - `metafile.server.json` (server JS)
@@ -1772,7 +1777,6 @@
1772
1777
  - built-in tls support ([#6483](https://github.com/remix-run/remix/pull/6483))
1773
1778
 
1774
1779
  New options:
1775
-
1776
1780
  - `--tls-key` / `tlsKey`: TLS key
1777
1781
  - `--tls-cert` / `tlsCert`: TLS Certificate
1778
1782
 
@@ -2043,7 +2047,6 @@
2043
2047
  ```
2044
2048
 
2045
2049
  The dev server will:
2046
-
2047
2050
  - force `NODE_ENV=development` and warn you if it was previously set to something else
2048
2051
  - rebuild your app whenever your Remix app code changes
2049
2052
  - restart your app server whenever rebuilds succeed
package/dist/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * @react-router/dev v7.8.1
3
+ * @react-router/dev v7.8.2-pre.0
4
4
  *
5
5
  * Copyright (c) Remix Software Inc.
6
6
  *
@@ -29,24 +29,38 @@ export default function handleRequest(
29
29
  ? "onAllReady"
30
30
  : "onShellReady";
31
31
 
32
+ // Abort the rendering stream after the `streamTimeout` so it has time to
33
+ // flush down the rejected boundaries
34
+ let timeoutId: ReturnType<typeof setTimeout> | undefined = setTimeout(
35
+ () => abort(),
36
+ streamTimeout + 1000,
37
+ );
38
+
32
39
  const { pipe, abort } = renderToPipeableStream(
33
40
  <ServerRouter context={routerContext} url={request.url} />,
34
41
  {
35
42
  [readyOption]() {
36
43
  shellRendered = true;
37
- const body = new PassThrough();
44
+ const body = new PassThrough({
45
+ final(callback) {
46
+ // Clear the timeout to prevent retaining the closure and memory leak
47
+ clearTimeout(timeoutId);
48
+ timeoutId = undefined;
49
+ callback();
50
+ },
51
+ });
38
52
  const stream = createReadableStreamFromReadable(body);
39
53
 
40
54
  responseHeaders.set("Content-Type", "text/html");
41
55
 
56
+ pipe(body);
57
+
42
58
  resolve(
43
59
  new Response(stream, {
44
60
  headers: responseHeaders,
45
61
  status: responseStatusCode,
46
62
  }),
47
63
  );
48
-
49
- pipe(body);
50
64
  },
51
65
  onShellError(error: unknown) {
52
66
  reject(error);
@@ -62,9 +76,5 @@ export default function handleRequest(
62
76
  },
63
77
  },
64
78
  );
65
-
66
- // Abort the rendering stream after the `streamTimeout` so it has time to
67
- // flush down the rejected boundaries
68
- setTimeout(abort, streamTimeout + 1000);
69
79
  });
70
80
  }
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v7.8.1
2
+ * @react-router/dev v7.8.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/internal.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v7.8.1
2
+ * @react-router/dev v7.8.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1348,19 +1348,39 @@ function invalidDestructureError(name) {
1348
1348
  }
1349
1349
 
1350
1350
  // vite/rsc/virtual-route-modules.ts
1351
+ var SERVER_ONLY_COMPONENT_EXPORTS = ["ServerComponent"];
1351
1352
  var SERVER_ONLY_ROUTE_EXPORTS = [
1353
+ ...SERVER_ONLY_COMPONENT_EXPORTS,
1352
1354
  "loader",
1353
1355
  "action",
1354
1356
  "unstable_middleware",
1355
- "headers",
1356
- "ServerComponent"
1357
+ "headers"
1357
1358
  ];
1358
- var COMPONENT_EXPORTS = [
1359
- "default",
1359
+ var SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS);
1360
+ function isServerOnlyRouteExport(name) {
1361
+ return SERVER_ONLY_ROUTE_EXPORTS_SET.has(name);
1362
+ }
1363
+ var COMMON_COMPONENT_EXPORTS = [
1360
1364
  "ErrorBoundary",
1361
1365
  "HydrateFallback",
1362
1366
  "Layout"
1363
1367
  ];
1368
+ var SERVER_FIRST_COMPONENT_EXPORTS = [
1369
+ ...COMMON_COMPONENT_EXPORTS,
1370
+ ...SERVER_ONLY_COMPONENT_EXPORTS
1371
+ ];
1372
+ var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
1373
+ SERVER_FIRST_COMPONENT_EXPORTS
1374
+ );
1375
+ function isServerFirstComponentExport(name) {
1376
+ return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
1377
+ name
1378
+ );
1379
+ }
1380
+ var CLIENT_COMPONENT_EXPORTS = [
1381
+ ...COMMON_COMPONENT_EXPORTS,
1382
+ "default"
1383
+ ];
1364
1384
  var CLIENT_NON_COMPONENT_EXPORTS = [
1365
1385
  "clientAction",
1366
1386
  "clientLoader",
@@ -1376,25 +1396,43 @@ function isClientNonComponentExport(name) {
1376
1396
  }
1377
1397
  var CLIENT_ROUTE_EXPORTS = [
1378
1398
  ...CLIENT_NON_COMPONENT_EXPORTS,
1379
- ...COMPONENT_EXPORTS
1399
+ ...CLIENT_COMPONENT_EXPORTS
1380
1400
  ];
1381
1401
  var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS);
1382
1402
  function isClientRouteExport(name) {
1383
1403
  return CLIENT_ROUTE_EXPORTS_SET.has(name);
1384
1404
  }
1405
+ var ROUTE_EXPORTS = [
1406
+ ...SERVER_ONLY_ROUTE_EXPORTS,
1407
+ ...CLIENT_ROUTE_EXPORTS
1408
+ ];
1409
+ var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
1410
+ function isRouteExport(name) {
1411
+ return ROUTE_EXPORTS_SET.has(name);
1412
+ }
1413
+ function isCustomRouteExport(name) {
1414
+ return !isRouteExport(name);
1415
+ }
1416
+ function hasReactServerCondition(viteEnvironment) {
1417
+ return viteEnvironment.config.resolve.conditions.includes("react-server");
1418
+ }
1385
1419
  function transformVirtualRouteModules({
1386
1420
  id,
1387
1421
  code,
1388
- viteCommand
1422
+ viteCommand,
1423
+ routeIdByFile,
1424
+ viteEnvironment
1389
1425
  }) {
1390
- if (!id.includes("route-module")) {
1391
- return;
1392
- }
1393
- if (isVirtualRouteModuleId(id)) {
1394
- return createVirtualRouteModuleCode({ id, code, viteCommand });
1426
+ if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
1427
+ return createVirtualRouteModuleCode({
1428
+ id,
1429
+ code,
1430
+ viteCommand,
1431
+ viteEnvironment
1432
+ });
1395
1433
  }
1396
1434
  if (isVirtualServerRouteModuleId(id)) {
1397
- return createVirtualServerRouteModuleCode({ id, code });
1435
+ return createVirtualServerRouteModuleCode({ id, code, viteEnvironment });
1398
1436
  }
1399
1437
  if (isVirtualClientRouteModuleId(id)) {
1400
1438
  return createVirtualClientRouteModuleCode({ id, code, viteCommand });
@@ -1403,22 +1441,44 @@ function transformVirtualRouteModules({
1403
1441
  async function createVirtualRouteModuleCode({
1404
1442
  id,
1405
1443
  code: routeSource,
1406
- viteCommand
1444
+ viteCommand,
1445
+ viteEnvironment
1407
1446
  }) {
1447
+ const isReactServer = hasReactServerCondition(viteEnvironment);
1408
1448
  const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
1409
1449
  const clientModuleId = getVirtualClientModuleId(id);
1410
1450
  const serverModuleId = getVirtualServerModuleId(id);
1411
1451
  let code = "";
1412
1452
  if (isServerFirstRoute) {
1453
+ if (staticExports.some(isServerFirstComponentExport)) {
1454
+ code += `import React from "react";
1455
+ `;
1456
+ }
1413
1457
  for (const staticExport of staticExports) {
1414
1458
  if (isClientNonComponentExport(staticExport)) {
1415
1459
  code += `export { ${staticExport} } from "${clientModuleId}";
1416
1460
  `;
1417
- } else if (staticExport === "ServerComponent") {
1418
- code += `export { ServerComponent as default } from "${serverModuleId}";
1461
+ } else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
1462
+ staticExport !== "Layout") {
1463
+ code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
1464
+ `;
1465
+ code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport}(props) {
1419
1466
  `;
1420
- } else {
1467
+ code += ` return React.createElement(React.Fragment, null,
1468
+ `;
1469
+ code += ` import.meta.viteRsc.loadCss(),
1470
+ `;
1471
+ code += ` React.createElement(${staticExport}WithoutCss, props),
1472
+ `;
1473
+ code += ` );
1474
+ `;
1475
+ code += `}
1476
+ `;
1477
+ } else if (isReactServer && isRouteExport(staticExport)) {
1421
1478
  code += `export { ${staticExport} } from "${serverModuleId}";
1479
+ `;
1480
+ } else if (isCustomRouteExport(staticExport)) {
1481
+ code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
1422
1482
  `;
1423
1483
  }
1424
1484
  }
@@ -1431,8 +1491,11 @@ async function createVirtualRouteModuleCode({
1431
1491
  if (isClientRouteExport(staticExport)) {
1432
1492
  code += `export { ${staticExport} } from "${clientModuleId}";
1433
1493
  `;
1434
- } else {
1494
+ } else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
1435
1495
  code += `export { ${staticExport} } from "${serverModuleId}";
1496
+ `;
1497
+ } else if (isCustomRouteExport(staticExport)) {
1498
+ code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
1436
1499
  `;
1437
1500
  }
1438
1501
  }
@@ -1445,8 +1508,18 @@ async function createVirtualRouteModuleCode({
1445
1508
  }
1446
1509
  function createVirtualServerRouteModuleCode({
1447
1510
  id,
1448
- code: routeSource
1511
+ code: routeSource,
1512
+ viteEnvironment
1449
1513
  }) {
1514
+ if (!hasReactServerCondition(viteEnvironment)) {
1515
+ throw new Error(
1516
+ [
1517
+ "Virtual server route module was loaded outside of the RSC environment.",
1518
+ `Environment Name: ${viteEnvironment.name}`,
1519
+ `Module ID: ${id}`
1520
+ ].join("\n")
1521
+ );
1522
+ }
1450
1523
  const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
1451
1524
  const clientModuleId = getVirtualClientModuleId(id);
1452
1525
  const serverRouteModuleAst = import_parser.parse(routeSource, {
@@ -1474,7 +1547,7 @@ function createVirtualClientRouteModuleCode({
1474
1547
  viteCommand
1475
1548
  }) {
1476
1549
  const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
1477
- const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS, ...COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS;
1550
+ const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS;
1478
1551
  const clientRouteModuleAst = import_parser.parse(routeSource, {
1479
1552
  sourceType: "module"
1480
1553
  });
@@ -1612,9 +1685,21 @@ function reactRouterRSCVitePlugin() {
1612
1685
  jsxDev: viteCommand !== "build"
1613
1686
  },
1614
1687
  environments: {
1615
- client: { build: { outDir: "build/client" } },
1616
- rsc: { build: { outDir: "build/server" } },
1617
- ssr: { build: { outDir: "build/server/__ssr_build" } }
1688
+ client: {
1689
+ build: {
1690
+ outDir: (0, import_pathe5.join)(config.buildDirectory, "client")
1691
+ }
1692
+ },
1693
+ rsc: {
1694
+ build: {
1695
+ outDir: (0, import_pathe5.join)(config.buildDirectory, "server")
1696
+ }
1697
+ },
1698
+ ssr: {
1699
+ build: {
1700
+ outDir: (0, import_pathe5.join)(config.buildDirectory, "server/__ssr_build")
1701
+ }
1702
+ }
1618
1703
  },
1619
1704
  build: {
1620
1705
  rollupOptions: {
@@ -1686,7 +1771,14 @@ function reactRouterRSCVitePlugin() {
1686
1771
  {
1687
1772
  name: "react-router/rsc/virtual-route-modules",
1688
1773
  transform(code, id) {
1689
- return transformVirtualRouteModules({ code, id, viteCommand });
1774
+ if (!routeIdByFile) return;
1775
+ return transformVirtualRouteModules({
1776
+ code,
1777
+ id,
1778
+ viteCommand,
1779
+ routeIdByFile,
1780
+ viteEnvironment: this.environment
1781
+ });
1690
1782
  }
1691
1783
  },
1692
1784
  {
@@ -1747,8 +1839,8 @@ function reactRouterRSCVitePlugin() {
1747
1839
  const isJSX = filepath.endsWith("x");
1748
1840
  const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
1749
1841
  if (!useFastRefresh) return;
1750
- const routeId = routeIdByFile?.get(filepath);
1751
- if (routeId !== void 0) {
1842
+ if (isVirtualClientRouteModuleId(id)) {
1843
+ const routeId = routeIdByFile?.get(filepath);
1752
1844
  return { code: addRefreshWrapper({ routeId, code, id }) };
1753
1845
  }
1754
1846
  const result = await babel.transformAsync(code, {
package/dist/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v7.8.1
2
+ * @react-router/dev v7.8.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v7.8.1
2
+ * @react-router/dev v7.8.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v7.8.1
2
+ * @react-router/dev v7.8.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-router/dev",
3
- "version": "7.8.1",
3
+ "version": "7.8.2-pre.0",
4
4
  "description": "Dev tools and CLI for React Router",
5
5
  "homepage": "https://reactrouter.com",
6
6
  "bugs": {
@@ -91,7 +91,7 @@
91
91
  "tinyglobby": "^0.2.14",
92
92
  "valibot": "^0.41.0",
93
93
  "vite-node": "^3.2.2",
94
- "@react-router/node": "7.8.1"
94
+ "@react-router/node": "7.8.2-pre.0"
95
95
  },
96
96
  "devDependencies": {
97
97
  "@types/babel__core": "^7.20.5",
@@ -114,15 +114,15 @@
114
114
  "vite": "^6.1.0",
115
115
  "wireit": "0.14.9",
116
116
  "wrangler": "^4.23.0",
117
- "@react-router/serve": "7.8.1",
118
- "react-router": "^7.8.1"
117
+ "@react-router/serve": "7.8.2-pre.0",
118
+ "react-router": "^7.8.2-pre.0"
119
119
  },
120
120
  "peerDependencies": {
121
121
  "typescript": "^5.1.0",
122
122
  "vite": "^5.1.0 || ^6.0.0 || ^7.0.0",
123
123
  "wrangler": "^3.28.2 || ^4.0.0",
124
- "@react-router/serve": "^7.8.1",
125
- "react-router": "^7.8.1"
124
+ "@react-router/serve": "^7.8.2-pre.0",
125
+ "react-router": "^7.8.2-pre.0"
126
126
  },
127
127
  "peerDependenciesMeta": {
128
128
  "@react-router/serve": {