Cannot use server-only files in an app with `router.type === 'hash': when prerendering +server.ts file
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
If you set router: { type: 'hash' } } in svelte.config.js, then you cannot have any +server files, not even prerendered ones.
The use case is that I'm building a static app using adapter-static and serving a prerendered manifest.json file via src/routes/manifest.json/+server.ts, which looks roughly like this:
import { json } from '@sveltejs/kit';
import type { WebAppManifest } from 'web-app-manifest';
import type { RequestHandler } from './$types';
export const prerender = true;
const manifest: WebAppManifest = {
theme_color: '#020817', // hsl(222, 84%, 5%)
...
};
export const GET: RequestHandler = async () => {
return json(manifest);
};
This works fine with the default router but not with the hash router. I understand the difficulties of hash routing but perhaps there is some way to make an exception for adapter-static and +server.ts files, because prerendering static data as part of applications are not uncommon, especially with adapter-static.
Reproduction
Run npm run dev or try building the below branch of the project:
Logs
System Info
-
Severity
serious, but I can work around it
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running npm run dev and building the reproduction branch linked in the issue with router: { type: 'hash' } in svelte.config.js. Inspect how src/routes/manifest.json/+server.ts is handled during prerendering with adapter-static and compare it with the default router. Done means the prerendered endpoint works with the hash router without breaking hash-based application routing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100