Skip to content
Source
Sign inSign up
TanStack/router

fix(devtools-core): never throw when serializing search params for history tracking or display #8769

OpenA-Raphie(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/8769/headopened

Showing 3 changed files with 130 additions and 3 deletions.

x
0 of 3 viewed, 3 left
23 additions and 3 deletionspackages/router-devtools-core/src/BaseTanStackRouterDevtoolsPanel.tsxModified
View file
@@ -73,6 +73,26 @@
​
const HISTORY_LIMIT = 15
​
+/**
+ * JSON.stringify, but never throws on values JSON cannot serialize
+ * (e.g. bigint search params produced by a custom `stringifySearch`).
+ */
+export function stringifySearchValue(search: unknown): string {
+ return JSON.stringify(search, (_key, value) =>
+ typeof value === 'bigint' ? value.toString() : value,
+ )
+}
+​
+/**
+ * Type-aware serialization for comparing searches: bigint values are tagged,
+ * so `1n`, the string `'1'` and the number `1` never compare equal.
+ */
+export function serializeSearchForComparison(search: unknown): string {
+ return JSON.stringify(search, (_key, value) =>
+ typeof value === 'bigint' ? ['bigint', value.toString()] : value,
+ )
+}
+​
function Logo(props: any) {
const { className, ...rest } = props
const styles = useStyles()
@@ -331,8 +351,8 @@