SvelteKit generates `__data.json` request even if `+page.*` does not export a `load` function
Describe the bug
A SvelteKit application makes a request to __data/json even when no actual load function gets exported inside +page.server.js.
I would expect that no unnecessary request gets made as it should be clear to SvelteKit that it can't fetch any data from that endpoint.
Someone could argue if an empty +page.server.ts file makes sense at all.
Maybe SvelteKit should throw an error if it sees that a +page.server.ts file does not export anything that is useful to SvelteKit.
I could imagine there will be some users that create a load function, but forget to export it. In this case an error message would be really helpful before they have to figure out what they did wrong.
Of course this would make sense for all other +*.ts files
Reproduction
Repo: https://stackblitz.com/edit/sveltejs-kit-template-default-djcepj?file=src/routes/test/+page.server.ts
- start the application
- hover over the link
- check the logs, a request to
/test/__data.jsonwas made, even if+page,server,tsdoes not export aloadfunction
Logs
No response
System Info
StackBlitz
Severity
annoyance
Additional Information
No response
I've just come across the same issue. In my case, I use +page.server.ts to exports actions but don't need a server-side load function.
I've worked around it by moving the actions to a dedicated route that results in a 404 if accessed via GET.
Thanks!
It would be great if SvelteKit detected these cases during build, f.e. when building as a static website, and printed a helpful message that a *.server.ts files don't work with static builds, etc.
(SvelteKit 1.7.2 here)