kit
kit copied to clipboard
`Fetch after load has returned` uneeded warning
Describe the bug
When doing two sequential fetch calls on +page.sever.ts in a streammed promise I get a warning
src/routes/+page.server.js: Calling `event.fetch(...)` in a promise handler after `load(...)` has returned will not cause the function to re-run when the dependency is invalidated
However this warning is unneeded as both call are inside an async function that will only return after both requests are done.
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-8f9xwa8z?file=src%2Froutes%2F%2Bpage.server.js
Here is the relevant code:
export const load = async ({ fetch }) => {
return {
character: loadData(fetch),
};
};
async function loadData(fetch) {
const res1 = await fetch('https://rickandmortyapi.com/api/character');
const charList = await res1.json();
console.log('Fetched char list with size ->', charList.results.length);
const res2 = await fetch(charList.results[0].url);
const char = await res2.json();
console.log('Fetched first Char -> ', char.name);
return char;
}
The warning will happen between the two console.log() but as explained before the function will only return after both calls are done thus I believe that the warning is not needed, as nothing was returned before the calls are done and thus there was no expectation regarding re-runs.
This also seems to happen if there is a Promise.all() with multiple fetchs.
Logs
Fetched char list with size -> 20
src/routes/+page.server.js: Calling `event.fetch(...)` in a promise handler after `load(...)` has returned will not cause the function to re-run when the dependency is invalidated
Fetched first Char -> Rick Sanchez
System Info
System:
OS: Linux 6.11 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
Memory: 17.41 GB / 31.05 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
pnpm: 10.8.1 - ~/.local/share/pnpm/pnpm
Browsers:
Chrome: 136.0.7103.92
npmPackages:
@sveltejs/adapter-auto: ^6.0.1 => 6.0.1
@sveltejs/kit: ^2.21.0 => 2.21.0
@sveltejs/vite-plugin-svelte: ^5.0.3 => 5.0.3
svelte: ^5.28.6 => 5.28.6
vite: ^6.3.5 => 6.3.5
Severity
annoyance
Additional Information
No response