@reckona/mreact-router 0.0.57 → 0.0.58
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/build.d.ts.map +1 -1
- package/dist/build.js +3 -0
- package/dist/build.js.map +1 -1
- package/dist/module-runner.d.ts +2 -0
- package/dist/module-runner.d.ts.map +1 -1
- package/dist/module-runner.js +3 -1
- package/dist/module-runner.js.map +1 -1
- package/dist/render.d.ts +2 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +59 -61
- package/dist/render.js.map +1 -1
- package/dist/vite-plugin-cache-key.d.ts +3 -0
- package/dist/vite-plugin-cache-key.d.ts.map +1 -0
- package/dist/vite-plugin-cache-key.js +39 -0
- package/dist/vite-plugin-cache-key.js.map +1 -0
- package/package.json +11 -11
package/dist/render.js
CHANGED
|
@@ -25,6 +25,7 @@ import { emitRouterLog, logDurationMs, logNow } from "./logger.js";
|
|
|
25
25
|
import { createRouterRuntimeCacheCounters, readRouterRuntimeCacheEntry, routerRuntimeCacheStat, } from "./cache-stats.js";
|
|
26
26
|
import { bundleRouterModule } from "./bundle-pipeline.js";
|
|
27
27
|
import { routeSecurityHeaders } from "./security-headers.js";
|
|
28
|
+
import { vitePluginsCacheKey } from "./vite-plugin-cache-key.js";
|
|
28
29
|
import { invokeRouterInstrumentation, traceContextFromRequest, } from "./trace.js";
|
|
29
30
|
const nativeEscapeTransform = {
|
|
30
31
|
batchImportName: "escapeHtmlBatch",
|
|
@@ -47,6 +48,7 @@ export async function preloadBuiltRequestModules(options) {
|
|
|
47
48
|
serverModules: options.serverModules,
|
|
48
49
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
49
50
|
serverSourceFiles: options.serverSourceFiles,
|
|
51
|
+
vitePlugins: options.vitePlugins,
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -108,7 +110,7 @@ async function preloadBuiltPageRouteModules(options) {
|
|
|
108
110
|
serverOutput: "string",
|
|
109
111
|
});
|
|
110
112
|
assertNoFatalServerDiagnostics(options.file, stringOutput.diagnostics);
|
|
111
|
-
await loadServerModule(stringOutput.code, options.file, options.serverModules, options.serverModuleCacheVersion);
|
|
113
|
+
await loadServerModule(stringOutput.code, options.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
112
114
|
}
|
|
113
115
|
if (options.analysis.streamRoute) {
|
|
114
116
|
const streamOutput = transformServerModule({
|
|
@@ -120,7 +122,7 @@ async function preloadBuiltPageRouteModules(options) {
|
|
|
120
122
|
serverAwaitHydration: options.analysis.clientInference.client,
|
|
121
123
|
});
|
|
122
124
|
assertNoFatalServerDiagnostics(options.file, streamOutput.diagnostics);
|
|
123
|
-
await loadServerStreamModule(streamOutput.code, options.file, options.serverModules, options.serverModuleCacheVersion);
|
|
125
|
+
await loadServerStreamModule(streamOutput.code, options.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
124
126
|
}
|
|
125
127
|
await preloadShellModulesForPage({
|
|
126
128
|
appDir: options.appDir,
|
|
@@ -128,6 +130,7 @@ async function preloadBuiltPageRouteModules(options) {
|
|
|
128
130
|
serverModules: options.serverModules,
|
|
129
131
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
130
132
|
serverSourceFiles: options.serverSourceFiles,
|
|
133
|
+
vitePlugins: options.vitePlugins,
|
|
131
134
|
});
|
|
132
135
|
if (!hasGenerateMetadataExport(options.code)) {
|
|
133
136
|
await loadComposedRouteMetadata({
|
|
@@ -159,7 +162,7 @@ async function preloadShellModulesForPage(options) {
|
|
|
159
162
|
serverOutput: "string",
|
|
160
163
|
});
|
|
161
164
|
assertNoFatalServerDiagnostics(shell.file, output.diagnostics);
|
|
162
|
-
await loadServerModule(output.code, shell.file, options.serverModules, options.serverModuleCacheVersion);
|
|
165
|
+
await loadServerModule(output.code, shell.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
function fatalServerDiagnostics(diagnostics) {
|
|
@@ -353,6 +356,7 @@ async function renderAppRequestInternal(options) {
|
|
|
353
356
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
354
357
|
serverSourceFiles: options.serverSourceFiles,
|
|
355
358
|
timing,
|
|
359
|
+
vitePlugins: options.vitePlugins,
|
|
356
360
|
});
|
|
357
361
|
finishRenderTimingPhase(timing, phaseStartedAt, "middlewareMs");
|
|
358
362
|
if (middlewareResult.type === "response") {
|
|
@@ -395,6 +399,7 @@ async function renderAppRequestInternal(options) {
|
|
|
395
399
|
serverModules: options.serverModules,
|
|
396
400
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
397
401
|
serverSourceFiles: options.serverSourceFiles,
|
|
402
|
+
vitePlugins: options.vitePlugins,
|
|
398
403
|
status: 404,
|
|
399
404
|
textFallback: "Not Found",
|
|
400
405
|
});
|
|
@@ -420,6 +425,7 @@ async function renderAppRequestInternal(options) {
|
|
|
420
425
|
serverModules: options.serverModules,
|
|
421
426
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
422
427
|
serverSourceFiles: options.serverSourceFiles,
|
|
428
|
+
vitePlugins: options.vitePlugins,
|
|
423
429
|
});
|
|
424
430
|
}
|
|
425
431
|
if (matched.route.kind === "server") {
|
|
@@ -432,6 +438,7 @@ async function renderAppRequestInternal(options) {
|
|
|
432
438
|
serverModules: options.serverModules,
|
|
433
439
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
434
440
|
serverSourceFiles: options.serverSourceFiles,
|
|
441
|
+
vitePlugins: options.vitePlugins,
|
|
435
442
|
});
|
|
436
443
|
}
|
|
437
444
|
// Issue 080: page routes render HTML for GET / HEAD only. Other
|
|
@@ -604,7 +611,7 @@ async function renderAppRequestInternal(options) {
|
|
|
604
611
|
params: matched.params,
|
|
605
612
|
queryClient,
|
|
606
613
|
request: options.request,
|
|
607
|
-
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion));
|
|
614
|
+
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins));
|
|
608
615
|
const pageHtml = renderedPage.html;
|
|
609
616
|
const pageHtmlForLayout = clientRoute
|
|
610
617
|
? withHydrationMarkers({
|
|
@@ -726,6 +733,7 @@ async function renderAppRequestInternal(options) {
|
|
|
726
733
|
serverModules: options.serverModules,
|
|
727
734
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
728
735
|
serverSourceFiles: options.serverSourceFiles,
|
|
736
|
+
vitePlugins: options.vitePlugins,
|
|
729
737
|
clientRouteInferenceCache,
|
|
730
738
|
script: clientScript,
|
|
731
739
|
clientReferenceManifest: output.metadata.clientReferenceManifest,
|
|
@@ -755,6 +763,7 @@ async function renderAppRequestInternal(options) {
|
|
|
755
763
|
serverModules: options.serverModules,
|
|
756
764
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
757
765
|
serverSourceFiles: options.serverSourceFiles,
|
|
766
|
+
vitePlugins: options.vitePlugins,
|
|
758
767
|
clientRouteInferenceCache,
|
|
759
768
|
clientRoute,
|
|
760
769
|
script: clientScript,
|
|
@@ -803,7 +812,7 @@ async function renderAppRequestInternal(options) {
|
|
|
803
812
|
params: matched.params,
|
|
804
813
|
queryClient,
|
|
805
814
|
request: options.request,
|
|
806
|
-
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, timing));
|
|
815
|
+
}, matched.route.file, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins, timing));
|
|
807
816
|
finishRenderTimingPhase(timing, phaseStartedAt, "pageRenderMs");
|
|
808
817
|
const pageHtml = renderedPage.html;
|
|
809
818
|
// Wrap the page (not the full document) with the hydration marker so
|
|
@@ -921,6 +930,7 @@ async function renderAppRequestInternal(options) {
|
|
|
921
930
|
serverModules: options.serverModules,
|
|
922
931
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
923
932
|
serverSourceFiles: options.serverSourceFiles,
|
|
933
|
+
vitePlugins: options.vitePlugins,
|
|
924
934
|
navigation: recoveryRoute,
|
|
925
935
|
status: 404,
|
|
926
936
|
textFallback: "Not Found",
|
|
@@ -944,6 +954,7 @@ async function renderAppRequestInternal(options) {
|
|
|
944
954
|
serverModules: options.serverModules,
|
|
945
955
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
946
956
|
serverSourceFiles: options.serverSourceFiles,
|
|
957
|
+
vitePlugins: options.vitePlugins,
|
|
947
958
|
navigation: recoveryRoute,
|
|
948
959
|
status: 500,
|
|
949
960
|
textFallback: error instanceof Error ? error.message : String(error),
|
|
@@ -1120,7 +1131,7 @@ async function renderSpecialRoute(options) {
|
|
|
1120
1131
|
routeId: routeIdForPath(options.routePath ?? new URL(options.request.url).pathname),
|
|
1121
1132
|
traceId: traceContextFromRequest(options.request)?.traceId,
|
|
1122
1133
|
};
|
|
1123
|
-
const pageHtml = await renderServerFileToHtml(options.routeFile, props, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles);
|
|
1134
|
+
const pageHtml = await renderServerFileToHtml(options.routeFile, props, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.vitePlugins);
|
|
1124
1135
|
const pageHtmlForLayout = options.navigation?.clientRoute === true
|
|
1125
1136
|
? withHydrationMarkers({
|
|
1126
1137
|
assetBaseUrl: options.assetBaseUrl,
|
|
@@ -1139,6 +1150,7 @@ async function renderSpecialRoute(options) {
|
|
|
1139
1150
|
serverModules: options.serverModules,
|
|
1140
1151
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1141
1152
|
serverSourceFiles: options.serverSourceFiles,
|
|
1153
|
+
vitePlugins: options.vitePlugins,
|
|
1142
1154
|
});
|
|
1143
1155
|
return new Response(`<!DOCTYPE html>${clientNavigationHeadTags({
|
|
1144
1156
|
assetBaseUrl: options.assetBaseUrl,
|
|
@@ -1149,7 +1161,7 @@ async function renderSpecialRoute(options) {
|
|
|
1149
1161
|
status: options.status,
|
|
1150
1162
|
});
|
|
1151
1163
|
}
|
|
1152
|
-
async function renderServerFileToHtml(file, props, serverModules, serverModuleCacheVersion, serverSourceFiles) {
|
|
1164
|
+
async function renderServerFileToHtml(file, props, serverModules, serverModuleCacheVersion, serverSourceFiles, vitePlugins) {
|
|
1153
1165
|
const code = await readServerSourceFile(file, serverModuleCacheVersion, serverSourceFiles);
|
|
1154
1166
|
const output = transformServerModule({
|
|
1155
1167
|
code,
|
|
@@ -1161,7 +1173,7 @@ async function renderServerFileToHtml(file, props, serverModules, serverModuleCa
|
|
|
1161
1173
|
if (fatalDiagnostics.length > 0) {
|
|
1162
1174
|
throw new Error(formatServerDiagnostics(file, fatalDiagnostics));
|
|
1163
1175
|
}
|
|
1164
|
-
return runServerModule(output.code, props, file, serverModules, serverModuleCacheVersion);
|
|
1176
|
+
return runServerModule(output.code, props, file, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1165
1177
|
}
|
|
1166
1178
|
function normalizeErrorForProps(error) {
|
|
1167
1179
|
if (error instanceof Error) {
|
|
@@ -1270,7 +1282,8 @@ async function dispatchMetadataRoute(options) {
|
|
|
1270
1282
|
return new Response("Invalid metadata route convention", { status: 500 });
|
|
1271
1283
|
}
|
|
1272
1284
|
async function loadServerRouteModule(options) {
|
|
1273
|
-
if (options.serverModuleCacheVersion === undefined
|
|
1285
|
+
if (options.serverModuleCacheVersion === undefined &&
|
|
1286
|
+
(options.vitePlugins === undefined || options.vitePlugins.length === 0)) {
|
|
1274
1287
|
return await importAppRouterFileModule(options.file);
|
|
1275
1288
|
}
|
|
1276
1289
|
const code = await readServerSourceFile(options.file, options.serverModuleCacheVersion, options.serverSourceFiles);
|
|
@@ -1286,7 +1299,7 @@ async function loadServerRouteModule(options) {
|
|
|
1286
1299
|
});
|
|
1287
1300
|
}
|
|
1288
1301
|
const moduleCode = artifactCode !== undefined && artifactCode.sourceHash === codeHash ? artifactCode.code : code;
|
|
1289
|
-
const cacheKey = `server-route\0${options.file}\0${options.serverModuleCacheVersion}\0${codeHash}\0${memoizedHashText(moduleCode)}`;
|
|
1302
|
+
const cacheKey = `server-route\0${options.file}\0${options.serverModuleCacheVersion}\0${codeHash}\0${memoizedHashText(moduleCode)}\0${vitePluginsCacheKey(options.vitePlugins)}`;
|
|
1290
1303
|
const cached = readRouterRuntimeCacheEntry(serverRouteModuleCache, cacheKey, serverRouteModuleCacheCounters);
|
|
1291
1304
|
if (cached !== undefined) {
|
|
1292
1305
|
return cached;
|
|
@@ -1297,6 +1310,7 @@ async function loadServerRouteModule(options) {
|
|
|
1297
1310
|
label: `server-route:${options.file}`,
|
|
1298
1311
|
...(moduleCode === code ? { resolveDir: dirname(options.file) } : {}),
|
|
1299
1312
|
sourcefile: options.file,
|
|
1313
|
+
vitePlugins: options.vitePlugins,
|
|
1300
1314
|
}).catch((error) => {
|
|
1301
1315
|
serverRouteModuleCache.delete(cacheKey);
|
|
1302
1316
|
throw error;
|
|
@@ -1341,6 +1355,7 @@ async function runMiddleware(options) {
|
|
|
1341
1355
|
serverModules: options.serverModules,
|
|
1342
1356
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1343
1357
|
serverSourceFiles: options.serverSourceFiles,
|
|
1358
|
+
vitePlugins: options.vitePlugins,
|
|
1344
1359
|
});
|
|
1345
1360
|
}
|
|
1346
1361
|
finally {
|
|
@@ -1439,7 +1454,7 @@ async function loadMiddlewareModule(options) {
|
|
|
1439
1454
|
(await readServerSourceFile(options.file, options.serverModuleCacheVersion, options.serverSourceFiles));
|
|
1440
1455
|
const cacheKey = options.serverModuleCacheVersion === undefined
|
|
1441
1456
|
? undefined
|
|
1442
|
-
: `middleware\0${options.appDir}\0${options.file}\0${options.serverModuleCacheVersion}\0${memoizedHashText(code)}\0${importPolicyCacheKey(options.importPolicy)}`;
|
|
1457
|
+
: `middleware\0${options.appDir}\0${options.file}\0${options.serverModuleCacheVersion}\0${memoizedHashText(code)}\0${importPolicyCacheKey(options.importPolicy)}\0${vitePluginsCacheKey(options.vitePlugins)}`;
|
|
1443
1458
|
if (cacheKey !== undefined) {
|
|
1444
1459
|
const cached = readRouterRuntimeCacheEntry(middlewareModuleCache, cacheKey, middlewareModuleCacheCounters);
|
|
1445
1460
|
if (cached !== undefined) {
|
|
@@ -1453,6 +1468,7 @@ async function loadMiddlewareModule(options) {
|
|
|
1453
1468
|
importPolicy: options.importPolicy,
|
|
1454
1469
|
prebuiltArtifact: prebuiltRequestModuleArtifact(options.serverModules, options.file, code),
|
|
1455
1470
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1471
|
+
vitePlugins: options.vitePlugins,
|
|
1456
1472
|
}).catch((error) => {
|
|
1457
1473
|
if (cacheKey !== undefined) {
|
|
1458
1474
|
middlewareModuleCache.delete(cacheKey);
|
|
@@ -1477,6 +1493,7 @@ export async function bundleMiddlewareModuleCode(options) {
|
|
|
1477
1493
|
label: "Middleware",
|
|
1478
1494
|
}),
|
|
1479
1495
|
],
|
|
1496
|
+
vitePlugins: options.vitePlugins,
|
|
1480
1497
|
});
|
|
1481
1498
|
const compiled = output.code;
|
|
1482
1499
|
if (compiled === undefined) {
|
|
@@ -1498,15 +1515,17 @@ async function loadBundledMiddlewareModule(options) {
|
|
|
1498
1515
|
code: options.code,
|
|
1499
1516
|
file: options.file,
|
|
1500
1517
|
importPolicy: options.importPolicy,
|
|
1518
|
+
vitePlugins: options.vitePlugins,
|
|
1501
1519
|
}));
|
|
1502
1520
|
return importAppRouterSourceModule({
|
|
1503
1521
|
...(options.serverModuleCacheVersion === undefined
|
|
1504
1522
|
? {}
|
|
1505
1523
|
: {
|
|
1506
|
-
cacheKey: `middleware:${options.file}:${options.serverModuleCacheVersion}:${memoizedHashText(compiled)}`,
|
|
1524
|
+
cacheKey: `middleware:${options.file}:${options.serverModuleCacheVersion}:${memoizedHashText(compiled)}:${vitePluginsCacheKey(options.vitePlugins)}`,
|
|
1507
1525
|
}),
|
|
1508
1526
|
code: compiled,
|
|
1509
1527
|
label: `middleware:${options.file}`,
|
|
1528
|
+
vitePlugins: options.vitePlugins,
|
|
1510
1529
|
});
|
|
1511
1530
|
}
|
|
1512
1531
|
function middlewareMatches(config, pathname) {
|
|
@@ -1671,13 +1690,13 @@ function memoizedHashText(code) {
|
|
|
1671
1690
|
codeHashCache.set(code, hash);
|
|
1672
1691
|
return hash;
|
|
1673
1692
|
}
|
|
1674
|
-
async function runServerModule(code, props, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1675
|
-
const component = await loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion);
|
|
1693
|
+
async function runServerModule(code, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
1694
|
+
const component = await loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1676
1695
|
return component(props);
|
|
1677
1696
|
}
|
|
1678
|
-
async function runServerModuleWithSlots(code, props, sourcefile, serverModules, serverModuleCacheVersion, timing) {
|
|
1697
|
+
async function runServerModuleWithSlots(code, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins, timing) {
|
|
1679
1698
|
const moduleLoadStartedAt = renderTimingPhaseStartedAt(timing);
|
|
1680
|
-
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion);
|
|
1699
|
+
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1681
1700
|
finishRenderTimingPhase(timing, moduleLoadStartedAt, "pageModuleLoadMs");
|
|
1682
1701
|
const component = selectServerComponent(module);
|
|
1683
1702
|
const componentStartedAt = renderTimingPhaseStartedAt(timing);
|
|
@@ -1691,7 +1710,7 @@ async function runServerModuleWithSlots(code, props, sourcefile, serverModules,
|
|
|
1691
1710
|
slots,
|
|
1692
1711
|
};
|
|
1693
1712
|
}
|
|
1694
|
-
async function loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1713
|
+
async function loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
1695
1714
|
const artifact = serverModules?.get(sourcefile)?.string;
|
|
1696
1715
|
const codeHash = memoizedHashText(code);
|
|
1697
1716
|
const prebuiltCode = prebuiltServerComponentModuleCode(artifact, code, codeHash);
|
|
@@ -1707,7 +1726,7 @@ async function loadServerModule(code, sourcefile, serverModules, serverModuleCac
|
|
|
1707
1726
|
const moduleCode = prebuiltCode ?? code;
|
|
1708
1727
|
const cacheKey = serverModuleCacheVersion === undefined
|
|
1709
1728
|
? undefined
|
|
1710
|
-
: `server-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}`;
|
|
1729
|
+
: `server-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}:${vitePluginsCacheKey(vitePlugins)}`;
|
|
1711
1730
|
return await importAppRouterSourceModule({
|
|
1712
1731
|
cacheKey,
|
|
1713
1732
|
code: moduleCode,
|
|
@@ -1719,10 +1738,12 @@ async function loadServerModule(code, sourcefile, serverModules, serverModuleCac
|
|
|
1719
1738
|
dev: serverModuleCacheVersion === undefined,
|
|
1720
1739
|
serverModules,
|
|
1721
1740
|
serverOutput: "string",
|
|
1741
|
+
vitePlugins,
|
|
1722
1742
|
},
|
|
1723
1743
|
}
|
|
1724
1744
|
: {}),
|
|
1725
1745
|
sourcefile,
|
|
1746
|
+
vitePlugins,
|
|
1726
1747
|
});
|
|
1727
1748
|
}
|
|
1728
1749
|
function prebuiltServerComponentModuleCode(artifact, code, codeHash) {
|
|
@@ -1747,8 +1768,8 @@ async function importBuiltServerModuleFile(options) {
|
|
|
1747
1768
|
file: options.file,
|
|
1748
1769
|
});
|
|
1749
1770
|
}
|
|
1750
|
-
async function loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1751
|
-
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion);
|
|
1771
|
+
async function loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
1772
|
+
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1752
1773
|
return selectServerComponent(module);
|
|
1753
1774
|
}
|
|
1754
1775
|
function selectServerComponent(module) {
|
|
@@ -1775,8 +1796,9 @@ function runServerStreamModule(code, options) {
|
|
|
1775
1796
|
props: options.props,
|
|
1776
1797
|
serverModules: options.serverModules,
|
|
1777
1798
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1799
|
+
vitePlugins: options.vitePlugins,
|
|
1778
1800
|
});
|
|
1779
|
-
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, options.props, slots, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache);
|
|
1801
|
+
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, options.props, slots, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.vitePlugins);
|
|
1780
1802
|
const marker = options.clientRoute
|
|
1781
1803
|
? hydrationMarkerParts({
|
|
1782
1804
|
assetBaseUrl: options.assetBaseUrl,
|
|
@@ -1800,7 +1822,7 @@ function runServerStreamModule(code, options) {
|
|
|
1800
1822
|
sink.append(shell.prefix);
|
|
1801
1823
|
}
|
|
1802
1824
|
sink.append(marker?.prefix ?? "");
|
|
1803
|
-
await appendServerStreamModule(code, sink, options.props, options.pageFile, options.serverModules, options.serverModuleCacheVersion);
|
|
1825
|
+
await appendServerStreamModule(code, sink, options.props, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
1804
1826
|
sink.append(marker?.suffix ?? "");
|
|
1805
1827
|
for (const shell of [...layoutShells].reverse()) {
|
|
1806
1828
|
sink.append(shell.suffix);
|
|
@@ -1909,8 +1931,8 @@ async function runServerStreamModuleWithLoading(code, options) {
|
|
|
1909
1931
|
queryClient: options.queryClient,
|
|
1910
1932
|
request: options.request,
|
|
1911
1933
|
};
|
|
1912
|
-
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, loadingProps, {}, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache);
|
|
1913
|
-
const loadingHtml = await renderServerFileToHtml(options.loadingFile, loadingProps, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles);
|
|
1934
|
+
const layoutShells = await layoutShellsForPage(options.appDir, options.pageFile, loadingProps, {}, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.clientRouteInferenceCache, options.vitePlugins);
|
|
1935
|
+
const loadingHtml = await renderServerFileToHtml(options.loadingFile, loadingProps, options.serverModules, options.serverModuleCacheVersion, options.serverSourceFiles, options.vitePlugins);
|
|
1914
1936
|
const marker = options.clientRoute
|
|
1915
1937
|
? hydrationMarkerParts({
|
|
1916
1938
|
assetBaseUrl: options.assetBaseUrl,
|
|
@@ -1940,7 +1962,7 @@ async function runServerStreamModuleWithLoading(code, options) {
|
|
|
1940
1962
|
params: options.params,
|
|
1941
1963
|
queryClient: options.queryClient,
|
|
1942
1964
|
request: options.request,
|
|
1943
|
-
}, options.pageFile, options.serverModules, options.serverModuleCacheVersion);
|
|
1965
|
+
}, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
1944
1966
|
}, {
|
|
1945
1967
|
placeholder(boundarySink) {
|
|
1946
1968
|
boundarySink.append(loadingHtml);
|
|
@@ -1979,8 +2001,8 @@ async function renderVisibleOutOfOrderFragment(sink, id, value, render, options)
|
|
|
1979
2001
|
await fragmentSink.drain();
|
|
1980
2002
|
sink.append(`<template data-mreact-oob-fragment="${escapeHtmlAttribute(id)}">${fragmentSink.toString()}</template>`);
|
|
1981
2003
|
}
|
|
1982
|
-
async function appendServerStreamModule(code, sink, props, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1983
|
-
const module = await loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion);
|
|
2004
|
+
async function appendServerStreamModule(code, sink, props, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
2005
|
+
const module = await loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
1984
2006
|
const component = selectStreamComponent(module);
|
|
1985
2007
|
await component(sink, props);
|
|
1986
2008
|
}
|
|
@@ -1988,7 +2010,7 @@ async function renderServerStreamSlots(code, options) {
|
|
|
1988
2010
|
if (!hasRouteSlotsExport(code)) {
|
|
1989
2011
|
return {};
|
|
1990
2012
|
}
|
|
1991
|
-
const module = await loadServerStreamModule(code, options.pageFile, options.serverModules, options.serverModuleCacheVersion);
|
|
2013
|
+
const module = await loadServerStreamModule(code, options.pageFile, options.serverModules, options.serverModuleCacheVersion, options.vitePlugins);
|
|
1992
2014
|
if (module.slots === undefined) {
|
|
1993
2015
|
return {};
|
|
1994
2016
|
}
|
|
@@ -2008,7 +2030,7 @@ async function renderServerStreamSlots(code, options) {
|
|
|
2008
2030
|
function hasRouteSlotsExport(code) {
|
|
2009
2031
|
return /^\s*export\s+const\s+slots\s*=/m.test(code);
|
|
2010
2032
|
}
|
|
2011
|
-
async function loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
2033
|
+
async function loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion, vitePlugins) {
|
|
2012
2034
|
const artifactCode = serverModules?.get(sourcefile)?.stream;
|
|
2013
2035
|
const codeHash = memoizedHashText(code);
|
|
2014
2036
|
const prebuiltCode = prebuiltServerComponentModuleCode(artifactCode, code, codeHash);
|
|
@@ -2024,7 +2046,7 @@ async function loadServerStreamModule(code, sourcefile, serverModules, serverMod
|
|
|
2024
2046
|
const moduleCode = prebuiltCode ?? code;
|
|
2025
2047
|
const cacheKey = serverModuleCacheVersion === undefined
|
|
2026
2048
|
? undefined
|
|
2027
|
-
: `server-stream-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}`;
|
|
2049
|
+
: `server-stream-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}:${vitePluginsCacheKey(vitePlugins)}`;
|
|
2028
2050
|
return await importAppRouterSourceModule({
|
|
2029
2051
|
cacheKey,
|
|
2030
2052
|
code: moduleCode,
|
|
@@ -2036,10 +2058,12 @@ async function loadServerStreamModule(code, sourcefile, serverModules, serverMod
|
|
|
2036
2058
|
dev: serverModuleCacheVersion === undefined,
|
|
2037
2059
|
serverModules,
|
|
2038
2060
|
serverOutput: "stream",
|
|
2061
|
+
vitePlugins,
|
|
2039
2062
|
},
|
|
2040
2063
|
}
|
|
2041
2064
|
: {}),
|
|
2042
2065
|
sourcefile,
|
|
2066
|
+
vitePlugins,
|
|
2043
2067
|
});
|
|
2044
2068
|
}
|
|
2045
2069
|
function selectStreamComponent(module) {
|
|
@@ -2074,12 +2098,12 @@ async function applyLayouts(options) {
|
|
|
2074
2098
|
await sink.drain();
|
|
2075
2099
|
return sink.toString();
|
|
2076
2100
|
}
|
|
2077
|
-
async function layoutShellsForPage(appDir, pageFile, props, slots, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache) {
|
|
2101
|
+
async function layoutShellsForPage(appDir, pageFile, props, slots, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, vitePlugins) {
|
|
2078
2102
|
const layoutFiles = await shellFilesForPage(appDir, pageFile, serverModuleCacheVersion);
|
|
2079
2103
|
const shells = [];
|
|
2080
2104
|
const slotContext = createSlotRenderContext(slots);
|
|
2081
2105
|
for (const shell of layoutFiles) {
|
|
2082
|
-
shells.push(await renderShellPrefixSuffix(appDir, shell, props, slotContext, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache));
|
|
2106
|
+
shells.push(await renderShellPrefixSuffix(appDir, shell, props, slotContext, serverModules, serverModuleCacheVersion, serverSourceFiles, clientRouteInferenceCache, undefined, vitePlugins));
|
|
2083
2107
|
}
|
|
2084
2108
|
warnUnconsumedRouteSlots({
|
|
2085
2109
|
appDir,
|
|
@@ -2093,7 +2117,7 @@ async function renderShellPrefixSuffix(appDir, shell, props, slotContext, server
|
|
|
2093
2117
|
const hasNamedSlots = Object.keys(slotContext.namedSlots).length > 0;
|
|
2094
2118
|
const cacheKey = serverModuleCacheVersion === undefined || hasNamedSlots || shell.kind === "template"
|
|
2095
2119
|
? undefined
|
|
2096
|
-
: `${appDir}\0${shell.file}\0${serverModuleCacheVersion}`;
|
|
2120
|
+
: `${appDir}\0${shell.file}\0${serverModuleCacheVersion}\0${vitePluginsCacheKey(vitePlugins)}`;
|
|
2097
2121
|
if (cacheKey !== undefined) {
|
|
2098
2122
|
const cached = readRouterRuntimeCacheEntry(renderedShellCache, cacheKey, renderedShellCacheCounters);
|
|
2099
2123
|
if (cached !== undefined && cached !== "impure") {
|
|
@@ -2137,8 +2161,8 @@ async function renderShellPrefixSuffix(appDir, shell, props, slotContext, server
|
|
|
2137
2161
|
}
|
|
2138
2162
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
2139
2163
|
const component = shellUsesAwait
|
|
2140
|
-
? selectStreamComponent(await loadServerStreamModule(output.code, shell.file, serverModules, serverModuleCacheVersion))
|
|
2141
|
-
: await loadServerComponent(output.code, shell.file, serverModules, serverModuleCacheVersion);
|
|
2164
|
+
? selectStreamComponent(await loadServerStreamModule(output.code, shell.file, serverModules, serverModuleCacheVersion, vitePlugins))
|
|
2165
|
+
: await loadServerComponent(output.code, shell.file, serverModules, serverModuleCacheVersion, vitePlugins);
|
|
2142
2166
|
addRenderTimingPhaseDuration(timing, phaseStartedAt, "layoutModuleLoadMs");
|
|
2143
2167
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
2144
2168
|
const layoutHtml = shellUsesAwait
|
|
@@ -2607,32 +2631,6 @@ function importPolicyCacheKey(policy) {
|
|
|
2607
2631
|
projectRoot: policy.projectRoot ?? "",
|
|
2608
2632
|
});
|
|
2609
2633
|
}
|
|
2610
|
-
function vitePluginsCacheKey(plugins) {
|
|
2611
|
-
if (plugins === undefined || plugins.length === 0) {
|
|
2612
|
-
return "";
|
|
2613
|
-
}
|
|
2614
|
-
return flattenVitePluginOptions(plugins)
|
|
2615
|
-
.map((plugin, index) => `${index}:${plugin.name ?? "<anonymous>"}`)
|
|
2616
|
-
.join("\0");
|
|
2617
|
-
}
|
|
2618
|
-
function flattenVitePluginOptions(options) {
|
|
2619
|
-
const plugins = [];
|
|
2620
|
-
for (const option of options) {
|
|
2621
|
-
if (Array.isArray(option)) {
|
|
2622
|
-
plugins.push(...flattenVitePluginOptions(option));
|
|
2623
|
-
continue;
|
|
2624
|
-
}
|
|
2625
|
-
if (option === false || option === null || option === undefined || typeof option === "string") {
|
|
2626
|
-
continue;
|
|
2627
|
-
}
|
|
2628
|
-
if (typeof option === "object" && "then" in option) {
|
|
2629
|
-
plugins.push({ name: "<async>" });
|
|
2630
|
-
continue;
|
|
2631
|
-
}
|
|
2632
|
-
plugins.push(option);
|
|
2633
|
-
}
|
|
2634
|
-
return plugins;
|
|
2635
|
-
}
|
|
2636
2634
|
async function loadRouteMetadata(options) {
|
|
2637
2635
|
if (!hasMetadataExport(options.code)) {
|
|
2638
2636
|
return undefined;
|