@skgo/sveltekit-adapter 0.32.0 → 0.32.1
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/package.json +1 -1
- package/skgo-adapter/entry.js +12 -7
- package/skgo-adapter/env.js +16 -21
package/package.json
CHANGED
package/skgo-adapter/entry.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { HandledHttpError } from '@sveltejs/kit/internal';
|
|
24
24
|
import * as devalue from 'skgo:devalue';
|
|
25
25
|
import { decoders, init_transport, parse } from 'skgo:kit/transport';
|
|
26
|
-
import {
|
|
26
|
+
import { componentLoaders, universalLoaders } from 'skgo:nodes';
|
|
27
27
|
import { transport } from 'skgo:hooks';
|
|
28
28
|
import { serialize_data } from 'skgo:kit/serialize-data';
|
|
29
29
|
import { create_universal_fetch } from 'skgo:kit/load-data';
|
|
@@ -227,13 +227,18 @@ async function build_props(req, url, event, state, fetched, serialized) {
|
|
|
227
227
|
};
|
|
228
228
|
|
|
229
229
|
const branch = req.branch ?? [];
|
|
230
|
-
const error_components = (req.error_components ?? []).map((i) =>
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
const error_components = await Promise.all((req.error_components ?? []).map(async (i) => {
|
|
231
|
+
try {
|
|
232
|
+
return i == null ? undefined : await componentLoaders[i]?.();
|
|
233
|
+
} catch {
|
|
234
|
+
// Kit skips error components that cannot load (runtime/error-chain.js).
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
}));
|
|
233
238
|
|
|
234
239
|
const props = new Props({
|
|
235
240
|
page,
|
|
236
|
-
tree: new RenderNode(
|
|
241
|
+
tree: new RenderNode(await componentLoaders[branch[0].node]?.(), undefined),
|
|
237
242
|
form,
|
|
238
243
|
error: req.error ?? undefined
|
|
239
244
|
});
|
|
@@ -243,7 +248,7 @@ async function build_props(req, url, event, state, fetched, serialized) {
|
|
|
243
248
|
|
|
244
249
|
for (let i = 0; i < branch.length; i += 1) {
|
|
245
250
|
const server_data = node_data(branch[i]);
|
|
246
|
-
const load =
|
|
251
|
+
const load = await universalLoaders[branch[i].node]?.();
|
|
247
252
|
const parent_data = data;
|
|
248
253
|
const result = load
|
|
249
254
|
? await with_request_store({ event, state }, () =>
|
|
@@ -270,7 +275,7 @@ async function build_props(req, url, event, state, fetched, serialized) {
|
|
|
270
275
|
|
|
271
276
|
if (i < branch.length - 1) {
|
|
272
277
|
current_node = current_node.child = new RenderNode(
|
|
273
|
-
|
|
278
|
+
await componentLoaders[branch[i + 1].node]?.(),
|
|
274
279
|
error_components[i + 1]
|
|
275
280
|
);
|
|
276
281
|
}
|
package/skgo-adapter/env.js
CHANGED
|
@@ -460,7 +460,7 @@ export function nodeTable(root, nodes) {
|
|
|
460
460
|
nodes.forEach((node, i) => {
|
|
461
461
|
if (node.universal) {
|
|
462
462
|
imports.push(`import * as U${i} from ${JSON.stringify(join(root, node.universal))};`);
|
|
463
|
-
loads.push(`U${i}.load`);
|
|
463
|
+
loads.push(`() => U${i}.load`);
|
|
464
464
|
} else {
|
|
465
465
|
loads.push('undefined');
|
|
466
466
|
}
|
|
@@ -469,9 +469,9 @@ export function nodeTable(root, nodes) {
|
|
|
469
469
|
return;
|
|
470
470
|
}
|
|
471
471
|
imports.push(`import N${i} from ${JSON.stringify(join(root, node.component))};`);
|
|
472
|
-
table.push(`N${i}`);
|
|
472
|
+
table.push(`() => N${i}`);
|
|
473
473
|
});
|
|
474
|
-
return `${imports.join('\n')}\nexport const
|
|
474
|
+
return `${imports.join('\n')}\nexport const componentLoaders = [${table.join(', ')}];\nexport const universalLoaders = [${loads.join(', ')}];\n`;
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
/**
|
|
@@ -613,26 +613,21 @@ function posix(p) {
|
|
|
613
613
|
*/
|
|
614
614
|
function devNodeTable(manifest, root) {
|
|
615
615
|
if (!manifest) throw new Error('skgo: the live Kit manifest is not ready');
|
|
616
|
-
|
|
617
|
-
const imports = [];
|
|
618
|
-
/** @type {string[]} */
|
|
619
|
-
const table = [];
|
|
616
|
+
const components = [];
|
|
620
617
|
const loads = [];
|
|
621
|
-
for (const
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
imports.push(`import N${index} from ${JSON.stringify(resolve(root, node.component))};`);
|
|
633
|
-
table.push(`N${index}`);
|
|
618
|
+
for (const node of manifest.nodes) {
|
|
619
|
+
// Kit's dev manifest supplies lazy component functions and resolves
|
|
620
|
+
// universal modules only when that node belongs to the requested page
|
|
621
|
+
// (exports/vite/dev/generate_manifest.js). Keep imports behind calls so
|
|
622
|
+
// bringing up the renderer cannot evaluate unrelated route modules.
|
|
623
|
+
components.push(node.component
|
|
624
|
+
? `() => import(${JSON.stringify(resolve(root, node.component))}).then(m => m.default)`
|
|
625
|
+
: 'undefined');
|
|
626
|
+
loads.push(node.universal
|
|
627
|
+
? `() => import(${JSON.stringify(resolve(root, node.universal))}).then(m => m.load)`
|
|
628
|
+
: 'undefined');
|
|
634
629
|
}
|
|
635
|
-
return
|
|
630
|
+
return `export const componentLoaders = [${components.join(', ')}];\nexport const universalLoaders = [${loads.join(', ')}];\n`;
|
|
636
631
|
}
|
|
637
632
|
|
|
638
633
|
/**
|