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

Offen Anfängerfreundlich
#8,928 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@hassanabrar202 arbeitet bereits daran.

Seit 14.11.2026.

  • #8931 von @hassanabrar202 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
react, typescript
Bereich
frontend

Rechercherichtung

Der Fehler liegt in commitLocation, wo __tempLocation aus dem logischen Speicherort ohne führendes # aufgebaut wird, und in parseLocation, das ihn mit hash.slice(1) wieder einliest. Beginne damit, mit dem eigenständigen Skript aus dem Issue zu reproduzieren (Memory-History, maskierte Navigation mit einem Hash), und bestätige, dass der Hash bei jeder Navigation um ein Zeichen kürzer wird. Fertig ist, wenn der logische Hash über wiederholte Navigationen hinweg "anchor" bleibt, mit einem Regressionstest für maskierte Navigation mit Hash.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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}` : "",
Vorherrschende Sprache
TypeScript
Sterne
15.3k
Forks
1.9k
Ø Merge
1 T. 5 Std.
Gemergte PRs (30 T.)
46

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/router

Alle Issues in TanStack/router

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.