@reckona/mreact-router 0.0.29 → 0.0.31
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/README.md +2 -2
- package/dist/adapters/aws-lambda.d.ts +1 -0
- package/dist/adapters/aws-lambda.d.ts.map +1 -1
- package/dist/adapters/aws-lambda.js +48 -15
- package/dist/adapters/aws-lambda.js.map +1 -1
- package/dist/build.d.ts +4 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +104 -5
- package/dist/build.js.map +1 -1
- package/dist/module-runner.d.ts +4 -0
- package/dist/module-runner.d.ts.map +1 -1
- package/dist/module-runner.js +16 -0
- package/dist/module-runner.js.map +1 -1
- package/dist/render.d.ts +5 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +136 -26
- package/dist/render.js.map +1 -1
- package/dist/serve.d.ts +2 -1
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +101 -19
- package/dist/serve.js.map +1 -1
- package/package.json +8 -8
package/dist/render.js
CHANGED
|
@@ -12,7 +12,7 @@ import { matchRoute, scanAppRoutes } from "./routes.js";
|
|
|
12
12
|
import { dispatchServerActionRequest, prepareRouteServerActions, serverActionCookie, } from "./actions.js";
|
|
13
13
|
import { beginRouteCacheContext, cachedRouteResponse, cacheRouteResponse, routeCacheKey, routeCachePolicyFromSource, } from "./cache.js";
|
|
14
14
|
import { resolveRouterCacheLimit } from "./cache-config.js";
|
|
15
|
-
import { importAppRouterFileModule, importAppRouterSourceModule } from "./module-runner.js";
|
|
15
|
+
import { importAppRouterBuiltFileModule, importAppRouterFileModule, importAppRouterSourceModule, } from "./module-runner.js";
|
|
16
16
|
import { contentSecurityPolicy } from "./csp.js";
|
|
17
17
|
import { htmlResponse } from "./http.js";
|
|
18
18
|
import { isNotFoundError, isRedirectError, rewriteLocation } from "./navigation.js";
|
|
@@ -239,6 +239,31 @@ function addRenderTimingPhaseDuration(timing, startedAt, phaseName) {
|
|
|
239
239
|
}
|
|
240
240
|
timing.phases[phaseName] = (timing.phases[phaseName] ?? 0) + logDurationMs(startedAt);
|
|
241
241
|
}
|
|
242
|
+
async function waitForRenderPreload(options, timing) {
|
|
243
|
+
if (options.preload?.wait !== "before-render") {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
247
|
+
try {
|
|
248
|
+
await options.preload.promise;
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
finishRenderTimingPhase(timing, phaseStartedAt, "preloadWaitMs");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async function loadServerRenderArtifacts(options, routeFile, timing) {
|
|
255
|
+
const loader = options.__mreactLoadServerRenderArtifacts;
|
|
256
|
+
if (loader === undefined) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
260
|
+
try {
|
|
261
|
+
await loader(routeFile);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
finishRenderTimingPhase(timing, phaseStartedAt, "renderArtifactLoadMs");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
242
267
|
function emitRenderTiming(options, timing, status) {
|
|
243
268
|
if (timing === undefined) {
|
|
244
269
|
return;
|
|
@@ -501,6 +526,8 @@ async function renderAppRequestInternal(options) {
|
|
|
501
526
|
emitRenderTiming(options, timing, data.status);
|
|
502
527
|
return data;
|
|
503
528
|
}
|
|
529
|
+
await waitForRenderPreload(options, timing);
|
|
530
|
+
await loadServerRenderArtifacts(options, matched.route.file, timing);
|
|
504
531
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
505
532
|
const stringOutput = transformServerModule({
|
|
506
533
|
code: routeCode,
|
|
@@ -598,6 +625,8 @@ async function renderAppRequestInternal(options) {
|
|
|
598
625
|
return streamData;
|
|
599
626
|
}
|
|
600
627
|
}
|
|
628
|
+
await waitForRenderPreload(options, timing);
|
|
629
|
+
await loadServerRenderArtifacts(options, matched.route.file, timing);
|
|
601
630
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
602
631
|
const output = transformServerModule({
|
|
603
632
|
code: routeCode,
|
|
@@ -683,6 +712,8 @@ async function renderAppRequestInternal(options) {
|
|
|
683
712
|
emitRenderTiming(options, timing, data.status);
|
|
684
713
|
return data;
|
|
685
714
|
}
|
|
715
|
+
await waitForRenderPreload(options, timing);
|
|
716
|
+
await loadServerRenderArtifacts(options, matched.route.file, timing);
|
|
686
717
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
687
718
|
const output = transformServerModule({
|
|
688
719
|
code: routeCode,
|
|
@@ -1073,6 +1104,13 @@ async function loadServerRouteModule(options) {
|
|
|
1073
1104
|
const code = await readServerSourceFile(options.file, options.serverModuleCacheVersion, options.serverSourceFiles);
|
|
1074
1105
|
const artifactCode = options.serverModules?.get(options.file)?.request;
|
|
1075
1106
|
const codeHash = memoizedHashText(code);
|
|
1107
|
+
if (artifactCode !== undefined && artifactCode.sourceHash === codeHash && artifactCode.moduleFile !== undefined) {
|
|
1108
|
+
return await importBuiltServerModuleFile({
|
|
1109
|
+
file: artifactCode.moduleFile,
|
|
1110
|
+
label: `server-route:${options.file}`,
|
|
1111
|
+
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1076
1114
|
const moduleCode = artifactCode !== undefined && artifactCode.sourceHash === codeHash ? artifactCode.code : code;
|
|
1077
1115
|
const cacheKey = `server-route\0${options.file}\0${options.serverModuleCacheVersion}\0${codeHash}\0${memoizedHashText(moduleCode)}`;
|
|
1078
1116
|
const cached = readRouterRuntimeCacheEntry(serverRouteModuleCache, cacheKey, serverRouteModuleCacheCounters);
|
|
@@ -1239,7 +1277,7 @@ async function loadMiddlewareModule(options) {
|
|
|
1239
1277
|
code,
|
|
1240
1278
|
file: options.file,
|
|
1241
1279
|
importPolicy: options.importPolicy,
|
|
1242
|
-
|
|
1280
|
+
prebuiltArtifact: prebuiltRequestModuleArtifact(options.serverModules, options.file, code),
|
|
1243
1281
|
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1244
1282
|
}).catch((error) => {
|
|
1245
1283
|
if (cacheKey !== undefined) {
|
|
@@ -1272,7 +1310,14 @@ export async function bundleMiddlewareModuleCode(options) {
|
|
|
1272
1310
|
return compiled;
|
|
1273
1311
|
}
|
|
1274
1312
|
async function loadBundledMiddlewareModule(options) {
|
|
1275
|
-
|
|
1313
|
+
if (options.prebuiltArtifact?.moduleFile !== undefined) {
|
|
1314
|
+
return await importBuiltServerModuleFile({
|
|
1315
|
+
file: options.prebuiltArtifact.moduleFile,
|
|
1316
|
+
label: `middleware:${options.file}`,
|
|
1317
|
+
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
const compiled = options.prebuiltArtifact?.code ??
|
|
1276
1321
|
(await bundleMiddlewareModuleCode({
|
|
1277
1322
|
appDir: options.appDir,
|
|
1278
1323
|
code: options.code,
|
|
@@ -1460,7 +1505,17 @@ async function runServerModuleWithSlots(code, props, sourcefile, serverModules,
|
|
|
1460
1505
|
async function loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1461
1506
|
const artifact = serverModules?.get(sourcefile)?.string;
|
|
1462
1507
|
const codeHash = memoizedHashText(code);
|
|
1463
|
-
const
|
|
1508
|
+
const prebuiltCode = prebuiltServerComponentModuleCode(artifact, code, codeHash);
|
|
1509
|
+
if (artifact !== undefined &&
|
|
1510
|
+
prebuiltServerModuleOutputMatches(artifact, code, codeHash) &&
|
|
1511
|
+
artifact.moduleFile !== undefined) {
|
|
1512
|
+
return await importBuiltServerModuleFile({
|
|
1513
|
+
file: artifact.moduleFile,
|
|
1514
|
+
label: `server-component:${sourcefile}`,
|
|
1515
|
+
serverModuleCacheVersion,
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
const moduleCode = prebuiltCode ?? code;
|
|
1464
1519
|
const cacheKey = serverModuleCacheVersion === undefined
|
|
1465
1520
|
? undefined
|
|
1466
1521
|
: `server-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}`;
|
|
@@ -1468,15 +1523,41 @@ async function loadServerModule(code, sourcefile, serverModules, serverModuleCac
|
|
|
1468
1523
|
cacheKey,
|
|
1469
1524
|
code: moduleCode,
|
|
1470
1525
|
label: `server-component:${sourcefile}`,
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1526
|
+
...(prebuiltCode === undefined
|
|
1527
|
+
? {
|
|
1528
|
+
resolveDir: dirname(sourcefile),
|
|
1529
|
+
serverSourceTransform: {
|
|
1530
|
+
dev: serverModuleCacheVersion === undefined,
|
|
1531
|
+
serverModules,
|
|
1532
|
+
serverOutput: "string",
|
|
1533
|
+
},
|
|
1534
|
+
}
|
|
1535
|
+
: {}),
|
|
1477
1536
|
sourcefile,
|
|
1478
1537
|
});
|
|
1479
1538
|
}
|
|
1539
|
+
function prebuiltServerComponentModuleCode(artifact, code, codeHash) {
|
|
1540
|
+
if (artifact === undefined) {
|
|
1541
|
+
return undefined;
|
|
1542
|
+
}
|
|
1543
|
+
if (!prebuiltServerModuleOutputMatches(artifact, code, codeHash)) {
|
|
1544
|
+
return undefined;
|
|
1545
|
+
}
|
|
1546
|
+
return artifact.bundleCode;
|
|
1547
|
+
}
|
|
1548
|
+
function prebuiltServerModuleOutputMatches(artifact, code, codeHash) {
|
|
1549
|
+
return artifact.sourceHash === codeHash || artifact.code === code;
|
|
1550
|
+
}
|
|
1551
|
+
async function importBuiltServerModuleFile(options) {
|
|
1552
|
+
return await importAppRouterBuiltFileModule({
|
|
1553
|
+
...(options.serverModuleCacheVersion === undefined
|
|
1554
|
+
? {}
|
|
1555
|
+
: {
|
|
1556
|
+
cacheKey: `${options.label}:${options.serverModuleCacheVersion}:${options.file}`,
|
|
1557
|
+
}),
|
|
1558
|
+
file: options.file,
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1480
1561
|
async function loadServerComponent(code, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1481
1562
|
const module = await loadServerModule(code, sourcefile, serverModules, serverModuleCacheVersion);
|
|
1482
1563
|
return selectServerComponent(module);
|
|
@@ -1740,7 +1821,17 @@ function hasRouteSlotsExport(code) {
|
|
|
1740
1821
|
async function loadServerStreamModule(code, sourcefile, serverModules, serverModuleCacheVersion) {
|
|
1741
1822
|
const artifactCode = serverModules?.get(sourcefile)?.stream;
|
|
1742
1823
|
const codeHash = memoizedHashText(code);
|
|
1743
|
-
const
|
|
1824
|
+
const prebuiltCode = prebuiltServerComponentModuleCode(artifactCode, code, codeHash);
|
|
1825
|
+
if (artifactCode !== undefined &&
|
|
1826
|
+
prebuiltServerModuleOutputMatches(artifactCode, code, codeHash) &&
|
|
1827
|
+
artifactCode.moduleFile !== undefined) {
|
|
1828
|
+
return await importBuiltServerModuleFile({
|
|
1829
|
+
file: artifactCode.moduleFile,
|
|
1830
|
+
label: `server-stream-component:${sourcefile}`,
|
|
1831
|
+
serverModuleCacheVersion,
|
|
1832
|
+
});
|
|
1833
|
+
}
|
|
1834
|
+
const moduleCode = prebuiltCode ?? code;
|
|
1744
1835
|
const cacheKey = serverModuleCacheVersion === undefined
|
|
1745
1836
|
? undefined
|
|
1746
1837
|
: `server-stream-component:${serverModuleCacheVersion}:${sourcefile}:${moduleCode === code ? codeHash : memoizedHashText(moduleCode)}`;
|
|
@@ -1748,12 +1839,16 @@ async function loadServerStreamModule(code, sourcefile, serverModules, serverMod
|
|
|
1748
1839
|
cacheKey,
|
|
1749
1840
|
code: moduleCode,
|
|
1750
1841
|
label: `server-stream-component:${sourcefile}`,
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1842
|
+
...(prebuiltCode === undefined
|
|
1843
|
+
? {
|
|
1844
|
+
resolveDir: dirname(sourcefile),
|
|
1845
|
+
serverSourceTransform: {
|
|
1846
|
+
dev: serverModuleCacheVersion === undefined,
|
|
1847
|
+
serverModules,
|
|
1848
|
+
serverOutput: "stream",
|
|
1849
|
+
},
|
|
1850
|
+
}
|
|
1851
|
+
: {}),
|
|
1757
1852
|
sourcefile,
|
|
1758
1853
|
});
|
|
1759
1854
|
}
|
|
@@ -2204,7 +2299,7 @@ async function loadRouteLoaderModule(options) {
|
|
|
2204
2299
|
}
|
|
2205
2300
|
const loaded = loadBundledRouteLoaderModule({
|
|
2206
2301
|
...options,
|
|
2207
|
-
|
|
2302
|
+
prebuiltArtifact: prebuiltRouteLoaderModuleArtifact(options.serverModules, options.filename, options.code),
|
|
2208
2303
|
}).catch((error) => {
|
|
2209
2304
|
if (cacheKey !== undefined) {
|
|
2210
2305
|
routeLoaderModuleCache.delete(cacheKey);
|
|
@@ -2236,7 +2331,14 @@ export async function bundleRouteLoaderModuleCode(options) {
|
|
|
2236
2331
|
return code;
|
|
2237
2332
|
}
|
|
2238
2333
|
async function loadBundledRouteLoaderModule(options) {
|
|
2239
|
-
|
|
2334
|
+
if (options.prebuiltArtifact?.moduleFile !== undefined) {
|
|
2335
|
+
return await importBuiltServerModuleFile({
|
|
2336
|
+
file: options.prebuiltArtifact.moduleFile,
|
|
2337
|
+
label: `loader:${options.filename}`,
|
|
2338
|
+
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
2339
|
+
});
|
|
2340
|
+
}
|
|
2341
|
+
const code = options.prebuiltArtifact?.code ??
|
|
2240
2342
|
(await bundleRouteLoaderModuleCode({
|
|
2241
2343
|
appDir: options.appDir,
|
|
2242
2344
|
code: options.code,
|
|
@@ -2253,17 +2355,17 @@ async function loadBundledRouteLoaderModule(options) {
|
|
|
2253
2355
|
label: `loader:${options.filename}`,
|
|
2254
2356
|
});
|
|
2255
2357
|
}
|
|
2256
|
-
function
|
|
2358
|
+
function prebuiltRequestModuleArtifact(serverModules, file, source, kind = "request") {
|
|
2257
2359
|
const artifact = serverModules?.get(file)?.[kind];
|
|
2258
2360
|
return artifact !== undefined && artifact.sourceHash === memoizedHashText(source)
|
|
2259
|
-
? artifact
|
|
2361
|
+
? artifact
|
|
2260
2362
|
: undefined;
|
|
2261
2363
|
}
|
|
2262
|
-
function
|
|
2364
|
+
function prebuiltRouteLoaderModuleArtifact(serverModules, file, source) {
|
|
2263
2365
|
const artifact = serverModules?.get(file)?.loader;
|
|
2264
2366
|
return artifact !== undefined && artifact.sourceHash === memoizedHashText(source)
|
|
2265
|
-
? artifact
|
|
2266
|
-
:
|
|
2367
|
+
? artifact
|
|
2368
|
+
: prebuiltRequestModuleArtifact(serverModules, file, source);
|
|
2267
2369
|
}
|
|
2268
2370
|
function importPolicyCacheKey(policy) {
|
|
2269
2371
|
if (policy === undefined) {
|
|
@@ -2279,8 +2381,16 @@ async function loadRouteMetadata(options) {
|
|
|
2279
2381
|
if (!hasMetadataExport(options.code)) {
|
|
2280
2382
|
return undefined;
|
|
2281
2383
|
}
|
|
2282
|
-
const
|
|
2283
|
-
|
|
2384
|
+
const prebuiltArtifact = prebuiltRequestModuleArtifact(options.serverModules, options.filename, options.code, "routeMetadata");
|
|
2385
|
+
if (prebuiltArtifact?.moduleFile !== undefined) {
|
|
2386
|
+
const module = await importBuiltServerModuleFile({
|
|
2387
|
+
file: prebuiltArtifact.moduleFile,
|
|
2388
|
+
label: `metadata:${options.filename}`,
|
|
2389
|
+
serverModuleCacheVersion: options.serverModuleCacheVersion,
|
|
2390
|
+
});
|
|
2391
|
+
return module.metadata;
|
|
2392
|
+
}
|
|
2393
|
+
const code = prebuiltArtifact?.code ?? await bundleRouteMetadataModuleCode(options);
|
|
2284
2394
|
const module = await importAppRouterSourceModule({
|
|
2285
2395
|
...(options.serverModuleCacheVersion === undefined
|
|
2286
2396
|
? {}
|