Skip to content

fix: correct relative paths on error page for a missing __data.json request#15884

Open
ATOM00blue wants to merge 1 commit into
sveltejs:mainfrom
ATOM00blue:fix-data-suffix-relative-paths
Open

fix: correct relative paths on error page for a missing __data.json request#15884
ATOM00blue wants to merge 1 commit into
sveltejs:mainfrom
ATOM00blue:fix-data-suffix-relative-paths

Conversation

@ATOM00blue
Copy link
Copy Markdown

closes #11353

When a non-existent page is requested with the __data.json suffix (e.g. /example/__data.json), the suffix is stripped from the URL before routing so that the path can be matched against the route table. The error page that is rendered for the resulting 404 then computed its relative asset paths from that stripped URL, which is one path segment shallower than the URL the browser is actually at. As a result the _app/immutable/... links (and the resolve/asset helpers from $app/paths) ended up one directory too shallow, so the error page loaded unstyled and without its scripts.

For example, requesting /example/__data.json produced asset links that resolved to /example/_app/... instead of /_app/....

This re-adds the data suffix when computing the relative path depth in both the error page renderer and $app/paths' resolve/asset, so the paths are resolved against the URL the browser is actually at. Root-level requests (/__data.json) and the .html__data.json form are unaffected because the reconstructed path has the same segment depth as the original request.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

…ssing __data.json request

When a non-existent page is requested with the `__data.json` suffix, the
suffix is stripped from the URL before routing. The error page that gets
rendered computed its relative asset paths from that stripped URL, so the
paths ended up one directory too shallow and failed to load the app's
assets in the browser.

Account for the data suffix when computing the relative path depth in both
the error page renderer and `$app/paths`' `resolve`/`asset`, so the paths
are resolved against the URL the browser is actually at.
Copilot AI review requested due to automatic review settings May 22, 2026 03:00
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: 83cf4cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-existent __data.json pages link to broken relative paths

2 participants