@react-router/dev 0.0.0-experimental-9ea41ead4 → 0.0.0-experimental-beaa4f52a

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/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9ea41ead4
2
+ * @react-router/dev v0.0.0-experimental-beaa4f52a
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -443,8 +443,7 @@ async function resolveConfig({
443
443
  );
444
444
  }
445
445
  let future = {
446
- unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
447
- unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false
446
+ unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false
448
447
  };
449
448
  let reactRouterConfig = deepFreeze({
450
449
  appDirectory,
@@ -693,6 +692,8 @@ function generate(ctx, route) {
693
692
  export type HeadersArgs = T.HeadersArgs
694
693
  export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
695
694
 
695
+ export type MiddlewareArgs = T.CreateServerMiddlewareArgs<Info>
696
+ export type ClientMiddlewareArgs = T.CreateClientMiddlewareArgs<Info>
696
697
  export type LoaderArgs = T.CreateServerLoaderArgs<Info>
697
698
  export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
698
699
  export type ActionArgs = T.CreateServerActionArgs<Info>
@@ -1160,607 +1161,6 @@ function invalidDestructureError(name) {
1160
1161
  return new Error(`Cannot remove destructured export "${name}"`);
1161
1162
  }
1162
1163
 
1163
- // vite/cache.ts
1164
- function getOrSetFromCache(cache, key, version, getValue) {
1165
- if (!cache) {
1166
- return getValue();
1167
- }
1168
- let entry = cache.get(key);
1169
- if (entry?.version === version) {
1170
- return entry.value;
1171
- }
1172
- let value = getValue();
1173
- let newEntry = { value, version };
1174
- cache.set(key, newEntry);
1175
- return value;
1176
- }
1177
-
1178
- // vite/route-chunks.ts
1179
- function codeToAst(code, cache, cacheKey) {
1180
- return structuredClone(
1181
- getOrSetFromCache(
1182
- cache,
1183
- `${cacheKey}::codeToAst`,
1184
- code,
1185
- () => (0, import_parser.parse)(code, { sourceType: "module" })
1186
- )
1187
- );
1188
- }
1189
- function assertNodePath(path7) {
1190
- invariant(
1191
- path7 && !Array.isArray(path7),
1192
- `Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
1193
- );
1194
- }
1195
- function assertNodePathIsStatement(path7) {
1196
- invariant(
1197
- path7 && !Array.isArray(path7) && t.isStatement(path7.node),
1198
- `Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1199
- );
1200
- }
1201
- function assertNodePathIsVariableDeclarator(path7) {
1202
- invariant(
1203
- path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
1204
- `Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1205
- );
1206
- }
1207
- function assertNodePathIsPattern(path7) {
1208
- invariant(
1209
- path7 && !Array.isArray(path7) && t.isPattern(path7.node),
1210
- `Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1211
- );
1212
- }
1213
- function getExportDependencies(code, cache, cacheKey) {
1214
- return getOrSetFromCache(
1215
- cache,
1216
- `${cacheKey}::getExportDependencies`,
1217
- code,
1218
- () => {
1219
- let exportDependencies = /* @__PURE__ */ new Map();
1220
- let ast = codeToAst(code, cache, cacheKey);
1221
- function handleExport(exportName, exportPath, identifiersPath = exportPath) {
1222
- let identifiers = getDependentIdentifiersForPath(identifiersPath);
1223
- let topLevelStatements = /* @__PURE__ */ new Set([
1224
- exportPath.node,
1225
- ...getTopLevelStatementsForPaths(identifiers)
1226
- ]);
1227
- let topLevelNonModuleStatements = new Set(
1228
- Array.from(topLevelStatements).filter(
1229
- (statement) => !t.isImportDeclaration(statement) && !t.isExportDeclaration(statement)
1230
- )
1231
- );
1232
- let importedIdentifierNames = /* @__PURE__ */ new Set();
1233
- for (let identifier of identifiers) {
1234
- if (identifier.parentPath.parentPath?.isImportDeclaration()) {
1235
- importedIdentifierNames.add(identifier.node.name);
1236
- }
1237
- }
1238
- let exportedVariableDeclarators = /* @__PURE__ */ new Set();
1239
- for (let identifier of identifiers) {
1240
- if (identifier.parentPath.isVariableDeclarator() && identifier.parentPath.parentPath.parentPath?.isExportNamedDeclaration()) {
1241
- exportedVariableDeclarators.add(identifier.parentPath.node);
1242
- continue;
1243
- }
1244
- let isWithinExportNamedDeclaration = Boolean(
1245
- identifier.findParent((path7) => path7.isExportNamedDeclaration())
1246
- );
1247
- if (isWithinExportNamedDeclaration) {
1248
- let currentPath = identifier;
1249
- while (currentPath) {
1250
- if (
1251
- // Check the identifier is within a variable declaration, and if
1252
- // so, ensure we're on the left-hand side of the expression
1253
- // since these identifiers are what make up the export names,
1254
- // e.g. export const { foo } = { foo: bar }; should pick up
1255
- // `foo` but not `bar`.
1256
- currentPath.parentPath?.isVariableDeclarator() && currentPath.parentKey === "id"
1257
- ) {
1258
- exportedVariableDeclarators.add(currentPath.parentPath.node);
1259
- break;
1260
- }
1261
- currentPath = currentPath.parentPath;
1262
- }
1263
- }
1264
- }
1265
- let dependencies = {
1266
- topLevelStatements,
1267
- topLevelNonModuleStatements,
1268
- importedIdentifierNames,
1269
- exportedVariableDeclarators
1270
- };
1271
- exportDependencies.set(exportName, dependencies);
1272
- }
1273
- traverse(ast, {
1274
- ExportDeclaration(exportPath) {
1275
- let { node } = exportPath;
1276
- if (t.isExportAllDeclaration(node)) {
1277
- return;
1278
- }
1279
- if (t.isExportDefaultDeclaration(node)) {
1280
- handleExport("default", exportPath);
1281
- return;
1282
- }
1283
- let { declaration } = node;
1284
- if (t.isVariableDeclaration(declaration)) {
1285
- let { declarations } = declaration;
1286
- for (let i = 0; i < declarations.length; i++) {
1287
- let declarator = declarations[i];
1288
- if (t.isIdentifier(declarator.id)) {
1289
- let declaratorPath = exportPath.get(
1290
- `declaration.declarations.${i}`
1291
- );
1292
- assertNodePathIsVariableDeclarator(declaratorPath);
1293
- handleExport(declarator.id.name, exportPath, declaratorPath);
1294
- continue;
1295
- }
1296
- if (t.isPattern(declarator.id)) {
1297
- let exportedPatternPath = exportPath.get(
1298
- `declaration.declarations.${i}.id`
1299
- );
1300
- assertNodePathIsPattern(exportedPatternPath);
1301
- let identifiers = getIdentifiersForPatternPath(exportedPatternPath);
1302
- for (let identifier of identifiers) {
1303
- handleExport(identifier.node.name, exportPath, identifier);
1304
- }
1305
- }
1306
- }
1307
- return;
1308
- }
1309
- if (t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) {
1310
- invariant(
1311
- declaration.id,
1312
- "Expected exported function or class declaration to have a name when not the default export"
1313
- );
1314
- handleExport(declaration.id.name, exportPath);
1315
- return;
1316
- }
1317
- if (t.isExportNamedDeclaration(node)) {
1318
- for (let specifier of node.specifiers) {
1319
- if (t.isIdentifier(specifier.exported)) {
1320
- let name = specifier.exported.name;
1321
- let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
1322
- invariant(
1323
- specifierPath,
1324
- `Expected to find specifier path for ${name}`
1325
- );
1326
- handleExport(name, exportPath, specifierPath);
1327
- }
1328
- }
1329
- return;
1330
- }
1331
- throw new Error(`Unknown export node type: ${node.type}`);
1332
- }
1333
- });
1334
- return exportDependencies;
1335
- }
1336
- );
1337
- }
1338
- function getDependentIdentifiersForPath(path7, state) {
1339
- let { visited, identifiers } = state ?? {
1340
- visited: /* @__PURE__ */ new Set(),
1341
- identifiers: /* @__PURE__ */ new Set()
1342
- };
1343
- if (visited.has(path7)) {
1344
- return identifiers;
1345
- }
1346
- visited.add(path7);
1347
- path7.traverse({
1348
- Identifier(path8) {
1349
- if (identifiers.has(path8)) {
1350
- return;
1351
- }
1352
- identifiers.add(path8);
1353
- let binding = path8.scope.getBinding(path8.node.name);
1354
- if (!binding) {
1355
- return;
1356
- }
1357
- getDependentIdentifiersForPath(binding.path, { visited, identifiers });
1358
- for (let reference of binding.referencePaths) {
1359
- if (reference.isExportNamedDeclaration()) {
1360
- continue;
1361
- }
1362
- getDependentIdentifiersForPath(reference, {
1363
- visited,
1364
- identifiers
1365
- });
1366
- }
1367
- for (let constantViolation of binding.constantViolations) {
1368
- getDependentIdentifiersForPath(constantViolation, {
1369
- visited,
1370
- identifiers
1371
- });
1372
- }
1373
- }
1374
- });
1375
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1376
- let withinImportStatement = topLevelStatement.isImportDeclaration();
1377
- let withinExportStatement = topLevelStatement.isExportDeclaration();
1378
- if (!withinImportStatement && !withinExportStatement) {
1379
- getDependentIdentifiersForPath(topLevelStatement, {
1380
- visited,
1381
- identifiers
1382
- });
1383
- }
1384
- if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
1385
- t.isPattern(path7.parentPath.parentPath?.node))) {
1386
- let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
1387
- assertNodePath(variableDeclarator);
1388
- getDependentIdentifiersForPath(variableDeclarator, {
1389
- visited,
1390
- identifiers
1391
- });
1392
- }
1393
- return identifiers;
1394
- }
1395
- function getTopLevelStatementPathForPath(path7) {
1396
- let ancestry = path7.getAncestry();
1397
- let topLevelStatement = ancestry[ancestry.length - 2];
1398
- assertNodePathIsStatement(topLevelStatement);
1399
- return topLevelStatement;
1400
- }
1401
- function getTopLevelStatementsForPaths(paths) {
1402
- let topLevelStatements = /* @__PURE__ */ new Set();
1403
- for (let path7 of paths) {
1404
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1405
- topLevelStatements.add(topLevelStatement.node);
1406
- }
1407
- return topLevelStatements;
1408
- }
1409
- function getIdentifiersForPatternPath(patternPath, identifiers = /* @__PURE__ */ new Set()) {
1410
- function walk(currentPath) {
1411
- if (currentPath.isIdentifier()) {
1412
- identifiers.add(currentPath);
1413
- return;
1414
- }
1415
- if (currentPath.isObjectPattern()) {
1416
- let { properties } = currentPath.node;
1417
- for (let i = 0; i < properties.length; i++) {
1418
- const property = properties[i];
1419
- if (t.isObjectProperty(property)) {
1420
- let valuePath = currentPath.get(`properties.${i}.value`);
1421
- assertNodePath(valuePath);
1422
- walk(valuePath);
1423
- } else if (t.isRestElement(property)) {
1424
- let argumentPath = currentPath.get(`properties.${i}.argument`);
1425
- assertNodePath(argumentPath);
1426
- walk(argumentPath);
1427
- }
1428
- }
1429
- } else if (currentPath.isArrayPattern()) {
1430
- let { elements } = currentPath.node;
1431
- for (let i = 0; i < elements.length; i++) {
1432
- const element = elements[i];
1433
- if (element) {
1434
- let elementPath = currentPath.get(`elements.${i}`);
1435
- assertNodePath(elementPath);
1436
- walk(elementPath);
1437
- }
1438
- }
1439
- } else if (currentPath.isRestElement()) {
1440
- let argumentPath = currentPath.get("argument");
1441
- assertNodePath(argumentPath);
1442
- walk(argumentPath);
1443
- }
1444
- }
1445
- walk(patternPath);
1446
- return identifiers;
1447
- }
1448
- var getExportedName = (exported) => {
1449
- return t.isIdentifier(exported) ? exported.name : exported.value;
1450
- };
1451
- function setsIntersect(set1, set2) {
1452
- let smallerSet = set1;
1453
- let largerSet = set2;
1454
- if (set1.size > set2.size) {
1455
- smallerSet = set2;
1456
- largerSet = set1;
1457
- }
1458
- for (let element of smallerSet) {
1459
- if (largerSet.has(element)) {
1460
- return true;
1461
- }
1462
- }
1463
- return false;
1464
- }
1465
- function hasChunkableExport(code, exportName, cache, cacheKey) {
1466
- return getOrSetFromCache(
1467
- cache,
1468
- `${cacheKey}::hasChunkableExport::${exportName}`,
1469
- code,
1470
- () => {
1471
- let exportDependencies = getExportDependencies(code, cache, cacheKey);
1472
- let dependencies = exportDependencies.get(exportName);
1473
- if (!dependencies) {
1474
- return false;
1475
- }
1476
- for (let [currentExportName, currentDependencies] of exportDependencies) {
1477
- if (currentExportName === exportName) {
1478
- continue;
1479
- }
1480
- if (setsIntersect(
1481
- currentDependencies.topLevelNonModuleStatements,
1482
- dependencies.topLevelNonModuleStatements
1483
- )) {
1484
- return false;
1485
- }
1486
- }
1487
- if (dependencies.exportedVariableDeclarators.size > 1) {
1488
- return false;
1489
- }
1490
- if (dependencies.exportedVariableDeclarators.size > 0) {
1491
- for (let [
1492
- currentExportName,
1493
- currentDependencies
1494
- ] of exportDependencies) {
1495
- if (currentExportName === exportName) {
1496
- continue;
1497
- }
1498
- if (setsIntersect(
1499
- currentDependencies.exportedVariableDeclarators,
1500
- dependencies.exportedVariableDeclarators
1501
- )) {
1502
- return false;
1503
- }
1504
- }
1505
- }
1506
- return true;
1507
- }
1508
- );
1509
- }
1510
- function getChunkedExport(code, exportName, generateOptions = {}, cache, cacheKey) {
1511
- return getOrSetFromCache(
1512
- cache,
1513
- `${cacheKey}::getChunkedExport::${exportName}::${JSON.stringify(
1514
- generateOptions
1515
- )}`,
1516
- code,
1517
- () => {
1518
- if (!hasChunkableExport(code, exportName, cache, cacheKey)) {
1519
- return void 0;
1520
- }
1521
- let exportDependencies = getExportDependencies(code, cache, cacheKey);
1522
- let dependencies = exportDependencies.get(exportName);
1523
- invariant(dependencies, "Expected export to have dependencies");
1524
- let topLevelStatementsArray = Array.from(dependencies.topLevelStatements);
1525
- let exportedVariableDeclaratorsArray = Array.from(
1526
- dependencies.exportedVariableDeclarators
1527
- );
1528
- let ast = codeToAst(code, cache, cacheKey);
1529
- ast.program.body = ast.program.body.filter(
1530
- (node) => topLevelStatementsArray.some(
1531
- (statement) => t.isNodesEquivalent(node, statement)
1532
- )
1533
- ).map((node) => {
1534
- if (!t.isImportDeclaration(node)) {
1535
- return node;
1536
- }
1537
- if (dependencies.importedIdentifierNames.size === 0) {
1538
- return null;
1539
- }
1540
- node.specifiers = node.specifiers.filter(
1541
- (specifier) => dependencies.importedIdentifierNames.has(specifier.local.name)
1542
- );
1543
- invariant(
1544
- node.specifiers.length > 0,
1545
- "Expected import statement to have used specifiers"
1546
- );
1547
- return node;
1548
- }).map((node) => {
1549
- if (!t.isExportDeclaration(node)) {
1550
- return node;
1551
- }
1552
- if (t.isExportAllDeclaration(node)) {
1553
- return null;
1554
- }
1555
- if (t.isExportDefaultDeclaration(node)) {
1556
- return exportName === "default" ? node : null;
1557
- }
1558
- let { declaration } = node;
1559
- if (t.isVariableDeclaration(declaration)) {
1560
- declaration.declarations = declaration.declarations.filter(
1561
- (node2) => exportedVariableDeclaratorsArray.some(
1562
- (declarator) => t.isNodesEquivalent(node2, declarator)
1563
- )
1564
- );
1565
- if (declaration.declarations.length === 0) {
1566
- return null;
1567
- }
1568
- return node;
1569
- }
1570
- if (t.isFunctionDeclaration(node.declaration) || t.isClassDeclaration(node.declaration)) {
1571
- return node.declaration.id?.name === exportName ? node : null;
1572
- }
1573
- if (t.isExportNamedDeclaration(node)) {
1574
- if (node.specifiers.length === 0) {
1575
- return null;
1576
- }
1577
- node.specifiers = node.specifiers.filter(
1578
- (specifier) => getExportedName(specifier.exported) === exportName
1579
- );
1580
- if (node.specifiers.length === 0) {
1581
- return null;
1582
- }
1583
- return node;
1584
- }
1585
- throw new Error(`Unknown export node type: ${node.type}`);
1586
- }).filter((node) => node !== null);
1587
- return generate2(ast, generateOptions);
1588
- }
1589
- );
1590
- }
1591
- function omitChunkedExports(code, exportNames, generateOptions = {}, cache, cacheKey) {
1592
- return getOrSetFromCache(
1593
- cache,
1594
- `${cacheKey}::omitChunkedExports::${exportNames.join(
1595
- ","
1596
- )}::${JSON.stringify(generateOptions)}`,
1597
- code,
1598
- () => {
1599
- const isChunkable = (exportName) => hasChunkableExport(code, exportName, cache, cacheKey);
1600
- const isOmitted = (exportName) => exportNames.includes(exportName) && isChunkable(exportName);
1601
- const isRetained = (exportName) => !isOmitted(exportName);
1602
- let exportDependencies = getExportDependencies(code, cache, cacheKey);
1603
- let allExportNames = Array.from(exportDependencies.keys());
1604
- let omittedExportNames = allExportNames.filter(isOmitted);
1605
- let retainedExportNames = allExportNames.filter(isRetained);
1606
- let omittedStatements = /* @__PURE__ */ new Set();
1607
- let omittedExportedVariableDeclarators = /* @__PURE__ */ new Set();
1608
- for (let omittedExportName of omittedExportNames) {
1609
- let dependencies = exportDependencies.get(omittedExportName);
1610
- invariant(
1611
- dependencies,
1612
- `Expected dependencies for ${omittedExportName}`
1613
- );
1614
- for (let statement of dependencies.topLevelNonModuleStatements) {
1615
- omittedStatements.add(statement);
1616
- }
1617
- for (let declarator of dependencies.exportedVariableDeclarators) {
1618
- omittedExportedVariableDeclarators.add(declarator);
1619
- }
1620
- }
1621
- let ast = codeToAst(code, cache, cacheKey);
1622
- let omittedStatementsArray = Array.from(omittedStatements);
1623
- let omittedExportedVariableDeclaratorsArray = Array.from(
1624
- omittedExportedVariableDeclarators
1625
- );
1626
- ast.program.body = ast.program.body.filter(
1627
- (node) => omittedStatementsArray.every(
1628
- (statement) => !t.isNodesEquivalent(node, statement)
1629
- )
1630
- ).map((node) => {
1631
- if (!t.isImportDeclaration(node)) {
1632
- return node;
1633
- }
1634
- if (node.specifiers.length === 0) {
1635
- return node;
1636
- }
1637
- node.specifiers = node.specifiers.filter((specifier) => {
1638
- let importedName = specifier.local.name;
1639
- for (let retainedExportName of retainedExportNames) {
1640
- let dependencies = exportDependencies.get(retainedExportName);
1641
- if (dependencies?.importedIdentifierNames?.has(importedName)) {
1642
- return true;
1643
- }
1644
- }
1645
- for (let omittedExportName of omittedExportNames) {
1646
- let dependencies = exportDependencies.get(omittedExportName);
1647
- if (dependencies?.importedIdentifierNames?.has(importedName)) {
1648
- return false;
1649
- }
1650
- }
1651
- return true;
1652
- });
1653
- if (node.specifiers.length === 0) {
1654
- return null;
1655
- }
1656
- return node;
1657
- }).map((node) => {
1658
- if (!t.isExportDeclaration(node)) {
1659
- return node;
1660
- }
1661
- if (t.isExportAllDeclaration(node)) {
1662
- return node;
1663
- }
1664
- if (t.isExportDefaultDeclaration(node)) {
1665
- return isOmitted("default") ? null : node;
1666
- }
1667
- if (t.isVariableDeclaration(node.declaration)) {
1668
- node.declaration.declarations = node.declaration.declarations.filter(
1669
- (node2) => omittedExportedVariableDeclaratorsArray.every(
1670
- (declarator) => !t.isNodesEquivalent(node2, declarator)
1671
- )
1672
- );
1673
- if (node.declaration.declarations.length === 0) {
1674
- return null;
1675
- }
1676
- return node;
1677
- }
1678
- if (t.isFunctionDeclaration(node.declaration) || t.isClassDeclaration(node.declaration)) {
1679
- invariant(
1680
- node.declaration.id,
1681
- "Expected exported function or class declaration to have a name when not the default export"
1682
- );
1683
- return isOmitted(node.declaration.id.name) ? null : node;
1684
- }
1685
- if (t.isExportNamedDeclaration(node)) {
1686
- if (node.specifiers.length === 0) {
1687
- return node;
1688
- }
1689
- node.specifiers = node.specifiers.filter((specifier) => {
1690
- const exportedName = getExportedName(specifier.exported);
1691
- return !isOmitted(exportedName);
1692
- });
1693
- if (node.specifiers.length === 0) {
1694
- return null;
1695
- }
1696
- return node;
1697
- }
1698
- throw new Error(`Unknown node type: ${node.type}`);
1699
- }).filter((node) => node !== null);
1700
- if (ast.program.body.length === 0) {
1701
- return void 0;
1702
- }
1703
- return generate2(ast, generateOptions);
1704
- }
1705
- );
1706
- }
1707
- function detectRouteChunks(code, cache, cacheKey) {
1708
- const hasRouteChunkByExportName = Object.fromEntries(
1709
- routeChunkExportNames.map((exportName) => [
1710
- exportName,
1711
- hasChunkableExport(code, exportName, cache, cacheKey)
1712
- ])
1713
- );
1714
- const chunkedExports = Object.entries(hasRouteChunkByExportName).filter(([, isChunked]) => isChunked).map(([exportName]) => exportName);
1715
- const hasRouteChunks = chunkedExports.length > 0;
1716
- return {
1717
- hasRouteChunks,
1718
- hasRouteChunkByExportName,
1719
- chunkedExports
1720
- };
1721
- }
1722
- var routeChunkExportNames = [
1723
- "clientAction",
1724
- "clientLoader",
1725
- "HydrateFallback"
1726
- ];
1727
- var mainChunkName = "main";
1728
- var routeChunkNames = ["main", ...routeChunkExportNames];
1729
- function getRouteChunkCode(code, chunkName, cache, cacheKey) {
1730
- if (chunkName === mainChunkName) {
1731
- return omitChunkedExports(code, routeChunkExportNames, {}, cache, cacheKey);
1732
- }
1733
- return getChunkedExport(code, chunkName, {}, cache, cacheKey);
1734
- }
1735
- var routeChunkQueryStringPrefix = "?route-chunk=";
1736
- var routeChunkQueryStrings = {
1737
- main: `${routeChunkQueryStringPrefix}main`,
1738
- clientAction: `${routeChunkQueryStringPrefix}clientAction`,
1739
- clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
1740
- HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
1741
- };
1742
- function getRouteChunkModuleId(filePath, chunkName) {
1743
- return `${filePath}${routeChunkQueryStrings[chunkName]}`;
1744
- }
1745
- function isRouteChunkModuleId(id) {
1746
- return Object.values(routeChunkQueryStrings).some(
1747
- (queryString) => id.endsWith(queryString)
1748
- );
1749
- }
1750
- function isRouteChunkName(name) {
1751
- return name === mainChunkName || routeChunkExportNames.includes(name);
1752
- }
1753
- function getRouteChunkNameFromModuleId(id) {
1754
- if (!isRouteChunkModuleId(id)) {
1755
- return null;
1756
- }
1757
- let chunkName = id.split(routeChunkQueryStringPrefix)[1].split("&")[0];
1758
- if (!isRouteChunkName(chunkName)) {
1759
- return null;
1760
- }
1761
- return chunkName;
1762
- }
1763
-
1764
1164
  // vite/with-props.ts
1765
1165
  var import_dedent2 = __toESM(require("dedent"));
1766
1166
  var vmod = create("with-props");
@@ -1886,10 +1286,11 @@ function toFunctionExpression(decl) {
1886
1286
  }
1887
1287
 
1888
1288
  // vite/plugin.ts
1889
- var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
1289
+ var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "middleware", "headers"];
1890
1290
  var CLIENT_ROUTE_EXPORTS = [
1891
1291
  "clientAction",
1892
1292
  "clientLoader",
1293
+ "clientMiddleware",
1893
1294
  "default",
1894
1295
  "ErrorBoundary",
1895
1296
  "handle",
@@ -1900,20 +1301,8 @@ var CLIENT_ROUTE_EXPORTS = [
1900
1301
  "shouldRevalidate"
1901
1302
  ];
1902
1303
  var BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
1903
- var isRouteEntryModuleId = (id) => {
1904
- return id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING);
1905
- };
1906
- var isRouteVirtualModule = (id) => {
1907
- return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
1908
- };
1909
1304
  var virtualHmrRuntime = create("hmr-runtime");
1910
1305
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
1911
- var normalizeRelativeFilePath = (file, reactRouterConfig) => {
1912
- let vite2 = getVite();
1913
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
1914
- let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
1915
- return vite2.normalizePath(relativePath).split("?")[0];
1916
- };
1917
1306
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
1918
1307
  let vite2 = getVite();
1919
1308
  let file = route.file;
@@ -1942,35 +1331,23 @@ var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
1942
1331
  let rootRelativeFilePath = vite2.normalizePath(
1943
1332
  path6.relative(ctx.rootDirectory, absoluteFilePath)
1944
1333
  );
1945
- let entryChunk = viteManifest[rootRelativeFilePath];
1334
+ let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
1946
1335
  if (!entryChunk) {
1947
- return void 0;
1336
+ let knownManifestKeys = Object.keys(viteManifest).map((key) => '"' + key + '"').join(", ");
1337
+ throw new Error(
1338
+ `No manifest entry found for "${rootRelativeFilePath}". Known manifest keys: ${knownManifestKeys}`
1339
+ );
1948
1340
  }
1949
1341
  return entryChunk;
1950
1342
  };
1951
- var getPublicModulePathForEntry = (ctx, viteManifest, entryFilePath) => {
1952
- let entryChunk = resolveChunk(ctx, viteManifest, entryFilePath);
1953
- return entryChunk ? `${ctx.publicPath}${entryChunk.file}` : void 0;
1954
- };
1955
1343
  var getReactRouterManifestBuildAssets = (ctx, viteManifest, entryFilePath, prependedAssetFilePaths = []) => {
1956
1344
  let entryChunk = resolveChunk(ctx, viteManifest, entryFilePath);
1957
- invariant(entryChunk, "Chunk not found");
1958
- let prependedAssetChunks = prependedAssetFilePaths.map((filePath) => {
1959
- let chunk = resolveChunk(ctx, viteManifest, filePath);
1960
- invariant(chunk, "Chunk not found");
1961
- return chunk;
1962
- });
1963
- let routeModuleChunks = routeChunkNames.map(
1964
- (routeChunkName) => resolveChunk(
1965
- ctx,
1966
- viteManifest,
1967
- getRouteChunkModuleId(entryFilePath.split("?")[0], routeChunkName)
1968
- )
1969
- ).filter(isNonNullable);
1345
+ let prependedAssetChunks = prependedAssetFilePaths.map(
1346
+ (filePath) => resolveChunk(ctx, viteManifest, filePath)
1347
+ );
1970
1348
  let chunks = resolveDependantChunks(viteManifest, [
1971
1349
  ...prependedAssetChunks,
1972
- entryChunk,
1973
- ...routeModuleChunks
1350
+ entryChunk
1974
1351
  ]);
1975
1352
  return {
1976
1353
  module: `${ctx.publicPath}${entryChunk.file}`,
@@ -2007,10 +1384,6 @@ var writeFileSafe = async (file, contents) => {
2007
1384
  await fse.ensureDir(path6.dirname(file));
2008
1385
  await fse.writeFile(file, contents);
2009
1386
  };
2010
- var getExportNames = (code) => {
2011
- let [, exportSpecifiers] = (0, import_es_module_lexer.parse)(code);
2012
- return exportSpecifiers.map(({ n: name }) => name);
2013
- };
2014
1387
  var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
2015
1388
  let entries = await Promise.all(
2016
1389
  Object.entries(ctx.reactRouterConfig.routes).map(async ([key, route]) => {
@@ -2024,7 +1397,7 @@ var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
2024
1397
  );
2025
1398
  return Object.fromEntries(entries);
2026
1399
  };
2027
- var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile) => {
1400
+ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteFile) => {
2028
1401
  if (!viteChildCompiler) {
2029
1402
  throw new Error("Vite child compiler not found");
2030
1403
  }
@@ -2044,19 +1417,9 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
2044
1417
  moduleGraph.ensureEntryFromUrl(url2, ssr)
2045
1418
  ]);
2046
1419
  let transformed = await pluginContainer.transform(code, id, { ssr });
2047
- return transformed.code;
2048
- };
2049
- var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteFile) => {
2050
- if (!viteChildCompiler) {
2051
- throw new Error("Vite child compiler not found");
2052
- }
2053
- let code = await compileRouteFile(
2054
- viteChildCompiler,
2055
- ctx,
2056
- routeFile,
2057
- readRouteFile
2058
- );
2059
- return getExportNames(code);
1420
+ let [, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
1421
+ let exportNames = exports2.map((e) => e.n);
1422
+ return exportNames;
2060
1423
  };
2061
1424
  var getServerBundleBuildConfig = (viteUserConfig) => {
2062
1425
  if (!("__reactRouterServerBundleBuildConfig" in viteUserConfig) || !viteUserConfig.__reactRouterServerBundleBuildConfig) {
@@ -2087,7 +1450,6 @@ var reactRouterVitePlugin = () => {
2087
1450
  let viteConfig;
2088
1451
  let cssModulesManifest = {};
2089
1452
  let viteChildCompiler = null;
2090
- let cache = /* @__PURE__ */ new Map();
2091
1453
  let reactRouterConfigLoader;
2092
1454
  let typegenWatcherPromise;
2093
1455
  let logger;
@@ -2227,31 +1589,13 @@ var reactRouterVitePlugin = () => {
2227
1589
  viteChildCompiler,
2228
1590
  ctx
2229
1591
  );
2230
- let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2231
1592
  for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
2232
- let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
1593
+ let routeFilePath = path6.join(
1594
+ ctx.reactRouterConfig.appDirectory,
1595
+ route.file
1596
+ );
2233
1597
  let sourceExports = routeManifestExports[key];
2234
1598
  let isRootRoute = route.parentId === void 0;
2235
- let hasClientAction = sourceExports.includes("clientAction");
2236
- let hasClientLoader = sourceExports.includes("clientLoader");
2237
- let hasHydrateFallback = sourceExports.includes("HydrateFallback");
2238
- let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
2239
- cache,
2240
- ctx,
2241
- routeFile,
2242
- { routeFile, viteChildCompiler }
2243
- );
2244
- if (enforceSplitRouteModules) {
2245
- validateRouteChunks({
2246
- ctx,
2247
- id: route.file,
2248
- valid: {
2249
- clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
2250
- clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
2251
- HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
2252
- }
2253
- });
2254
- }
2255
1599
  let routeManifestEntry = {
2256
1600
  id: route.id,
2257
1601
  parentId: route.parentId,
@@ -2260,33 +1604,18 @@ var reactRouterVitePlugin = () => {
2260
1604
  caseSensitive: route.caseSensitive,
2261
1605
  hasAction: sourceExports.includes("action"),
2262
1606
  hasLoader: sourceExports.includes("loader"),
2263
- hasClientAction,
2264
- hasClientLoader,
1607
+ hasClientAction: sourceExports.includes("clientAction"),
1608
+ hasClientLoader: sourceExports.includes("clientLoader"),
2265
1609
  hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
2266
1610
  ...getReactRouterManifestBuildAssets(
2267
1611
  ctx,
2268
1612
  viteManifest,
2269
- `${routeFile}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
1613
+ routeFilePath,
2270
1614
  // If this is the root route, we also need to include assets from the
2271
1615
  // client entry file as this is a common way for consumers to import
2272
1616
  // global reset styles, etc.
2273
1617
  isRootRoute ? [ctx.entryClientFilePath] : []
2274
- ),
2275
- clientActionModule: hasRouteChunkByExportName.clientAction ? getPublicModulePathForEntry(
2276
- ctx,
2277
- viteManifest,
2278
- getRouteChunkModuleId(routeFile, "clientAction")
2279
- ) : void 0,
2280
- clientLoaderModule: hasRouteChunkByExportName.clientLoader ? getPublicModulePathForEntry(
2281
- ctx,
2282
- viteManifest,
2283
- getRouteChunkModuleId(routeFile, "clientLoader")
2284
- ) : void 0,
2285
- hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? getPublicModulePathForEntry(
2286
- ctx,
2287
- viteManifest,
2288
- getRouteChunkModuleId(routeFile, "HydrateFallback")
2289
- ) : void 0
1618
+ )
2290
1619
  };
2291
1620
  browserRoutes[key] = routeManifestEntry;
2292
1621
  let serverBundleRoutes = ctx.serverBundleBuildConfig?.routes;
@@ -2327,52 +1656,25 @@ var reactRouterVitePlugin = () => {
2327
1656
  viteChildCompiler,
2328
1657
  ctx
2329
1658
  );
2330
- let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2331
1659
  for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
2332
- let routeFile = route.file;
2333
1660
  let sourceExports = routeManifestExports[key];
2334
- let hasClientAction = sourceExports.includes("clientAction");
2335
- let hasClientLoader = sourceExports.includes("clientLoader");
2336
- let hasHydrateFallback = sourceExports.includes("HydrateFallback");
2337
- let routeModulePath = combineURLs(
2338
- ctx.publicPath,
2339
- `${resolveFileUrl(
2340
- ctx,
2341
- resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2342
- )}`
2343
- );
2344
- if (enforceSplitRouteModules) {
2345
- let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
2346
- cache,
2347
- ctx,
2348
- routeFile,
2349
- { routeFile, viteChildCompiler }
2350
- );
2351
- validateRouteChunks({
2352
- ctx,
2353
- id: route.file,
2354
- valid: {
2355
- clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
2356
- clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
2357
- HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
2358
- }
2359
- });
2360
- }
2361
1661
  routes[key] = {
2362
1662
  id: route.id,
2363
1663
  parentId: route.parentId,
2364
1664
  path: route.path,
2365
1665
  index: route.index,
2366
1666
  caseSensitive: route.caseSensitive,
2367
- module: routeModulePath,
2368
- // Split route modules are a build-time optimization
2369
- clientActionModule: void 0,
2370
- clientLoaderModule: void 0,
2371
- hydrateFallbackModule: void 0,
1667
+ module: combineURLs(
1668
+ ctx.publicPath,
1669
+ resolveFileUrl(
1670
+ ctx,
1671
+ resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
1672
+ )
1673
+ ),
2372
1674
  hasAction: sourceExports.includes("action"),
2373
1675
  hasLoader: sourceExports.includes("loader"),
2374
- hasClientAction,
2375
- hasClientLoader,
1676
+ hasClientAction: sourceExports.includes("clientAction"),
1677
+ hasClientLoader: sourceExports.includes("clientLoader"),
2376
1678
  hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
2377
1679
  imports: []
2378
1680
  };
@@ -2468,9 +1770,9 @@ var reactRouterVitePlugin = () => {
2468
1770
  },
2469
1771
  optimizeDeps: {
2470
1772
  entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
2471
- ctx.entryClientFilePath,
1773
+ vite2.normalizePath(ctx.entryClientFilePath),
2472
1774
  ...Object.values(ctx.reactRouterConfig.routes).map(
2473
- (route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
1775
+ (route) => resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2474
1776
  )
2475
1777
  ] : [],
2476
1778
  include: [
@@ -2525,28 +1827,12 @@ var reactRouterVitePlugin = () => {
2525
1827
  preserveEntrySignatures: "exports-only",
2526
1828
  input: [
2527
1829
  ctx.entryClientFilePath,
2528
- ...Object.values(
2529
- ctx.reactRouterConfig.routes
2530
- ).flatMap((route) => {
2531
- let routeFilePath = path6.resolve(
1830
+ ...Object.values(ctx.reactRouterConfig.routes).map(
1831
+ (route) => `${path6.resolve(
2532
1832
  ctx.reactRouterConfig.appDirectory,
2533
1833
  route.file
2534
- );
2535
- let isRootRoute = route.file === ctx.reactRouterConfig.routes.root.file;
2536
- let code = fse.readFileSync(
2537
- routeFilePath,
2538
- "utf-8"
2539
- );
2540
- return [
2541
- `${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
2542
- ...ctx.reactRouterConfig.future.unstable_splitRouteModules && !isRootRoute ? routeChunkExportNames.map(
2543
- (exportName) => code.includes(exportName) ? getRouteChunkModuleId(
2544
- routeFilePath,
2545
- exportName
2546
- ) : null
2547
- ) : []
2548
- ].filter(isNonNullable);
2549
- })
1834
+ )}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
1835
+ )
2550
1836
  ]
2551
1837
  }
2552
1838
  } : {
@@ -2784,6 +2070,7 @@ var reactRouterVitePlugin = () => {
2784
2070
  viteConfig,
2785
2071
  ctx.reactRouterConfig,
2786
2072
  serverBuildDirectory,
2073
+ ssrViteManifest[virtual.serverBuild.id].file,
2787
2074
  clientBuildDirectory
2788
2075
  );
2789
2076
  }
@@ -2792,6 +2079,7 @@ var reactRouterVitePlugin = () => {
2792
2079
  viteConfig,
2793
2080
  ctx.reactRouterConfig,
2794
2081
  serverBuildDirectory,
2082
+ ssrViteManifest[virtual.serverBuild.id].file,
2795
2083
  clientBuildDirectory
2796
2084
  );
2797
2085
  }
@@ -2814,59 +2102,10 @@ var reactRouterVitePlugin = () => {
2814
2102
  await typegenWatcher?.close();
2815
2103
  }
2816
2104
  },
2817
- {
2818
- name: "react-router:route-chunks-index",
2819
- // This plugin provides the route module "index" since route modules can
2820
- // be chunked and may be made up of multiple smaller modules. This plugin
2821
- // primarily ensures code is never duplicated across a route module and
2822
- // its chunks. If we didn't have this plugin, any app that explicitly
2823
- // imports a route module would result in duplicate code since the app
2824
- // would contain code for both the unprocessed route module as well as its
2825
- // individual chunks. This is because, since they have different module
2826
- // IDs, they are treated as completely separate modules even though they
2827
- // all reference the same underlying file. This plugin addresses this by
2828
- // ensuring that any explicit imports of a route module resolve to a
2829
- // module that simply re-exports from its underlying chunks, if present.
2830
- async transform(code, id, options) {
2831
- if (viteCommand !== "build") return;
2832
- if (options?.ssr) {
2833
- return;
2834
- }
2835
- if (!isRoute(ctx.reactRouterConfig, id)) {
2836
- return;
2837
- }
2838
- if (isRouteVirtualModule(id)) {
2839
- return;
2840
- }
2841
- let { hasRouteChunks, chunkedExports } = await detectRouteChunksIfEnabled(cache, ctx, id, code);
2842
- if (!hasRouteChunks) {
2843
- return;
2844
- }
2845
- let sourceExports = await getRouteModuleExports(
2846
- viteChildCompiler,
2847
- ctx,
2848
- id
2849
- );
2850
- let isMainChunkExport = (name) => !chunkedExports.includes(name);
2851
- let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
2852
- let chunkBasePath = `./${path6.basename(id)}`;
2853
- return [
2854
- `export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
2855
- chunkBasePath,
2856
- "main"
2857
- )}";`,
2858
- ...chunkedExports.map(
2859
- (exportName) => `export { ${exportName} } from "${getRouteChunkModuleId(
2860
- chunkBasePath,
2861
- exportName
2862
- )}";`
2863
- )
2864
- ].filter(Boolean).join("\n");
2865
- }
2866
- },
2867
2105
  {
2868
2106
  name: "react-router:build-client-route",
2869
- async transform(code, id, options) {
2107
+ enforce: "pre",
2108
+ async transform(_code, id, options) {
2870
2109
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
2871
2110
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
2872
2111
  let routeFileName = path6.basename(routeModuleId);
@@ -2875,59 +2114,12 @@ var reactRouterVitePlugin = () => {
2875
2114
  ctx,
2876
2115
  routeModuleId
2877
2116
  );
2878
- let { chunkedExports = [] } = options?.ssr ? {} : await detectRouteChunksIfEnabled(cache, ctx, id, code);
2879
- let reexports = sourceExports.filter((exportName) => {
2880
- let isRouteEntryExport = options?.ssr && SERVER_ONLY_ROUTE_EXPORTS.includes(exportName) || CLIENT_ROUTE_EXPORTS.includes(exportName);
2881
- let isChunkedExport = chunkedExports.includes(
2882
- exportName
2883
- );
2884
- return isRouteEntryExport && !isChunkedExport;
2885
- }).join(", ");
2117
+ let reexports = sourceExports.filter(
2118
+ (exportName) => options?.ssr && SERVER_ONLY_ROUTE_EXPORTS.includes(exportName) || CLIENT_ROUTE_EXPORTS.includes(exportName)
2119
+ ).join(", ");
2886
2120
  return `export { ${reexports} } from "./${routeFileName}";`;
2887
2121
  }
2888
2122
  },
2889
- {
2890
- name: "react-router:split-route-modules",
2891
- async transform(code, id, options) {
2892
- if (options?.ssr) return;
2893
- if (!isRouteChunkModuleId(id)) return;
2894
- invariant(
2895
- viteCommand === "build",
2896
- "Route modules are only split in build mode"
2897
- );
2898
- let chunkName = getRouteChunkNameFromModuleId(id);
2899
- if (!chunkName) {
2900
- throw new Error(`Invalid route chunk name "${chunkName}" in "${id}"`);
2901
- }
2902
- let chunk = await getRouteChunkIfEnabled(
2903
- cache,
2904
- ctx,
2905
- id,
2906
- chunkName,
2907
- code
2908
- );
2909
- let preventEmptyChunkSnippet = ({ reason }) => `Math.random()<0&&console.log(${JSON.stringify(reason)});`;
2910
- if (chunk === null) {
2911
- return preventEmptyChunkSnippet({
2912
- reason: "Split round modules disabled"
2913
- });
2914
- }
2915
- let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2916
- if (enforceSplitRouteModules && chunkName === "main" && chunk) {
2917
- let exportNames = getExportNames(chunk.code);
2918
- validateRouteChunks({
2919
- ctx,
2920
- id,
2921
- valid: {
2922
- clientAction: !exportNames.includes("clientAction"),
2923
- clientLoader: !exportNames.includes("clientLoader"),
2924
- HydrateFallback: !exportNames.includes("HydrateFallback")
2925
- }
2926
- });
2927
- }
2928
- return chunk ?? preventEmptyChunkSnippet({ reason: `No ${chunkName} chunk` });
2929
- }
2930
- },
2931
2123
  {
2932
2124
  name: "react-router:virtual-modules",
2933
2125
  enforce: "pre",
@@ -2982,7 +2174,8 @@ var reactRouterVitePlugin = () => {
2982
2174
  let importerShort = vite2.normalizePath(
2983
2175
  path6.relative(ctx.rootDirectory, importer)
2984
2176
  );
2985
- if (isRoute(ctx.reactRouterConfig, importer)) {
2177
+ let isRoute = getRoute(ctx.reactRouterConfig, importer);
2178
+ if (isRoute) {
2986
2179
  let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
2987
2180
  (xport) => `\`${xport}\``
2988
2181
  ).join(", ");
@@ -3021,10 +2214,10 @@ var reactRouterVitePlugin = () => {
3021
2214
  let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
3022
2215
  let clientDirRE = /\/\.client\//;
3023
2216
  if (clientFileRE.test(id) || clientDirRE.test(id)) {
3024
- let exports2 = getExportNames(code);
2217
+ let exports2 = (0, import_es_module_lexer.parse)(code)[1];
3025
2218
  return {
3026
2219
  code: exports2.map(
3027
- (name) => name === "default" ? "export default undefined;" : `export const ${name} = undefined;`
2220
+ ({ n: name }) => name === "default" ? "export default undefined;" : `export const ${name} = undefined;`
3028
2221
  ).join("\n"),
3029
2222
  map: null
3030
2223
  };
@@ -3035,25 +2228,17 @@ var reactRouterVitePlugin = () => {
3035
2228
  {
3036
2229
  name: "react-router:route-exports",
3037
2230
  async transform(code, id, options) {
3038
- if (isRouteChunkModuleId(id)) {
3039
- id = id.split("?")[0];
3040
- }
3041
2231
  let route = getRoute(ctx.reactRouterConfig, id);
3042
2232
  if (!route) return;
3043
2233
  if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
3044
- let exportNames = getExportNames(code);
3045
- let serverOnlyExports = exportNames.filter(
3046
- (exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp)
3047
- );
2234
+ let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
3048
2235
  if (serverOnlyExports.length > 0) {
3049
2236
  let str = serverOnlyExports.map((e) => `\`${e}\``).join(", ");
3050
2237
  let message = `SPA Mode: ${serverOnlyExports.length} invalid route export(s) in \`${route.file}\`: ${str}. See https://remix.run/guides/spa-mode for more information.`;
3051
2238
  throw Error(message);
3052
2239
  }
3053
2240
  if (route.id !== "root") {
3054
- let hasHydrateFallback = exportNames.some(
3055
- (exp) => exp === "HydrateFallback"
3056
- );
2241
+ let hasHydrateFallback = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).some((exp) => exp === "HydrateFallback");
3057
2242
  if (hasHydrateFallback) {
3058
2243
  let message = `SPA Mode: Invalid \`HydrateFallback\` export found in \`${route.file}\`. \`HydrateFallback\` is only permitted on the root route in SPA Mode. See https://remix.run/guides/spa-mode for more information.`;
3059
2244
  throw Error(message);
@@ -3131,9 +2316,6 @@ var reactRouterVitePlugin = () => {
3131
2316
  let isJSX = filepath.endsWith("x");
3132
2317
  let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
3133
2318
  if (!useFastRefresh) return;
3134
- if (isRouteVirtualModule(id)) {
3135
- return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id) };
3136
- }
3137
2319
  let result = await babel.transformAsync(code, {
3138
2320
  babelrc: false,
3139
2321
  configFile: false,
@@ -3164,7 +2346,6 @@ var reactRouterVitePlugin = () => {
3164
2346
  let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
3165
2347
  let oldRouteMetadata = serverManifest.routes[route.id];
3166
2348
  let newRouteMetadata = await getRouteMetadata(
3167
- cache,
3168
2349
  ctx,
3169
2350
  viteChildCompiler,
3170
2351
  route,
@@ -3174,12 +2355,9 @@ var reactRouterVitePlugin = () => {
3174
2355
  if (!oldRouteMetadata || [
3175
2356
  "hasLoader",
3176
2357
  "hasClientLoader",
3177
- "clientLoaderModule",
3178
2358
  "hasAction",
3179
2359
  "hasClientAction",
3180
- "clientActionModule",
3181
- "hasErrorBoundary",
3182
- "hydrateFallbackModule"
2360
+ "hasErrorBoundary"
3183
2361
  ].some((key) => oldRouteMetadata[key] !== newRouteMetadata[key])) {
3184
2362
  invalidateVirtualModules(server);
3185
2363
  }
@@ -3245,6 +2423,7 @@ function addRefreshWrapper(reactRouterConfig, code, id) {
3245
2423
  let acceptExports = route ? [
3246
2424
  "clientAction",
3247
2425
  "clientLoader",
2426
+ "clientMiddleware",
3248
2427
  "handle",
3249
2428
  "meta",
3250
2429
  "links",
@@ -3297,30 +2476,13 @@ function getRoute(pluginConfig, file) {
3297
2476
  );
3298
2477
  return route;
3299
2478
  }
3300
- function isRoute(pluginConfig, file) {
3301
- return Boolean(getRoute(pluginConfig, file));
3302
- }
3303
- async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteFile) {
3304
- let routeFile = route.file;
2479
+ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
3305
2480
  let sourceExports = await getRouteModuleExports(
3306
2481
  viteChildCompiler,
3307
2482
  ctx,
3308
2483
  route.file,
3309
2484
  readRouteFile
3310
2485
  );
3311
- let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
3312
- cache,
3313
- ctx,
3314
- routeFile,
3315
- { routeFile, readRouteFile, viteChildCompiler }
3316
- );
3317
- let moduleUrl = combineURLs(
3318
- ctx.publicPath,
3319
- `${resolveFileUrl(
3320
- ctx,
3321
- resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3322
- )}`
3323
- );
3324
2486
  let info = {
3325
2487
  id: route.id,
3326
2488
  parentId: route.parentId,
@@ -3334,11 +2496,14 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
3334
2496
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3335
2497
  )
3336
2498
  ),
3337
- module: `${moduleUrl}?import`,
2499
+ module: combineURLs(
2500
+ ctx.publicPath,
2501
+ `${resolveFileUrl(
2502
+ ctx,
2503
+ resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2504
+ )}?import`
2505
+ ),
3338
2506
  // Ensure the Vite dev server responds with a JS module
3339
- clientActionModule: hasRouteChunkByExportName.clientAction ? `${getRouteChunkModuleId(moduleUrl, "clientAction")}` : void 0,
3340
- clientLoaderModule: hasRouteChunkByExportName.clientLoader ? `${getRouteChunkModuleId(moduleUrl, "clientLoader")}` : void 0,
3341
- hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? `${getRouteChunkModuleId(moduleUrl, "HydrateFallback")}` : void 0,
3342
2507
  hasAction: sourceExports.includes("action"),
3343
2508
  hasClientAction: sourceExports.includes("clientAction"),
3344
2509
  hasLoader: sourceExports.includes("loader"),
@@ -3348,11 +2513,8 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
3348
2513
  };
3349
2514
  return info;
3350
2515
  }
3351
- async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
3352
- let serverBuildPath = path6.join(
3353
- serverBuildDirectory,
3354
- reactRouterConfig.serverBuildFile
3355
- );
2516
+ async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
2517
+ let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
3356
2518
  let build = await import(url.pathToFileURL(serverBuildPath).toString());
3357
2519
  let { createRequestHandler: createHandler } = await import("react-router");
3358
2520
  return {
@@ -3360,11 +2522,11 @@ async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, server
3360
2522
  handler: createHandler(build, viteConfig.mode)
3361
2523
  };
3362
2524
  }
3363
- async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
2525
+ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildFile, clientBuildDirectory) {
3364
2526
  let { handler } = await getPrerenderBuildAndHandler(
3365
2527
  viteConfig,
3366
- reactRouterConfig,
3367
- serverBuildDirectory
2528
+ serverBuildDirectory,
2529
+ serverBuildFile
3368
2530
  );
3369
2531
  let request = new Request(`http://localhost${reactRouterConfig.basename}`);
3370
2532
  let response = await handler(request);
@@ -3376,11 +2538,11 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3376
2538
  "SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path6.relative(process.cwd(), clientBuildDirectory)) + " directory"
3377
2539
  );
3378
2540
  }
3379
- async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
2541
+ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildPath, clientBuildDirectory) {
3380
2542
  let { build, handler } = await getPrerenderBuildAndHandler(
3381
2543
  viteConfig,
3382
- reactRouterConfig,
3383
- serverBuildDirectory
2544
+ serverBuildDirectory,
2545
+ serverBuildPath
3384
2546
  );
3385
2547
  let routes = createPrerenderRoutes(build.routes);
3386
2548
  let routesToPrerender;
@@ -3576,6 +2738,8 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
3576
2738
  loader: route.module.loader ? () => null : void 0,
3577
2739
  action: void 0,
3578
2740
  handle: route.module.handle
2741
+ // middleware is not necessary here since we just need to know which
2742
+ // routes have loaders so we know what paths to prerender
3579
2743
  };
3580
2744
  return route.index ? {
3581
2745
  index: true,
@@ -3587,73 +2751,6 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
3587
2751
  };
3588
2752
  });
3589
2753
  }
3590
- var resolveRouteFileCode = async (ctx, input) => {
3591
- if (typeof input === "string") return input;
3592
- invariant(input.viteChildCompiler);
3593
- return await compileRouteFile(
3594
- input.viteChildCompiler,
3595
- ctx,
3596
- input.routeFile,
3597
- input.readRouteFile
3598
- );
3599
- };
3600
- async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
3601
- function noRouteChunks() {
3602
- return {
3603
- chunkedExports: [],
3604
- hasRouteChunks: false,
3605
- hasRouteChunkByExportName: {
3606
- clientAction: false,
3607
- clientLoader: false,
3608
- HydrateFallback: false
3609
- }
3610
- };
3611
- }
3612
- if (!ctx.reactRouterConfig.future.unstable_splitRouteModules) {
3613
- return noRouteChunks();
3614
- }
3615
- if (normalizeRelativeFilePath(id, ctx.reactRouterConfig) === ctx.reactRouterConfig.routes.root.file) {
3616
- return noRouteChunks();
3617
- }
3618
- let code = await resolveRouteFileCode(ctx, input);
3619
- if (!routeChunkExportNames.some((exportName) => code.includes(exportName))) {
3620
- return noRouteChunks();
3621
- }
3622
- let cacheKey = normalizeRelativeFilePath(id, ctx.reactRouterConfig) + (typeof input === "string" ? "" : "?read");
3623
- return detectRouteChunks(code, cache, cacheKey);
3624
- }
3625
- async function getRouteChunkIfEnabled(cache, ctx, id, chunkName, input) {
3626
- if (!ctx.reactRouterConfig.future.unstable_splitRouteModules) {
3627
- return null;
3628
- }
3629
- let code = await resolveRouteFileCode(ctx, input);
3630
- let cacheKey = normalizeRelativeFilePath(id, ctx.reactRouterConfig) + (typeof input === "string" ? "" : "?read");
3631
- return getRouteChunkCode(code, chunkName, cache, cacheKey);
3632
- }
3633
- function validateRouteChunks({
3634
- ctx,
3635
- id,
3636
- valid
3637
- }) {
3638
- let invalidChunks = Object.entries(valid).filter(([_, isValid]) => !isValid).map(([chunkName]) => chunkName);
3639
- if (invalidChunks.length === 0) {
3640
- return;
3641
- }
3642
- let plural = invalidChunks.length > 1;
3643
- throw new Error(
3644
- [
3645
- `Error splitting route module: ${normalizeRelativeFilePath(
3646
- id,
3647
- ctx.reactRouterConfig
3648
- )}`,
3649
- invalidChunks.map((name) => `- ${name}`).join("\n"),
3650
- `${plural ? "These exports" : "This export"} could not be split into ${plural ? "their own chunks" : "its own chunk"} because ${plural ? "they share" : "it shares"} code with other exports. You should extract any shared code into its own module and then import it within the route module.`
3651
- ].join("\n\n")
3652
- );
3653
- }
3654
- function isNonNullable(x) {
3655
- return x != null;
3656
- }
3657
2754
  // Annotate the CommonJS export names for ESM import in node:
3658
2755
  0 && (module.exports = {
3659
2756
  reactRouter