@reckona/mreact-router 0.0.131 → 0.0.134

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.
Files changed (48) hide show
  1. package/dist/adapters/cloudflare.js +1 -1
  2. package/dist/adapters/cloudflare.js.map +1 -1
  3. package/dist/adapters/static.js +5 -1
  4. package/dist/adapters/static.js.map +1 -1
  5. package/dist/build.d.ts +1 -0
  6. package/dist/build.d.ts.map +1 -1
  7. package/dist/build.js +136 -41
  8. package/dist/build.js.map +1 -1
  9. package/dist/client.d.ts.map +1 -1
  10. package/dist/client.js +188 -6
  11. package/dist/client.js.map +1 -1
  12. package/dist/http.d.ts +1 -0
  13. package/dist/http.d.ts.map +1 -1
  14. package/dist/http.js +7 -1
  15. package/dist/http.js.map +1 -1
  16. package/dist/module-runner.d.ts +4 -1
  17. package/dist/module-runner.d.ts.map +1 -1
  18. package/dist/module-runner.js +3 -2
  19. package/dist/module-runner.js.map +1 -1
  20. package/dist/render.d.ts +6 -1
  21. package/dist/render.d.ts.map +1 -1
  22. package/dist/render.js +84 -46
  23. package/dist/render.js.map +1 -1
  24. package/dist/routes.js +1 -1
  25. package/dist/routes.js.map +1 -1
  26. package/dist/serve.d.ts.map +1 -1
  27. package/dist/serve.js +110 -17
  28. package/dist/serve.js.map +1 -1
  29. package/dist/vite-plugin-cache-key.d.ts +2 -1
  30. package/dist/vite-plugin-cache-key.d.ts.map +1 -1
  31. package/dist/vite-plugin-cache-key.js +9 -0
  32. package/dist/vite-plugin-cache-key.js.map +1 -1
  33. package/dist/vite.d.ts +2 -1
  34. package/dist/vite.d.ts.map +1 -1
  35. package/dist/vite.js +2 -0
  36. package/dist/vite.js.map +1 -1
  37. package/package.json +11 -11
  38. package/src/adapters/cloudflare.ts +1 -1
  39. package/src/adapters/static.ts +7 -1
  40. package/src/build.ts +201 -53
  41. package/src/client.ts +329 -8
  42. package/src/http.ts +9 -1
  43. package/src/module-runner.ts +8 -2
  44. package/src/render.ts +117 -21
  45. package/src/routes.ts +1 -1
  46. package/src/serve.ts +167 -18
  47. package/src/vite-plugin-cache-key.ts +12 -1
  48. package/src/vite.ts +4 -0
package/src/client.ts CHANGED
@@ -920,10 +920,16 @@ async function inferClientRouteModuleSource(options: {
920
920
  if (exported.clientBoundaryModule) {
921
921
  clientProxy = true;
922
922
  } else if (exported.clientBoundaryExportNames.length > 0) {
923
- for (const exportName of reference.exportedNames) {
924
- if (exported.clientBoundaryExportNames.includes(exportName)) {
923
+ if (reference.exportAll) {
924
+ for (const exportName of exported.clientBoundaryExportNames) {
925
925
  clientBoundaryExportNames.add(exportName);
926
926
  }
927
+ } else {
928
+ for (const specifier of reference.specifiers) {
929
+ if (exported.clientBoundaryExportNames.includes(specifier.localName)) {
930
+ clientBoundaryExportNames.add(specifier.exportedName);
931
+ }
932
+ }
927
933
  }
928
934
  } else if (exported.client) {
929
935
  nestedClient = true;
@@ -1110,7 +1116,16 @@ function isStyleModuleSpecifier(source: string): boolean {
1110
1116
  const styleModuleExtensions = new Set([".css", ".less", ".sass", ".scss", ".styl", ".stylus"]);
1111
1117
 
1112
1118
  function isClientBoundaryFallbackEligibleSource(source: string): boolean {
1119
+ if (hasClientBoundaryFallbackUnsafeBrowserGlobal(source)) {
1120
+ return false;
1121
+ }
1122
+
1113
1123
  const destructuredCallbackPropNames = destructuredPropsCallbackNames(source);
1124
+ const callbackPropNames = new Set([
1125
+ ...destructuredCallbackPropNames,
1126
+ ...propsCallbackAliasNames(source),
1127
+ ...memberCallbackNames(source),
1128
+ ]);
1114
1129
  const sourceWithoutComponentCallbackProps = source.replaceAll(
1115
1130
  /<[A-Z][A-Za-z0-9_$.]*(?:\s[\s\S]*?)?>/gu,
1116
1131
  (tag) => tag.replaceAll(/\s+on[A-Z][A-Za-z0-9_$]*\s*=\s*\{[^{}]*\}/gu, ""),
@@ -1125,16 +1140,98 @@ function isClientBoundaryFallbackEligibleSource(source: string): boolean {
1125
1140
  "",
1126
1141
  );
1127
1142
 
1128
- for (const callbackName of destructuredCallbackPropNames) {
1143
+ for (const callbackName of callbackPropNames) {
1144
+ const escapedCallbackName = escapeRegExp(callbackName);
1145
+ const callbackHandlerAttributePattern = new RegExp(
1146
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*[^{}]*\b${escapedCallbackName}\b[^{}]*\}`,
1147
+ "gu",
1148
+ );
1129
1149
  sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1130
1150
  new RegExp(
1131
- String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapeRegExp(
1132
- callbackName,
1133
- )}\s*\?\s*[^{}]*:\s*undefined\s*\}`,
1151
+ String.raw`\b(?:const|let|var)\s+${escapedCallbackName}\s*=\s*props\.[A-Za-z_$][\w$]*\s*;?`,
1152
+ "gu",
1153
+ ),
1154
+ "",
1155
+ );
1156
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1157
+ new RegExp(
1158
+ String.raw`\b(?:const|let|var)\s+${escapedCallbackName}\s*=\s*[^;\n]+\.${escapedCallbackName}\s*;?`,
1159
+ "gu",
1160
+ ),
1161
+ "",
1162
+ );
1163
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1164
+ new RegExp(
1165
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*\?\s*[^{}]*:\s*undefined\s*\}`,
1166
+ "gu",
1167
+ ),
1168
+ "",
1169
+ );
1170
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1171
+ new RegExp(
1172
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*(?:===|==)\s*(?:undefined|null)\s*\?\s*undefined\s*:\s*[^{}]*\}`,
1173
+ "gu",
1174
+ ),
1175
+ "",
1176
+ );
1177
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1178
+ new RegExp(
1179
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*(?:undefined|null)\s*(?:===|==)\s*${escapedCallbackName}\s*\?\s*undefined\s*:\s*[^{}]*\}`,
1180
+ "gu",
1181
+ ),
1182
+ "",
1183
+ );
1184
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1185
+ new RegExp(
1186
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*(?:!==|!=)\s*(?:undefined|null)\s*\?\s*[^{}]*:\s*undefined\s*\}`,
1187
+ "gu",
1188
+ ),
1189
+ "",
1190
+ );
1191
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1192
+ new RegExp(
1193
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*typeof\s+${escapedCallbackName}\s*===\s*["']function["']\s*\?\s*[^{}]*:\s*undefined\s*\}`,
1194
+ "gu",
1195
+ ),
1196
+ "",
1197
+ );
1198
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1199
+ new RegExp(
1200
+ String.raw`\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{\s*${escapedCallbackName}\s*\?\?\s*undefined\s*\}`,
1134
1201
  "gu",
1135
1202
  ),
1136
1203
  "",
1137
1204
  );
1205
+
1206
+ if (
1207
+ hasCallbackAbsenceGuard(
1208
+ sourceWithoutComponentCallbackProps.replaceAll(callbackHandlerAttributePattern, ""),
1209
+ callbackName,
1210
+ )
1211
+ ) {
1212
+ sourceWithoutGuardedUndefinedCallbacks = sourceWithoutGuardedUndefinedCallbacks.replaceAll(
1213
+ callbackHandlerAttributePattern,
1214
+ "",
1215
+ );
1216
+ }
1217
+ sourceWithoutGuardedUndefinedCallbacks = removeSafeCallbackHandlerAttributes(
1218
+ sourceWithoutGuardedUndefinedCallbacks,
1219
+ callbackName,
1220
+ {
1221
+ externalAbsenceGuard: hasCallbackAbsenceGuard(
1222
+ sourceWithoutComponentCallbackProps.replaceAll(callbackHandlerAttributePattern, ""),
1223
+ callbackName,
1224
+ ),
1225
+ },
1226
+ );
1227
+
1228
+ if (
1229
+ new RegExp(String.raw`\b${escapedCallbackName}\s*\(`, "u").test(
1230
+ sourceWithoutGuardedUndefinedCallbacks,
1231
+ )
1232
+ ) {
1233
+ return false;
1234
+ }
1138
1235
  }
1139
1236
 
1140
1237
  return (
@@ -1143,6 +1240,201 @@ function isClientBoundaryFallbackEligibleSource(source: string): boolean {
1143
1240
  );
1144
1241
  }
1145
1242
 
1243
+ function hasClientBoundaryFallbackUnsafeBrowserGlobal(source: string): boolean {
1244
+ return /\b(?:window|document|localStorage)\b/u.test(source);
1245
+ }
1246
+
1247
+ function propsCallbackAliasNames(source: string): Set<string> {
1248
+ const names = new Set<string>();
1249
+
1250
+ for (const match of source.matchAll(
1251
+ /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*props\.([A-Za-z_$][\w$]*)\b/gu,
1252
+ )) {
1253
+ const localName = match[1];
1254
+ const propName = match[2];
1255
+
1256
+ if (
1257
+ localName !== undefined &&
1258
+ (isCallbackPropName(propName) || isCallbackPropName(localName))
1259
+ ) {
1260
+ names.add(localName);
1261
+ }
1262
+ }
1263
+
1264
+ for (const match of source.matchAll(
1265
+ /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*\(\s*props\s+as\s+[^)]+\)\.([A-Za-z_$][\w$]*)\b/gu,
1266
+ )) {
1267
+ const localName = match[1];
1268
+ const propName = match[2];
1269
+
1270
+ if (
1271
+ localName !== undefined &&
1272
+ (isCallbackPropName(propName) || isCallbackPropName(localName))
1273
+ ) {
1274
+ names.add(localName);
1275
+ }
1276
+ }
1277
+
1278
+ for (const match of source.matchAll(
1279
+ /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*\(\s*props\s*\)\.([A-Za-z_$][\w$]*)\b/gu,
1280
+ )) {
1281
+ const localName = match[1];
1282
+ const propName = match[2];
1283
+
1284
+ if (
1285
+ localName !== undefined &&
1286
+ (isCallbackPropName(propName) || isCallbackPropName(localName))
1287
+ ) {
1288
+ names.add(localName);
1289
+ }
1290
+ }
1291
+
1292
+ for (const match of source.matchAll(
1293
+ /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*[^;\n]+\.([A-Za-z_$][\w$]*)\s*;?/gu,
1294
+ )) {
1295
+ const localName = match[1];
1296
+ const propName = match[2];
1297
+
1298
+ if (
1299
+ localName !== undefined &&
1300
+ (isCallbackPropName(propName) || isCallbackPropName(localName))
1301
+ ) {
1302
+ names.add(localName);
1303
+ }
1304
+ }
1305
+
1306
+ let added = true;
1307
+ while (added) {
1308
+ added = false;
1309
+ for (const match of source.matchAll(
1310
+ /\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)\b/gu,
1311
+ )) {
1312
+ const localName = match[1];
1313
+ const sourceName = match[2];
1314
+
1315
+ if (localName !== undefined && sourceName !== undefined && names.has(sourceName)) {
1316
+ const previousSize = names.size;
1317
+ names.add(localName);
1318
+ added ||= names.size !== previousSize;
1319
+ }
1320
+ }
1321
+ }
1322
+
1323
+ return names;
1324
+ }
1325
+
1326
+ function hasCallbackAbsenceGuard(source: string, name: string): boolean {
1327
+ const escapedName = escapeRegExp(name);
1328
+
1329
+ return new RegExp(
1330
+ String.raw`(?:!\s*${escapedName}\b|${escapedName}\s*(?:===|==)\s*(?:undefined|null)|(?:undefined|null)\s*(?:===|==)\s*${escapedName}\b)`,
1331
+ "u",
1332
+ ).test(source);
1333
+ }
1334
+
1335
+ function memberCallbackNames(source: string): Set<string> {
1336
+ const names = new Set<string>();
1337
+
1338
+ for (const match of source.matchAll(/\.([A-Za-z_$][\w$]*)\b/gu)) {
1339
+ const memberName = match[1];
1340
+
1341
+ if (memberName !== undefined && isCallbackPropName(memberName)) {
1342
+ names.add(memberName);
1343
+ }
1344
+ }
1345
+
1346
+ return names;
1347
+ }
1348
+
1349
+ function removeSafeCallbackHandlerAttributes(
1350
+ source: string,
1351
+ callbackName: string,
1352
+ options: { externalAbsenceGuard: boolean },
1353
+ ): string {
1354
+ const attributePattern = /\bon[A-Z][A-Za-z0-9_$]*\s*=\s*\{/gu;
1355
+ let result = "";
1356
+ let cursor = 0;
1357
+
1358
+ for (const match of source.matchAll(attributePattern)) {
1359
+ const start = match.index;
1360
+ const expressionStart = start + match[0].length;
1361
+ const end = matchingBraceEnd(source, expressionStart - 1);
1362
+
1363
+ if (end === undefined) {
1364
+ continue;
1365
+ }
1366
+
1367
+ const expression = source.slice(expressionStart, end);
1368
+ if (isSafeCallbackHandlerExpression(expression, callbackName, options)) {
1369
+ result += source.slice(cursor, start);
1370
+ cursor = end + 1;
1371
+ }
1372
+ }
1373
+
1374
+ return cursor === 0 ? source : result + source.slice(cursor);
1375
+ }
1376
+
1377
+ function matchingBraceEnd(source: string, openBraceIndex: number): number | undefined {
1378
+ let depth = 0;
1379
+ let quote: "\"" | "'" | "`" | undefined;
1380
+ let escaped = false;
1381
+
1382
+ for (let index = openBraceIndex; index < source.length; index += 1) {
1383
+ const char = source[index];
1384
+
1385
+ if (quote !== undefined) {
1386
+ if (escaped) {
1387
+ escaped = false;
1388
+ } else if (char === "\\") {
1389
+ escaped = true;
1390
+ } else if (char === quote) {
1391
+ quote = undefined;
1392
+ }
1393
+ continue;
1394
+ }
1395
+
1396
+ if (char === "\"" || char === "'" || char === "`") {
1397
+ quote = char;
1398
+ continue;
1399
+ }
1400
+
1401
+ if (char === "{") {
1402
+ depth += 1;
1403
+ continue;
1404
+ }
1405
+
1406
+ if (char === "}") {
1407
+ depth -= 1;
1408
+ if (depth === 0) {
1409
+ return index;
1410
+ }
1411
+ }
1412
+ }
1413
+
1414
+ return undefined;
1415
+ }
1416
+
1417
+ function isSafeCallbackHandlerExpression(
1418
+ expression: string,
1419
+ callbackName: string,
1420
+ options: { externalAbsenceGuard: boolean },
1421
+ ): boolean {
1422
+ const escapedName = escapeRegExp(callbackName);
1423
+ if (!new RegExp(String.raw`\b${escapedName}\b`, "u").test(expression)) {
1424
+ return false;
1425
+ }
1426
+
1427
+ if (new RegExp(String.raw`\b${escapedName}\s*\(`, "u").test(expression)) {
1428
+ return false;
1429
+ }
1430
+
1431
+ return (
1432
+ new RegExp(String.raw`\b${escapedName}\s*\?\.\s*\(`, "u").test(expression) ||
1433
+ new RegExp(String.raw`^\s*${escapedName}\s*\?\?\s*undefined\s*$`, "u").test(expression) ||
1434
+ options.externalAbsenceGuard
1435
+ );
1436
+ }
1437
+
1146
1438
  function destructuredPropsCallbackNames(source: string): Set<string> {
1147
1439
  const names = new Set<string>();
1148
1440
 
@@ -1151,7 +1443,31 @@ function destructuredPropsCallbackNames(source: string): Set<string> {
1151
1443
  }
1152
1444
 
1153
1445
  for (const match of source.matchAll(
1154
- /\bfunction\s+[A-Za-z_$][\w$]*\s*\(\s*\{([^}]+)\}/gu,
1446
+ /\{[^{}]*:\s*\{([^{}]+)\}\s*(?:=\s*\{\})?[^{}]*\}/gu,
1447
+ )) {
1448
+ addDestructuredCallbackNames(names, match[1] ?? "");
1449
+ }
1450
+
1451
+ for (const match of source.matchAll(
1452
+ /\bfunction(?:\s+[A-Za-z_$][\w$]*(?:<[^>()]+>)?)?\s*\(\s*\{([^}]+)\}/gu,
1453
+ )) {
1454
+ addDestructuredCallbackNames(names, match[1] ?? "");
1455
+ }
1456
+
1457
+ for (const match of source.matchAll(
1458
+ /\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?\(?\s*\{([^}]+)\}\s*(?::\s*[^)=]+)?\)?\s*=>/gu,
1459
+ )) {
1460
+ addDestructuredCallbackNames(names, match[1] ?? "");
1461
+ }
1462
+
1463
+ for (const match of source.matchAll(
1464
+ /\bexport\s+default\s+(?:async\s*)?\(?\s*\{([^}]+)\}\s*(?::\s*[^)=]+)?\)?\s*=>/gu,
1465
+ )) {
1466
+ addDestructuredCallbackNames(names, match[1] ?? "");
1467
+ }
1468
+
1469
+ for (const match of source.matchAll(
1470
+ /\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*function(?:\s+[A-Za-z_$][\w$]*)?\s*\(\s*\{([^}]+)\}/gu,
1155
1471
  )) {
1156
1472
  addDestructuredCallbackNames(names, match[1] ?? "");
1157
1473
  }
@@ -4261,5 +4577,10 @@ function errorMessage(error: unknown): string {
4261
4577
  }
4262
4578
 
4263
4579
  function escapeScriptJson(value: string): string {
4264
- return value.replaceAll("<", "\\u003c");
4580
+ return value
4581
+ .replaceAll("&", "\\u0026")
4582
+ .replaceAll("<", "\\u003c")
4583
+ .replaceAll(">", "\\u003e")
4584
+ .replaceAll("\u2028", "\\u2028")
4585
+ .replaceAll("\u2029", "\\u2029");
4265
4586
  }
package/src/http.ts CHANGED
@@ -2,6 +2,8 @@ import type { ServerResponse } from "node:http";
2
2
  import type { IncomingMessage } from "node:http";
3
3
  import { Readable } from "node:stream";
4
4
 
5
+ const rawUrlByRequest = new WeakMap<Request, string>();
6
+
5
7
  export function nodeRequestToWebRequest(
6
8
  incoming: IncomingMessage,
7
9
  origin: string,
@@ -32,7 +34,13 @@ export function nodeRequestToWebRequest(
32
34
  init.duplex = "half";
33
35
  }
34
36
 
35
- return new Request(new URL(incoming.url ?? "/", origin), init);
37
+ const request = new Request(new URL(incoming.url ?? "/", origin), init);
38
+ rawUrlByRequest.set(request, incoming.url ?? "/");
39
+ return request;
40
+ }
41
+
42
+ export function rawNodeRequestUrl(request: Request): string | undefined {
43
+ return rawUrlByRequest.get(request);
36
44
  }
37
45
 
38
46
  /**
@@ -13,6 +13,7 @@ import {
13
13
  type InlineConfig,
14
14
  type PluginOption,
15
15
  type RunnableDevEnvironment,
16
+ type UserConfig,
16
17
  } from "vite";
17
18
  import { resolveWorkspacePackageFile } from "./workspace-packages.js";
18
19
  import {
@@ -36,7 +37,7 @@ import {
36
37
  inferClientRouteModule,
37
38
  type ClientRouteInferenceCache,
38
39
  } from "./client-route-inference.js";
39
- import { vitePluginsCacheKey } from "./vite-plugin-cache-key.js";
40
+ import { viteDefineCacheKey, vitePluginsCacheKey } from "./vite-plugin-cache-key.js";
40
41
 
41
42
  const runnerConfig = {
42
43
  configFile: false,
@@ -81,6 +82,7 @@ export function routerModuleRunnerRuntimeCacheStats(): RouterRuntimeCacheStat[]
81
82
  export async function importAppRouterSourceModule<T>(options: {
82
83
  cacheKey?: string | undefined;
83
84
  code: string;
85
+ define?: UserConfig["define"] | undefined;
84
86
  externalizeAppSourceModuleDirs?: readonly string[] | undefined;
85
87
  label: string;
86
88
  plugins?: readonly RouterCompatPlugin[] | undefined;
@@ -122,6 +124,7 @@ export async function importAppRouterSourceModule<T>(options: {
122
124
 
123
125
  async function importAppRouterSourceModuleWithoutCache<T>(options: {
124
126
  code: string;
127
+ define?: UserConfig["define"] | undefined;
125
128
  externalizeAppSourceModuleDirs?: readonly string[] | undefined;
126
129
  label: string;
127
130
  plugins?: readonly RouterCompatPlugin[] | undefined;
@@ -273,6 +276,7 @@ export async function importAppRouterBuiltFileModule<T>(options: {
273
276
 
274
277
  export async function bundleAppRouterSourceModule(options: {
275
278
  code: string;
279
+ define?: UserConfig["define"] | undefined;
276
280
  externalizeAppSourceModuleDirs?: readonly string[] | undefined;
277
281
  label: string;
278
282
  plugins?: readonly RouterCompatPlugin[] | undefined;
@@ -284,6 +288,7 @@ export async function bundleAppRouterSourceModule(options: {
284
288
  }): Promise<string> {
285
289
  const output = await bundleRouterModule({
286
290
  code: options.code,
291
+ define: options.define,
287
292
  externalizeAppSourceModuleDirs: options.externalizeAppSourceModuleDirs,
288
293
  filename: options.sourcefile ?? join(options.resolveDir ?? process.cwd(), "module.js"),
289
294
  platform: "node",
@@ -334,6 +339,7 @@ export function fileImportMetaUrlPlugin(): RouterCompatPlugin {
334
339
 
335
340
  interface ServerSourceTransformOptions {
336
341
  clientRouteInferenceCache?: ClientRouteInferenceCache | undefined;
342
+ define?: UserConfig["define"] | undefined;
337
343
  dev: boolean;
338
344
  serverModules?: ReadonlyMap<string, BuiltServerModuleArtifact> | undefined;
339
345
  serverOutput: ServerOutputMode;
@@ -411,7 +417,7 @@ async function transformServerSourceFile(
411
417
  console.warn(formatClientRouteInferenceDiagnostic(diagnostic));
412
418
  }
413
419
 
414
- const cacheKey = `${options.serverOutput}\0${options.dev ? "dev" : "prod"}\0${options.filename}\0${transformedSourceHash}\0${clientInference.clientBoundaryImports.join("\0")}\0${clientInference.clientBoundaryFallbackImports.join("\0")}\0${vitePluginsCacheKey(options.vitePlugins)}`;
420
+ const cacheKey = `${options.serverOutput}\0${options.dev ? "dev" : "prod"}\0${options.filename}\0${transformedSourceHash}\0${clientInference.clientBoundaryImports.join("\0")}\0${clientInference.clientBoundaryFallbackImports.join("\0")}\0${viteDefineCacheKey(options.define)}\0${vitePluginsCacheKey(options.vitePlugins)}`;
415
421
  const cached = readRouterRuntimeCacheEntry(
416
422
  serverSourceTransformCache,
417
423
  cacheKey,