Skip to content

Commit 57f2027

Browse files
fix: warn when preload fails (#8985)
* fix: warn when preload fails closes #8301 * Apply suggestions from code review --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 9b212e6 commit 57f2027

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.changeset/loud-comics-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: warn after failed data preloads in dev

packages/kit/src/runtime/client/client.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,22 @@ export function create_client({ target }) {
12561256
if (!options.reload) {
12571257
if (priority <= options.preload_data) {
12581258
const intent = get_navigation_intent(/** @type {URL} */ (url), false);
1259-
if (intent) preload_data(intent);
1259+
if (intent) {
1260+
if (__SVELTEKIT_DEV__) {
1261+
preload_data(intent).then((result) => {
1262+
if (result.type === 'loaded' && result.state.error) {
1263+
console.warn(
1264+
`Preloading data for ${intent.url.pathname} failed with the following error: ${result.state.error.message}\n` +
1265+
'If this error is transient, you can ignore it. Otherwise, consider disabling preloading for this route. ' +
1266+
'This route was preloaded due to a data-sveltekit-preload-data attribute. ' +
1267+
'See https://kit.svelte.dev/docs/link-options for more info'
1268+
);
1269+
}
1270+
});
1271+
} else {
1272+
preload_data(intent);
1273+
}
1274+
}
12601275
} else if (priority <= options.preload_code) {
12611276
preload_code(get_url_path(/** @type {URL} */ (url)));
12621277
}

0 commit comments

Comments
 (0)