@sveltejs/kit 1.0.0-next.422 → 1.0.0-next.423
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
CHANGED
|
@@ -425,7 +425,7 @@ function process_node(ts, node, outdir, params, groups) {
|
|
|
425
425
|
written_proxies.push(write(`${outdir}/proxy${basename}`, proxy.code));
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
server_data = get_data_type(node.server, '
|
|
428
|
+
server_data = get_data_type(node.server, 'null', proxy);
|
|
429
429
|
server_load = `Kit.ServerLoad<${params}, ${get_parent_type('LayoutServerData')}, OutputData>`;
|
|
430
430
|
|
|
431
431
|
if (proxy) {
|
|
@@ -449,6 +449,8 @@ function process_node(ts, node, outdir, params, groups) {
|
|
|
449
449
|
server_data = 'null';
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
const parent_type = get_parent_type('LayoutData');
|
|
453
|
+
|
|
452
454
|
if (node.shared) {
|
|
453
455
|
const content = fs.readFileSync(node.shared, 'utf8');
|
|
454
456
|
const proxy = tweak_types(ts, content, shared_names);
|
|
@@ -456,29 +458,32 @@ function process_node(ts, node, outdir, params, groups) {
|
|
|
456
458
|
written_proxies.push(write(`${outdir}/proxy${path.basename(node.shared)}`, proxy.code));
|
|
457
459
|
}
|
|
458
460
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
+
const type = get_data_type(node.shared, `${parent_type} & ${server_data}`, proxy);
|
|
462
|
+
|
|
463
|
+
data = `Omit<${parent_type}, keyof ${type}> & ${type}`;
|
|
464
|
+
load = `Kit.Load<${params}, ${server_data}, ${parent_type}, OutputData>`;
|
|
465
|
+
} else if (server_data === 'null') {
|
|
466
|
+
data = parent_type;
|
|
461
467
|
} else {
|
|
462
|
-
data = server_data
|
|
468
|
+
data = `Omit<${parent_type}, keyof ${server_data}> & ${server_data}`;
|
|
463
469
|
}
|
|
464
470
|
|
|
465
471
|
return { data, server_data, load, server_load, errors, written_proxies };
|
|
466
472
|
|
|
467
473
|
/**
|
|
468
474
|
* @param {string} file_path
|
|
469
|
-
* @param {string} method
|
|
470
475
|
* @param {string} fallback
|
|
471
476
|
* @param {Proxy} proxy
|
|
472
477
|
*/
|
|
473
|
-
function get_data_type(file_path,
|
|
478
|
+
function get_data_type(file_path, fallback, proxy) {
|
|
474
479
|
if (proxy) {
|
|
475
|
-
if (proxy.exports.includes(
|
|
480
|
+
if (proxy.exports.includes('load')) {
|
|
476
481
|
// If the file wasn't tweaked, we can use the return type of the original file.
|
|
477
482
|
// The advantage is that type updates are reflected without saving.
|
|
478
483
|
const from = proxy.modified
|
|
479
484
|
? `./proxy${replace_ext_with_js(path.basename(file_path))}`
|
|
480
485
|
: path_to_original(outdir, file_path);
|
|
481
|
-
return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}')
|
|
486
|
+
return `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}').load>>>`;
|
|
482
487
|
} else {
|
|
483
488
|
return fallback;
|
|
484
489
|
}
|
|
@@ -403,10 +403,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
403
403
|
let data = {};
|
|
404
404
|
let data_changed = false;
|
|
405
405
|
for (let i = 0; i < filtered.length; i += 1) {
|
|
406
|
-
|
|
406
|
+
data = { ...data, ...filtered[i].data };
|
|
407
407
|
// Only set props if the node actually updated. This prevents needless rerenders.
|
|
408
|
-
if (!current.branch.some((node) => node === filtered[i])) {
|
|
409
|
-
result.props[`data_${i}`] =
|
|
408
|
+
if (data_changed || !current.branch.some((node) => node === filtered[i])) {
|
|
409
|
+
result.props[`data_${i}`] = data;
|
|
410
410
|
data_changed = true;
|
|
411
411
|
}
|
|
412
412
|
}
|
|
@@ -83,18 +83,31 @@ export async function render_response({
|
|
|
83
83
|
navigating: writable(null),
|
|
84
84
|
updated
|
|
85
85
|
},
|
|
86
|
-
/** @type {import('types').Page} */
|
|
87
|
-
page: {
|
|
88
|
-
error,
|
|
89
|
-
params: /** @type {Record<string, any>} */ (event.params),
|
|
90
|
-
routeId: event.routeId,
|
|
91
|
-
status,
|
|
92
|
-
url: state.prerendering ? new PrerenderingURL(event.url) : event.url,
|
|
93
|
-
data: branch.reduce((acc, { data }) => (Object.assign(acc, data), acc), {})
|
|
94
|
-
},
|
|
95
86
|
components: await Promise.all(branch.map(({ node }) => node.component()))
|
|
96
87
|
};
|
|
97
88
|
|
|
89
|
+
let data = {};
|
|
90
|
+
|
|
91
|
+
// props_n (instead of props[n]) makes it easy to avoid
|
|
92
|
+
// unnecessary updates for layout components
|
|
93
|
+
for (let i = 0; i < branch.length; i += 1) {
|
|
94
|
+
data = { ...data, ...branch[i].data };
|
|
95
|
+
props[`data_${i}`] = data;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
props.page = {
|
|
99
|
+
error,
|
|
100
|
+
params: /** @type {Record<string, any>} */ (event.params),
|
|
101
|
+
routeId: event.routeId,
|
|
102
|
+
status,
|
|
103
|
+
url: state.prerendering ? new PrerenderingURL(event.url) : event.url,
|
|
104
|
+
data
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (validation_errors) {
|
|
108
|
+
props.errors = validation_errors;
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
// TODO remove this for 1.0
|
|
99
112
|
/**
|
|
100
113
|
* @param {string} property
|
|
@@ -112,16 +125,6 @@ export async function render_response({
|
|
|
112
125
|
print_error('path', 'pathname');
|
|
113
126
|
print_error('query', 'searchParams');
|
|
114
127
|
|
|
115
|
-
// props_n (instead of props[n]) makes it easy to avoid
|
|
116
|
-
// unnecessary updates for layout components
|
|
117
|
-
for (let i = 0; i < branch.length; i += 1) {
|
|
118
|
-
props[`data_${i}`] = branch[i].data;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (validation_errors) {
|
|
122
|
-
props.errors = validation_errors;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
128
|
rendered = options.root.render(props);
|
|
126
129
|
|
|
127
130
|
for (const { node } of branch) {
|