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

Aperta Adatta ai principianti
#8,928 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@hassanabrar202 ci sta già lavorando.

Dal 14/11/2026.

  • #8931 di @hassanabrar202 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Il bug si trova in commitLocation, dove __tempLocation viene costruito dalla posizione logica senza un # iniziale, e in parseLocation, che lo rilegge con hash.slice(1). Inizia riproducendolo con lo script autonomo presente nell'issue (history in memoria, navigazione mascherata con un hash) e verifica che l'hash si accorci di un carattere a ogni navigazione. È completato quando l'hash logico resta "anchor" dopo navigazioni ripetute, con un test di regressione che copra la navigazione mascherata con hash.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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}` : "",
Lingua principale
TypeScript
Stelle
15.3k
Fork
1.9k
Merge medio
1g 5h
PR unite (30g)
46

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/router

Tutte le issue di TanStack/router

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.