@tanstack/react-router 1.12.9 → 1.12.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  import * as React from 'react';
2
2
  import { Router } from './router';
3
- export declare let routerContext: React.Context<Router<any, Record<string, any>, Record<string, any>>>;
3
+ export declare function getRouterContext(): React.Context<Router<any, Record<string, any>, Record<string, any>>>;
@@ -1,13 +1,16 @@
1
1
  import * as React from "react";
2
2
  let routerContext = React.createContext(null);
3
- if (typeof document !== "undefined") {
3
+ function getRouterContext() {
4
+ if (typeof document === "undefined") {
5
+ return routerContext;
6
+ }
4
7
  if (window.__TSR_ROUTER_CONTEXT__) {
5
- routerContext = window.__TSR_ROUTER_CONTEXT__;
6
- } else {
7
- window.__TSR_ROUTER_CONTEXT__ = routerContext;
8
+ return window.__TSR_ROUTER_CONTEXT__;
8
9
  }
10
+ window.__TSR_ROUTER_CONTEXT__ = routerContext;
11
+ return routerContext;
9
12
  }
10
13
  export {
11
- routerContext
14
+ getRouterContext
12
15
  };
13
16
  //# sourceMappingURL=routerContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"routerContext.js","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Router } from './router'\n\nexport let routerContext = React.createContext<Router<any>>(null!)\nif (typeof document !== 'undefined') {\n if (window.__TSR_ROUTER_CONTEXT__) {\n routerContext = window.__TSR_ROUTER_CONTEXT__\n } else {\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n }\n}\n"],"names":[],"mappings":";AAGW,IAAA,gBAAgB,MAAM,cAA2B,IAAK;AACjE,IAAI,OAAO,aAAa,aAAa;AACnC,MAAI,OAAO,wBAAwB;AACjC,oBAAgB,OAAO;AAAA,EAAA,OAClB;AACL,WAAO,yBAAyB;AAAA,EAClC;AACF;"}
1
+ {"version":3,"file":"routerContext.js","sources":["../../src/routerContext.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Router } from './router'\n\nlet routerContext = React.createContext<Router<any>>(null!)\n\nexport function getRouterContext() {\n if (typeof document === 'undefined') {\n return routerContext\n }\n\n if (window.__TSR_ROUTER_CONTEXT__) {\n return window.__TSR_ROUTER_CONTEXT__\n }\n\n window.__TSR_ROUTER_CONTEXT__ = routerContext as any\n\n return routerContext\n}\n"],"names":[],"mappings":";AAGA,IAAI,gBAAgB,MAAM,cAA2B,IAAK;AAEnD,SAAS,mBAAmB;AAC7B,MAAA,OAAO,aAAa,aAAa;AAC5B,WAAA;AAAA,EACT;AAEA,MAAI,OAAO,wBAAwB;AACjC,WAAO,OAAO;AAAA,EAChB;AAEA,SAAO,yBAAyB;AAEzB,SAAA;AACT;"}
@@ -1,9 +1,8 @@
1
1
  import * as React from "react";
2
2
  import warning from "tiny-warning";
3
- import { routerContext } from "./routerContext.js";
3
+ import { getRouterContext } from "./routerContext.js";
4
4
  function useRouter(opts) {
5
- const resolvedContext = typeof document !== "undefined" ? window.__TSR_ROUTER_CONTEXT__ || routerContext : routerContext;
6
- const value = React.useContext(resolvedContext);
5
+ const value = React.useContext(getRouterContext());
7
6
  warning(
8
7
  !(((opts == null ? void 0 : opts.warn) ?? true) && !value),
9
8
  "useRouter must be used inside a <RouterProvider> component!"
@@ -1 +1 @@
1
- {"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router } from './router'\nimport { routerContext } from './routerContext'\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(opts?: { warn?: boolean }): Router<TRouteTree> {\n const resolvedContext =\n typeof document !== 'undefined'\n ? window.__TSR_ROUTER_CONTEXT__ || routerContext\n : routerContext\n const value = React.useContext(resolvedContext)\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,UAEd,MAA+C;AAC/C,QAAM,kBACJ,OAAO,aAAa,cAChB,OAAO,0BAA0B,gBACjC;AACA,QAAA,QAAQ,MAAM,WAAW,eAAe;AAC9C;AAAA,IACE,IAAG,6BAAM,SAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEK,SAAA;AACT;"}
1
+ {"version":3,"file":"useRouter.js","sources":["../../src/useRouter.tsx"],"sourcesContent":["import * as React from 'react'\nimport warning from 'tiny-warning'\nimport { AnyRoute } from './route'\nimport { RegisteredRouter, Router } from './router'\nimport { getRouterContext } from './routerContext'\n\nexport function useRouter<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n>(opts?: { warn?: boolean }): Router<TRouteTree> {\n const value = React.useContext(getRouterContext())\n warning(\n !((opts?.warn ?? true) && !value),\n 'useRouter must be used inside a <RouterProvider> component!',\n )\n return value as any\n}\n"],"names":[],"mappings":";;;AAMO,SAAS,UAEd,MAA+C;AAC/C,QAAM,QAAQ,MAAM,WAAW,iBAAkB,CAAA;AACjD;AAAA,IACE,IAAG,6BAAM,SAAQ,SAAS,CAAC;AAAA,IAC3B;AAAA,EAAA;AAEK,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
- "version": "1.12.9",
3
+ "version": "1.12.11",
4
4
  "description": "",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@ import { pick, useLayoutEffect } from './utils'
10
10
  import { RouteMatch } from './Matches'
11
11
  import { useRouter } from './useRouter'
12
12
  import { useRouterState } from './useRouterState'
13
- import { routerContext } from './routerContext'
13
+ import { getRouterContext } from './routerContext'
14
14
 
15
15
  const useTransition =
16
16
  React.useTransition ||
@@ -78,6 +78,8 @@ export function RouterProvider<
78
78
  <Matches />
79
79
  )
80
80
 
81
+ const routerContext = getRouterContext()
82
+
81
83
  const provider = (
82
84
  <routerContext.Provider value={router}>
83
85
  {matches}
@@ -197,10 +199,10 @@ function Transitioner() {
197
199
  ])
198
200
 
199
201
  useLayoutEffect(() => {
200
- if (window.__TSR_DEHYDRATED__) return
201
202
  if (
202
- mountLoadForRouter.current.router === router &&
203
- mountLoadForRouter.current.mounted
203
+ window.__TSR_DEHYDRATED__ ||
204
+ (mountLoadForRouter.current.router === router &&
205
+ mountLoadForRouter.current.mounted)
204
206
  ) {
205
207
  return
206
208
  }
package/src/path.ts CHANGED
@@ -220,7 +220,9 @@ export function matchByPath(
220
220
  if (routeSegment) {
221
221
  if (routeSegment.type === 'wildcard') {
222
222
  if (baseSegment?.value) {
223
- const _splat = joinPaths(baseSegments.slice(i).map((d) => d.value))
223
+ const _splat = decodeURI(
224
+ joinPaths(baseSegments.slice(i).map((d) => d.value)),
225
+ )
224
226
  // TODO: Deprecate *
225
227
  params['*'] = _splat
226
228
  params['_splat'] = _splat
@@ -257,7 +259,9 @@ export function matchByPath(
257
259
  return false
258
260
  }
259
261
  if (baseSegment.value.charAt(0) !== '$') {
260
- params[routeSegment.value.substring(1)] = baseSegment.value
262
+ params[routeSegment.value.substring(1)] = decodeURI(
263
+ baseSegment.value,
264
+ )
261
265
  }
262
266
  }
263
267
  }
package/src/router.ts CHANGED
@@ -509,13 +509,14 @@ export class Router<
509
509
  state,
510
510
  }: HistoryLocation): ParsedLocation<FullSearchSchema<TRouteTree>> => {
511
511
  const parsedSearch = this.options.parseSearch(search)
512
+ const searchStr = this.options.stringifySearch(parsedSearch)
512
513
 
513
514
  return {
514
515
  pathname: pathname,
515
- searchStr: search,
516
+ searchStr,
516
517
  search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
517
518
  hash: hash.split('#').reverse()[0] ?? '',
518
- href: `${pathname}${search}${hash}`,
519
+ href: `${pathname}${searchStr}${hash}`,
519
520
  state: replaceEqualDeep(previousLocation?.state, state) as HistoryState,
520
521
  }
521
522
  }
@@ -1,11 +1,18 @@
1
1
  import * as React from 'react'
2
2
  import { Router } from './router'
3
3
 
4
- export let routerContext = React.createContext<Router<any>>(null!)
5
- if (typeof document !== 'undefined') {
4
+ let routerContext = React.createContext<Router<any>>(null!)
5
+
6
+ export function getRouterContext() {
7
+ if (typeof document === 'undefined') {
8
+ return routerContext
9
+ }
10
+
6
11
  if (window.__TSR_ROUTER_CONTEXT__) {
7
- routerContext = window.__TSR_ROUTER_CONTEXT__
8
- } else {
9
- window.__TSR_ROUTER_CONTEXT__ = routerContext as any
12
+ return window.__TSR_ROUTER_CONTEXT__
10
13
  }
14
+
15
+ window.__TSR_ROUTER_CONTEXT__ = routerContext as any
16
+
17
+ return routerContext
11
18
  }
package/src/useRouter.tsx CHANGED
@@ -2,16 +2,12 @@ import * as React from 'react'
2
2
  import warning from 'tiny-warning'
3
3
  import { AnyRoute } from './route'
4
4
  import { RegisteredRouter, Router } from './router'
5
- import { routerContext } from './routerContext'
5
+ import { getRouterContext } from './routerContext'
6
6
 
7
7
  export function useRouter<
8
8
  TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
9
9
  >(opts?: { warn?: boolean }): Router<TRouteTree> {
10
- const resolvedContext =
11
- typeof document !== 'undefined'
12
- ? window.__TSR_ROUTER_CONTEXT__ || routerContext
13
- : routerContext
14
- const value = React.useContext(resolvedContext)
10
+ const value = React.useContext(getRouterContext())
15
11
  warning(
16
12
  !((opts?.warn ?? true) && !value),
17
13
  'useRouter must be used inside a <RouterProvider> component!',