SPA initial route stays pending with `basepath` under Tauri’s (or any other) custom protocol
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- react, typescript, vite
- 領域
- frontend
調査の方向性
Start in packages/router-core/src/router.ts around the origin handling near line 131 and the URL classification/buildLocation path near line 2596. Reproduce with the linked minimal repo, then compare buildLocation() output under http:// versus tauri:// with a non-root basepath, focusing on whether publicHref becomes absolute and external flips true. Done means the initial route loads under the custom protocol with the basepath preserved, with a regression test covering custom-protocol origins.
索引モデルが issue の本文から書いたものです。
説明
Which project does this relate to?
Router
Describe the bug
A TanStack Start SPA works when served over HTTP, but its initial index route remains pending when the same build is loaded through Tauri’s tauri:// protocol with a non-root base path.
JavaScript executes, React mounts, and state updates work. The index route has no loader, beforeLoad, or data fetching. However, the initial router.load() is never called under Tauri.
Removing the base path fixes startup. Normalizing buildLocation() output to a relative publicHref and setting external: false also fixes it while preserving the base path.
I think it's worth fixing because not only tauri is affected, but any custom webview-like solution with non-http loader (eg. electron uses file://)
Complete minimal reproducer
https://github.com/kpostekk/tanstack-router-protocol-basepath-issue-20261115
Steps to Reproduce the Bug
-
Build the SPA with the configuration above.
-
Serve the output at http://localhost:7644/app-x/ - the index route renders. This can be modified in tauri.conf.json
-
Load the same output through Tauri at tauri://localhost:7644/app-x/ - the root shell renders, but the index route remains pending.
-
Remove Vite base and router basepath, rebuild, and load at tauri://localhost:7644/: the index route renders.
Expected behavior
The initial route should load under the custom protocol with a base path, as it does over HTTP and under the custom protocol without a base path.
Actual behavior
The router remains in this state:
{
"status": "idle",
"pathname": "/",
"matches": [
{ "routeId": "__root__", "status": "success" },
{ "routeId": "/", "status": "pending" }
]
}
Instrumenting router.load() shows:
-
HTTP: called with { sync: true }; both matches become successful.
-
Tauri: no initial call.
-
Manual router.invalidate(): the index route renders successfully.
URL comparison
I compared router.latestLocation with:
router.buildLocation({
to: '/',
search: true,
hash: true,
})
const router = useRouter()
useEffect(() => {
const current = router.latestLocation
const generated = router.buildLocation({
to: '/',
search: true,
hash: true,
})
console.log('[URL comparison]', {
browser: window.location.href,
basepath: router.options.basepath,
origin: router.options.origin,
currentHref: current.href,
currentPublicHref: current.publicHref,
generatedHref: generated.href,
generatedPublicHref: generated.publicHref,
})
}, [router])
Results:
| Value | HTTP | Tauri |
|---|---|---|
| Browser URL | http://localhost:7644/app-x/ |
tauri://localhost:7644/app-x/ |
router.options.basepath |
"app-x" |
"app-x" |
Current href |
/ |
/ |
Current publicHref |
/app-x/ |
/app-x/ |
Generated href |
/app-x/ |
/app-x/ |
Generated publicHref |
/app-x/ |
tauri://localhost:7644/app-x/ |
In the Tauri webview, both location.origin and new URL(location.href).origin return tauri://localhost:7644, rather than "null".
Explicitly setting the router’s origin to window.location.origin did not resolve the issue.
Suspected source
These locations look relevant to the origin handling and generated URL classification:
My suspicion is that the rewrite path used by basepath produces an absolute URL or classifies the location as external under the custom protocol, affecting startup. I have not confirmed the exact failing condition.
Working workaround
Wrapping buildLocation() immediately after router creation fixes startup:
if (
typeof window !== 'undefined' &&
window.location.protocol === 'tauri:'
) {
const buildLocation = router.buildLocation.bind(router)
router.buildLocation = ((...args) => {
const location = buildLocation(...args)
const url = new URL(location.publicHref, window.location.href)
if (
url.protocol === window.location.protocol &&
url.host === window.location.host
) {
return {
...location,
publicHref: `${url.pathname}${url.search}${url.hash}`,
external: false,
}
}
return location
}) as typeof router.buildLocation
}
This changes both publicHref and external; I have not isolated which change is necessary.
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.169.5
- OS: Linux Fedora 45
- Browser: Webkit2gtk-4.1
- Browser Version: 605.1.15
- Bundler: vite
- Bundler Version: 8.3.8
Additional context
- The route chunk imports successfully.
- React state updates work in the root shell.
- Removing the outer
ClientOnlywrapper does not help. - Removing React Compiler does not help.
- The issue occurs with a trivial index component and no route loaders.
- 主要言語
- TypeScript
- スター
- 15.3k
- フォーク
- 1.9k
- 平均マージ
- 1日 5時間
- マージ済み PR(30日)
- 46
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/router のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')対応中かも @hassanabrar202 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)対応中かも @Sheraff が 27 日前に担当しました。 オープンpackage: router-generator performance
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
router-generator: sibling `physical()` subtrees in a virtual route config generate duplicate identifiers対応中かも @Sheraff が 27 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
docs(router): clarify static title fallback in SPA mode対応中かも @Rohan-Dedhia が 17 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
TanStack/router の issue をすべて見る
似ている issue
-
[BUG]: Shared links drop the configured basePath on GitHub Pages対応中かも @anshulchikhale30-p が今日担当しました。 オープンbug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add: GTrekkerオープンcheck:passed streams:add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
メンテナーはふだん 1 日以内に返信
-
area: ui Bug Payload OSS
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
payloadcms/payload#19839 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
メンテナーはふだん 1 日以内に返信