sveltejs / sveltejs/kit

Option to prerender 404 page

Open
#10,007 1 comment 19 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2-nice-to-have
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I am using the static adapter. The recommended way to generate a 404 page seems to be by using the fallback option, however, this option is meant to be used to generate a SPA, so it outputs a blank HTML page. I would like my 404 page to be prerendered.

Describe the proposed solution

I propose adding an option to adapter-static to generate a prerendered 404 page.

Alternatives considered

I tried simply creating 404/+page.svelte. There are two problems with this approach:

  1. It doesn't work during development, because the server renders +error.svelte.
  2. It doesn't work when serving the file from a subdirectory, because SvelteKit uses relative paths to assets.

Problem 1 can be solved by turning the 404 page into a component and rendering it in both 404/+page.svelte and +error.svelte.

Problem 2 can be solved by setting kit.paths.relative to false.

This feels quite hacky though.

Importance

nice to have

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 reviewing adapter-static's existing fallback behavior and the error/404 rendering paths described in the issue. Determine how a new option would fit both development rendering and deployment from a subdirectory. Done means adapter-static can emit a prerendered 404 page without requiring the proposed component duplication or relative-path workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.