sveltejs / sveltejs/kit

Cannot use server-only files in an app with `router.type === 'hash': when prerendering +server.ts file

Open
#13,652 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

router
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.