From e0ad73196e17012fc0194990b5ab23396f5ae5b9 Mon Sep 17 00:00:00 2001 From: naoya7076 Date: Tue, 10 Jun 2025 21:33:01 +0900 Subject: [PATCH 1/4] fix: update state key references from 'key' to '__key' --- .../router/framework/react/guide/scroll-restoration.md | 4 ++-- packages/history/src/index.ts | 10 +++++----- packages/react-router/src/Match.tsx | 2 +- packages/router-core/src/router.ts | 6 +++--- packages/router-core/src/scroll-restoration.ts | 2 +- packages/solid-router/src/Match.tsx | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/router/framework/react/guide/scroll-restoration.md b/docs/router/framework/react/guide/scroll-restoration.md index ffc1387e10..88abd93cd2 100644 --- a/docs/router/framework/react/guide/scroll-restoration.md +++ b/docs/router/framework/react/guide/scroll-restoration.md @@ -71,7 +71,7 @@ Falling in behind Remix's own Scroll Restoration APIs, you can also customize th The `getKey` option receives the relevant `Location` state from TanStack Router and expects you to return a string to uniquely identify the scrollable measurements for that state. -The default `getKey` is `(location) => location.state.key!`, where `key` is the unique key generated for each entry in the history. +The default `getKey` is `(location) => location.state.__key!`, where `__key` is the unique key generated for each entry in the history. ## Examples @@ -95,7 +95,7 @@ const router = createRouter({ const paths = ['/', '/chat'] return paths.includes(location.pathname) ? location.pathname - : location.state.key! + : location.state.__key! }, }) ``` diff --git a/packages/history/src/index.ts b/packages/history/src/index.ts index 3428c41939..61b4784f6e 100644 --- a/packages/history/src/index.ts +++ b/packages/history/src/index.ts @@ -53,7 +53,7 @@ export interface ParsedPath { export interface HistoryState {} export type ParsedHistoryState = HistoryState & { - key?: string + __key?: string __TSR_index: number } @@ -254,7 +254,7 @@ function assignKeyAndIndex(index: number, state: HistoryState | undefined) { } return { ...state, - key: createRandomKey(), + __key: createRandomKey(), [stateIndexKey]: index, } as ParsedHistoryState } @@ -302,11 +302,11 @@ export function createBrowserHistory(opts?: { )) // Ensure there is always a key to start - if (!win.history.state?.key) { + if (!win.history.state?.__key) { win.history.replaceState( { [stateIndexKey]: 0, - key: createRandomKey(), + __key: createRandomKey(), }, '', ) @@ -632,7 +632,7 @@ export function parseHref( searchIndex > -1 ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex) : '', - state: state || { [stateIndexKey]: 0, key: createRandomKey() }, + state: state || { [stateIndexKey]: 0, __key: createRandomKey() }, } } diff --git a/packages/react-router/src/Match.tsx b/packages/react-router/src/Match.tsx index 79dd4ed01a..efc9dff395 100644 --- a/packages/react-router/src/Match.tsx +++ b/packages/react-router/src/Match.tsx @@ -139,7 +139,7 @@ function OnRendered() { return (