@reckona/mreact-router 0.0.185 → 0.0.186
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/render.d.ts.map +1 -1
- package/dist/render.js +24 -0
- package/dist/render.js.map +1 -1
- package/dist/route-loader-runtime.d.ts +1 -0
- package/dist/route-loader-runtime.d.ts.map +1 -1
- package/dist/route-loader-runtime.js +2 -0
- package/dist/route-loader-runtime.js.map +1 -1
- package/package.json +11 -11
- package/src/render.ts +35 -0
- package/src/route-loader-runtime.ts +3 -0
|
@@ -17,6 +17,7 @@ export declare function loadRouteDataFromModule(options: {
|
|
|
17
17
|
context: RouteDataContext;
|
|
18
18
|
hasLoader: boolean;
|
|
19
19
|
loadModule(): Promise<RouteLoaderModule>;
|
|
20
|
+
onLoaderReady?: (() => void) | undefined;
|
|
20
21
|
timing?: RouteLoaderRuntimeTiming | undefined;
|
|
21
22
|
}): Promise<unknown>;
|
|
22
23
|
//# sourceMappingURL=route-loader-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-loader-runtime.d.ts","sourceRoot":"","sources":["../src/route-loader-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC;CACjD;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,mBAAmB,GAAG,oBAAo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C,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BnB"}
|
|
@@ -11,9 +11,11 @@ export async function loadRouteDataFromModule(options) {
|
|
|
11
11
|
options.timing?.finish(moduleLoadStartedAt, "loaderModuleLoadMs");
|
|
12
12
|
}
|
|
13
13
|
if (module.loader === undefined) {
|
|
14
|
+
options.onLoaderReady?.();
|
|
14
15
|
return undefined;
|
|
15
16
|
}
|
|
16
17
|
const executionStartedAt = options.timing?.start();
|
|
18
|
+
options.onLoaderReady?.();
|
|
17
19
|
try {
|
|
18
20
|
return await module.loader(options.context);
|
|
19
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-loader-runtime.js","sourceRoot":"","sources":["../src/route-loader-runtime.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,
|
|
1
|
+
{"version":3,"file":"route-loader-runtime.js","sourceRoot":"","sources":["../src/route-loader-runtime.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAM7C;IACC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,MAAyB,CAAC;IAC9B,MAAM,mBAAmB,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACpD,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACnD,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;IAC1B,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;IAClE,CAAC;AACH,CAAC","sourcesContent":["import type { QueryClient } from \"@reckona/mreact-query\";\nimport type { RouteParams } from \"./types.js\";\n\nexport interface RouteDataContext {\n env?: unknown;\n params: RouteParams;\n queryClient: QueryClient;\n request: Request;\n}\n\nexport interface RouteLoaderModule {\n loader?: (context: RouteDataContext) => unknown;\n}\n\nexport interface RouteLoaderRuntimeTiming {\n finish(startedAt: number | undefined, phase: \"loaderExecutionMs\" | \"loaderModuleLoadMs\"): void;\n start(): number | undefined;\n}\n\nexport async function loadRouteDataFromModule(options: {\n context: RouteDataContext;\n hasLoader: boolean;\n loadModule(): Promise<RouteLoaderModule>;\n onLoaderReady?: (() => void) | undefined;\n timing?: RouteLoaderRuntimeTiming | undefined;\n}): Promise<unknown> {\n if (!options.hasLoader) {\n return undefined;\n }\n\n let module: RouteLoaderModule;\n const moduleLoadStartedAt = options.timing?.start();\n try {\n module = await options.loadModule();\n } finally {\n options.timing?.finish(moduleLoadStartedAt, \"loaderModuleLoadMs\");\n }\n\n if (module.loader === undefined) {\n options.onLoaderReady?.();\n return undefined;\n }\n\n const executionStartedAt = options.timing?.start();\n options.onLoaderReady?.();\n try {\n return await module.loader(options.context);\n } catch (error) {\n if (error instanceof Response) {\n return error;\n }\n\n throw error;\n } finally {\n options.timing?.finish(executionStartedAt, \"loaderExecutionMs\");\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reckona/mreact-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.186",
|
|
4
4
|
"description": "File-system app router, SSR, actions, and deployment adapters for mreact.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jsx",
|
|
@@ -105,20 +105,20 @@
|
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
107
|
"typescript": "^6.0.3",
|
|
108
|
-
"@reckona/mreact": "0.0.
|
|
109
|
-
"@reckona/mreact-compat": "0.0.
|
|
110
|
-
"@reckona/mreact-compiler": "0.0.
|
|
111
|
-
"@reckona/mreact-
|
|
112
|
-
"@reckona/mreact-
|
|
113
|
-
"@reckona/mreact-
|
|
114
|
-
"@reckona/mreact-reactive-dom": "0.0.
|
|
115
|
-
"@reckona/mreact-
|
|
116
|
-
"@reckona/mreact-
|
|
108
|
+
"@reckona/mreact": "0.0.186",
|
|
109
|
+
"@reckona/mreact-compat": "0.0.186",
|
|
110
|
+
"@reckona/mreact-compiler": "0.0.186",
|
|
111
|
+
"@reckona/mreact-query": "0.0.186",
|
|
112
|
+
"@reckona/mreact-devtools": "0.0.186",
|
|
113
|
+
"@reckona/mreact-reactive-core": "0.0.186",
|
|
114
|
+
"@reckona/mreact-reactive-dom": "0.0.186",
|
|
115
|
+
"@reckona/mreact-shared": "0.0.186",
|
|
116
|
+
"@reckona/mreact-server": "0.0.186"
|
|
117
117
|
},
|
|
118
118
|
"peerDependencies": {
|
|
119
119
|
"vite": ">=8 <9"
|
|
120
120
|
},
|
|
121
121
|
"optionalDependencies": {
|
|
122
|
-
"@reckona/mreact-router-native": "0.0.
|
|
122
|
+
"@reckona/mreact-router-native": "0.0.186"
|
|
123
123
|
}
|
|
124
124
|
}
|
package/src/render.ts
CHANGED
|
@@ -715,6 +715,34 @@ async function readSettledPromiseAtNextTask<T>(
|
|
|
715
715
|
]);
|
|
716
716
|
}
|
|
717
717
|
|
|
718
|
+
function createDeferredSignal(): {
|
|
719
|
+
promise: Promise<void>;
|
|
720
|
+
resolve(): void;
|
|
721
|
+
} {
|
|
722
|
+
let resolve: (() => void) | undefined;
|
|
723
|
+
const promise = new Promise<void>((innerResolve) => {
|
|
724
|
+
resolve = innerResolve;
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
return {
|
|
728
|
+
promise,
|
|
729
|
+
resolve() {
|
|
730
|
+
resolve?.();
|
|
731
|
+
},
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
async function waitForLoaderReadyOrSettled(
|
|
736
|
+
dataPromise: Promise<unknown>,
|
|
737
|
+
loaderReady: Promise<void> | undefined,
|
|
738
|
+
): Promise<void> {
|
|
739
|
+
if (loaderReady === undefined) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
await Promise.race([loaderReady, dataPromise.then(() => undefined, () => undefined)]);
|
|
744
|
+
}
|
|
745
|
+
|
|
718
746
|
function addRenderTimingPhaseDuration(
|
|
719
747
|
timing: RenderTiming | undefined,
|
|
720
748
|
startedAt: number | undefined,
|
|
@@ -1087,6 +1115,7 @@ async function renderAppRequestInternal(
|
|
|
1087
1115
|
const clientInference = routeAnalysis.clientInference;
|
|
1088
1116
|
const clientRoute = clientInference.client;
|
|
1089
1117
|
phaseStartedAt = renderTimingPhaseStartedAt(timing);
|
|
1118
|
+
const loaderReady = routeAnalysis.hasLoader ? createDeferredSignal() : undefined;
|
|
1090
1119
|
const dataPromise = routeAnalysis.hasLoader
|
|
1091
1120
|
? loadRouteDataWithInstrumentation({
|
|
1092
1121
|
appDir: options.appDir,
|
|
@@ -1109,6 +1138,7 @@ async function renderAppRequestInternal(
|
|
|
1109
1138
|
define: options.define,
|
|
1110
1139
|
vitePlugins: options.vitePlugins,
|
|
1111
1140
|
timing,
|
|
1141
|
+
onLoaderReady: loaderReady?.resolve,
|
|
1112
1142
|
})
|
|
1113
1143
|
: undefined;
|
|
1114
1144
|
finishRenderTimingPhase(timing, phaseStartedAt, "loaderStartMs");
|
|
@@ -1316,6 +1346,8 @@ async function renderAppRequestInternal(
|
|
|
1316
1346
|
return settledData.value;
|
|
1317
1347
|
}
|
|
1318
1348
|
streamDataPromise = Promise.resolve(settledData.value);
|
|
1349
|
+
} else {
|
|
1350
|
+
await waitForLoaderReadyOrSettled(streamDataPromise, loaderReady?.promise);
|
|
1319
1351
|
}
|
|
1320
1352
|
} finally {
|
|
1321
1353
|
finishRenderTimingPhase(timing, phaseStartedAt, "loaderWaitMs");
|
|
@@ -4466,6 +4498,7 @@ async function loadRouteData(options: {
|
|
|
4466
4498
|
devServerModuleCacheVersion?: string | undefined;
|
|
4467
4499
|
filename: string;
|
|
4468
4500
|
importPolicy?: AppRouterImportPolicy | undefined;
|
|
4501
|
+
onLoaderReady?: (() => void) | undefined;
|
|
4469
4502
|
serverModules?: ReadonlyMap<string, BuiltServerModuleArtifact> | undefined;
|
|
4470
4503
|
serverModuleCacheVersion?: string | undefined;
|
|
4471
4504
|
timing?: RenderTiming | undefined;
|
|
@@ -4475,6 +4508,7 @@ async function loadRouteData(options: {
|
|
|
4475
4508
|
context: options.context,
|
|
4476
4509
|
hasLoader: hasLoaderExport(options.code),
|
|
4477
4510
|
loadModule: () => loadRouteLoaderModule(options),
|
|
4511
|
+
onLoaderReady: options.onLoaderReady,
|
|
4478
4512
|
timing: {
|
|
4479
4513
|
finish(startedAt, phase) {
|
|
4480
4514
|
finishRenderTimingPhase(options.timing, startedAt, phase);
|
|
@@ -4495,6 +4529,7 @@ async function loadRouteDataWithInstrumentation(options: {
|
|
|
4495
4529
|
filename: string;
|
|
4496
4530
|
importPolicy?: AppRouterImportPolicy | undefined;
|
|
4497
4531
|
instrumentation?: RouterInstrumentation | undefined;
|
|
4532
|
+
onLoaderReady?: (() => void) | undefined;
|
|
4498
4533
|
request: Request;
|
|
4499
4534
|
routeId: string;
|
|
4500
4535
|
routePath: string;
|
|
@@ -21,6 +21,7 @@ export async function loadRouteDataFromModule(options: {
|
|
|
21
21
|
context: RouteDataContext;
|
|
22
22
|
hasLoader: boolean;
|
|
23
23
|
loadModule(): Promise<RouteLoaderModule>;
|
|
24
|
+
onLoaderReady?: (() => void) | undefined;
|
|
24
25
|
timing?: RouteLoaderRuntimeTiming | undefined;
|
|
25
26
|
}): Promise<unknown> {
|
|
26
27
|
if (!options.hasLoader) {
|
|
@@ -36,10 +37,12 @@ export async function loadRouteDataFromModule(options: {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
if (module.loader === undefined) {
|
|
40
|
+
options.onLoaderReady?.();
|
|
39
41
|
return undefined;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
const executionStartedAt = options.timing?.start();
|
|
45
|
+
options.onLoaderReady?.();
|
|
43
46
|
try {
|
|
44
47
|
return await module.loader(options.context);
|
|
45
48
|
} catch (error) {
|