Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-brooms-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': major
---

breaking: stop awaiting top-level promises returned from load functions
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/write_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
const from = proxy.modified
? `./proxy${replace_ext_with_js(path.basename(file_path))}`
: path_to_original(outdir, file_path);
const type = `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}').load>>>`;
const type = `Awaited<ReturnType<typeof import('${from}').load>>`;
return expand ? `Expand<OptionalUnion<EnsureDefined<${type}>>>` : type;
} else {
return fallback;
Expand Down
5 changes: 0 additions & 5 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input ex
? input
: unknown;

export type AwaitedProperties<input extends Record<string, any> | void> =
AwaitedPropertiesUnion<input> extends Record<string, any>
? OptionalUnion<AwaitedPropertiesUnion<input>>
: AwaitedPropertiesUnion<input>;

export type AwaitedActions<T extends Record<string, (...args: any) => any>> = OptionalUnion<
{
[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]>>>;
Expand Down
2 changes: 0 additions & 2 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { base } from '__sveltekit/paths';
import * as devalue from 'devalue';
import { compact } from '../../utils/array.js';
import { validate_page_exports } from '../../utils/exports.js';
import { unwrap_promises } from '../../utils/promises.js';
import { HttpError, Redirect } from '../control.js';
import { INVALIDATED_PARAM, TRAILING_SLASH_PARAM, validate_depends } from '../shared.js';
import { INDEX_KEY, PRELOAD_PRIORITIES, SCROLL_KEY, SNAPSHOT_KEY } from './constants.js';
Expand Down Expand Up @@ -555,7 +554,6 @@ export function create_client(app, target) {
} else {
data = (await node.universal.load.call(null, load_input)) ?? null;
}
data = data ? await unwrap_promises(data, route.id) : null;
}

return {
Expand Down
5 changes: 2 additions & 3 deletions packages/kit/src/runtime/server/page/load_data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { disable_search, make_trackable } from '../../../utils/url.js';
import { unwrap_promises } from '../../../utils/promises.js';
import { DEV } from 'esm-env';
import { validate_depends } from '../../shared.js';

Expand Down Expand Up @@ -125,7 +124,7 @@ export async function load_server_data({
url
});

const data = result ? await unwrap_promises(result, node.server_id) : null;
const data = result ?? null;
if (__SVELTEKIT_DEV__) {
validate_load_response(data, node.server_id);
}
Expand Down Expand Up @@ -181,7 +180,7 @@ export async function load_data({
parent
});

const data = result ? await unwrap_promises(result, node.universal_id) : null;
const data = result ?? null;
if (__SVELTEKIT_DEV__) {
validate_load_response(data, node.universal_id);
}
Expand Down
61 changes: 0 additions & 61 deletions packages/kit/src/utils/promises.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function load({ fetch, url }) {
});

return {
a: r1.json(),
b: r2.json()
a: await r1.json(),
b: await r2.json()
};
}
4 changes: 2 additions & 2 deletions packages/kit/test/types/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Kit, { Deferred } from '@sveltejs/kit';
// Test: Return types inferred correctly and transformed into a union
type LoadReturn1 = { success: true } | { message: Promise<string> };

let result1: Kit.AwaitedProperties<LoadReturn1> = null as any;
let result1: LoadReturn1 = null as any;
result1.message = '';
result1.success = true;
// @ts-expect-error - cannot both be present at the same time
Expand All @@ -12,7 +12,7 @@ result1 = { message: '', success: true };
// Test: Return types keep promise for Deferred
type LoadReturn2 = { success: true } | Deferred<{ message: Promise<string>; eager: true }>;

let result2: Kit.AwaitedProperties<LoadReturn2> = null as any;
let result2: LoadReturn2 = null as any;
result2.message = Promise.resolve('');
result2.eager = true;
result2.success = true;
Expand Down