Skip to content

fix: add handleInvalidUrl prerender option for non-HTTP URL schemes#16088

Merged
Rich-Harris merged 2 commits into
sveltejs:mainfrom
Zelys-DFKH:fix/prerender-invalid-url-handler
Jun 22, 2026
Merged

fix: add handleInvalidUrl prerender option for non-HTTP URL schemes#16088
Rich-Harris merged 2 commits into
sveltejs:mainfrom
Zelys-DFKH:fix/prerender-invalid-url-handler

Conversation

@Zelys-DFKH

Copy link
Copy Markdown
Contributor

closes #15935

When SvelteKit's prerender crawler encounters a URL scheme it cannot parse — like an AT Protocol URL (at://did:plc:...) — calling new URL(href, base) throws an unhandled TypeError and crashes the build. Since the AT Protocol identifier syntax embeds colons inside the host segment, WHATWG URL parsing interprets the part after the first colon as an invalid port number.

This adds a handleInvalidUrl option to config.prerender, following the same normalise_error_handler pattern already used by handleHttpError, handleMissingId, and handleUnseenRoutes. The default behavior throws with a message pointing users to the docs. Setting it to 'warn' or 'ignore' lets a build continue, and a custom function receives { href, referrer, message }.

The crawl function now collects URLs that throw into an invalid[] array instead of crashing immediately, and prerender.js iterates that array to invoke the configured handler for each one.

Thanks to @Rich-Harris for proposing this exact design in #15935.

Fixes sveltejs#15935

URLs with non-standard schemes (e.g. AT Protocol `at://did:plc:...` used
for Bluesky identity verification via `<link rel="me">`) throw
`TypeError: Invalid URL` inside the prerender crawler, crashing the build
with an unhelpful stack trace and no way to suppress the failure.

The crawler now catches URL parse errors and collects the raw href values
in an `invalid` array returned alongside `ids` and `hrefs`. The prerender
runner routes each one through a new `handleInvalidUrl` handler (default
`'fail'`) that follows the same `'fail' | 'warn' | 'ignore' | function`
pattern as `handleHttpError` and friends, including a helpful error message
pointing to the config option.
@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b1a0367

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 Minor

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

Comment thread .changeset/fix-prerender-invalid-url-19c21cbf9730.md Outdated
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
@Rich-Harris Rich-Harris merged commit cf15fa0 into sveltejs:main Jun 22, 2026
42 of 44 checks passed
@Rich-Harris

Copy link
Copy Markdown
Member

thank you!

@github-actions github-actions Bot mentioned this pull request Jun 22, 2026
Rich-Harris pushed a commit that referenced this pull request Jun 22, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @sveltejs/kit@2.67.0

### Minor Changes


- feat: add `prerender.handleInvalidUrl` option for invalid URLs
discovered while crawling
([#16088](#16088))


### Patch Changes


- fix: support `exactOptionalPropertyTypes` for optional form schema
fields ([#15866](#15866))


- fix: avoid unnecessarily overriding a user's Vite 8 `codeSplitting`
setting ([#16118](#16118))
## @sveltejs/adapter-node@5.5.6

### Patch Changes


- fix: avoid circular dependency between server initialisation and hook
retrieval that causes the app to crash on start
([#16115](#16115))


- fix: correctly resolve root directory on the server
([#16114](#16114))


- fix: ensure `ENV_PREFIX` is defined
([#16106](#16106))

- Updated dependencies
[[`cf15fa0`](cf15fa0),
[`5c76121`](5c76121),
[`2992e17`](2992e17)]:
  - @sveltejs/kit@2.67.0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions Bot mentioned this pull request Jun 22, 2026
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.

at:// link in svelte:head gives error in pre-render mode

4 participants