Skip to content

fix: allow anchor routing on custom standard schemes (#755) - #756

Open
saudademjj wants to merge 1 commit into
solidjs:mainfrom
saudademjj:saudademjj/fix-custom-scheme-anchor-links
Open

saudademjj wants to merge 1 commit into
solidjs:mainfrom
saudademjj:saudademjj/fix-custom-scheme-anchor-links

Conversation

@saudademjj

@saudademjj saudademjj commented Dec 1, 2026 •

Copy link
Copy Markdown

Fixes #755.

Problem

anchorUrl in src/data/events.ts previously restricted handled links to http: and https: (url.protocol !== "https:" && url.protocol !== "http:"), which was added in #581 to stop blob: URLs from slipping through the same-origin check (#382).

When an app is served from a custom standard scheme (such as Electron's app://example/ via protocol.registerSchemesAsPrivileged({ privileges: { standard: true } }), Tauri tauri://, or browser extensions), window.location.protocol is "app:" and window.location.origin is "app://example". Every internal anchor link therefore failed the hardcoded http:/https: check and fell back to a full page load.

Fix

Compare url.protocol against window.location.protocol instead of hardcoding http:/https:, while explicitly rejecting file:, blob:, and opaque "null" origins:

if (
  url.protocol !== window.location.protocol ||
  url.protocol === "file:" ||
  url.protocol === "blob:" ||
  url.origin === "null" ||
  url.origin !== window.location.origin ||
  !isUnderBase(url.pathname, basePath)
)
  return;
  • Internal links on custom standard schemes (e.g. app://example/about) share both protocol and a non-opaque origin with window.location, so both click navigation and link preloading work.
  • file: is rejected explicitly because Chromium/Electron serializes file:// URL and location origins as "file://" rather than "null", where history.pushState would throw SecurityError after preventDefault().
  • blob: is rejected explicitly so both blob: links on http(s):/app: pages (handleAnchor and blob links #382) and blob: links inside blob: documents are ignored.
  • mailto:, tel:, data:, javascript:, cross-scheme links, and opaque "null" origins continue to be ignored.

Tests & Verification

  • Added regression tests in test/data/events.spec.ts covering:
    • internal relative, absolute, and SVG links on a custom standard scheme (app://example/) — verified failing before the fix and passing after
    • basePath boundary matching on app://example/sub/
    • ignoring blob:app://example/..., mailto:, https://, and cross-origin app://other/ links on an app:// page
    • ignoring file:// links with both Chromium ("file://") and opaque ("null") origins
    • ignoring blob: links even inside a blob: document
  • pnpm test: 54 client test files (766 passed), 17 server test files (110 passed), tsc --project tsconfig.test.json clean
  • pnpm build: tsc, rollup -c, and check-fs-gate.mjs clean
  • prettier --check: clean
  • Changeset: @solidjs/router patch

Match url.protocol against window.location.protocol instead of hardcoding
http:/https:, while explicitly rejecting file:, blob:, and opaque "null"
origins. Custom standard schemes such as Electron's app:// now route
internally, whereas file:// links (whose origin Chromium serializes as
"file://" rather than "null"), blob: links (including inside blob:
documents), mailto:, and cross-scheme links remain ignored.

Fixes solidjs#755
@saudademjj
saudademjj force-pushed the saudademjj/fix-custom-scheme-anchor-links branch from 1e02395 to ea641df Compare December 1, 2026 19:40
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.

[2.0.1] Internal links do a full page load on a custom scheme (Electron app://)

1 participant