Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')

オープン 初心者向け
#8,928 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@hassanabrar202 がすでに取り組んでいます。

2026年11月14日 から。

  • #8931 @hassanabrar202 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
react, typescript
領域
frontend

調査の方向性

バグは commitLocation にあります。ここでは先頭の # を付けない論理的な位置から __tempLocation を構築しています。さらに parseLocation が hash.slice(1) でそれを読み戻しています。まず issue の単独スクリプト(メモリ履歴、ハッシュ付きのマスク付きナビゲーション)で再現し、ナビゲーションごとにハッシュが1文字ずつ short くなることを確認してください。論理ハッシュが繰り返しのナビゲーションを経ても "anchor" のまま残り、ハッシュを伴うマスク付きナビゲーションを対象とする回帰テストがあれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Which project does this relate to? Router

Describe the bug
A navigation with mask stores the real (logical) location in history.state.__tempLocation. commitLocation spreads the built location into it, whose hash has no leading # (buildLocation returns hash: hash ?? ""). parseLocation then reads __tempLocation back with decodePath(hash.slice(1)), so the logical hash loses its first character. An app that carries the current hash forward loses one more character per navigation: anchor -> nchor -> chor -> hor.

Your Example Website or App
Standalone script below (Node 22, @tanstack/react-router 1.169.2; same code in router-core 1.171.39).

Steps to Reproduce the Bug or Issue

import { createRouter, createRootRoute, createRoute, createMemoryHistory } from "@tanstack/react-router"
const root = createRootRoute()
const home = createRoute({ getParentRoute: () => root, path: "/" })
const chat = createRoute({ getParentRoute: () => root, path: "/chats/$chatId" })
const router = createRouter({ routeTree: root.addChildren([home, chat]), history: createMemoryHistory({ initialEntries: ["/"] }) })
await router.load()
let hash = "anchor"
for (let i = 1; i <= 3; i++) {
  void router.navigate({ to: "/", hash, mask: { to: "/chats/$chatId", params: { chatId: "c1" }, hash } })
  await new Promise((r) => setTimeout(r, 50))
  hash = router.parseLocation(router.history.location).hash
  console.log(i, JSON.stringify(hash))
}
// 1 "nchor"   2 "chor"   3 "hor"

Expected behavior
The logical location parsed back from a masked entry keeps its hash: "anchor" every time.

Suggested fix
In commitLocation, store the hash with its # in __tempLocation, as parse expects (it already does for history.location):

 __tempLocation: {
   ...nextHistory,
   search: nextHistory.searchStr,
+  hash: nextHistory.hash ? `#${nextHistory.hash}` : "",
主要言語
TypeScript
スター
15.3k
フォーク
1.9k
平均マージ
1日 5時間
マージ済み PR(30日)
46

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/router のほかの issue

TanStack/router の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。