@tanstack/react-router 1.34.2 → 1.34.5

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.
package/src/awaited.tsx CHANGED
@@ -116,8 +116,7 @@ function AwaitInner<T>(
116
116
  if (window.__TSR__ROUTER__) {
117
117
  let deferred = window.__TSR__ROUTER__.getDeferred('${state.uid}');
118
118
  if (deferred) deferred.resolve(window.__TSR__DEFERRED__${state.uid});
119
- }
120
- document.querySelectorAll('.tsr-script-once').forEach((el) => el.parentElement.removeChild(el));`}
119
+ }`}
121
120
  />
122
121
  ) : null}
123
122
  {props.children(data)}
@@ -125,7 +124,7 @@ function AwaitInner<T>(
125
124
  )
126
125
  }
127
126
 
128
- function ScriptOnce({
127
+ export function ScriptOnce({
129
128
  className,
130
129
  children,
131
130
  ...rest
@@ -135,7 +134,10 @@ function ScriptOnce({
135
134
  {...rest}
136
135
  className={`tsr-script-once ${className || ''}`}
137
136
  dangerouslySetInnerHTML={{
138
- __html: children,
137
+ __html: [
138
+ children,
139
+ `document.querySelectorAll('.tsr-script-once').forEach((el) => el.parentElement.removeChild(el));`,
140
+ ].join('\n'),
139
141
  }}
140
142
  />
141
143
  )
package/src/index.tsx CHANGED
@@ -12,7 +12,7 @@ export {
12
12
  } from '@tanstack/history'
13
13
  export { default as invariant } from 'tiny-invariant'
14
14
  export { default as warning } from 'tiny-warning'
15
- export { useAwaited, Await, type AwaitOptions } from './awaited'
15
+ export { useAwaited, Await, type AwaitOptions, ScriptOnce } from './awaited'
16
16
  export {
17
17
  defer,
18
18
  isDehydratedDeferred,
package/src/router.ts CHANGED
@@ -7,7 +7,6 @@ import { defaultParseSearch, defaultStringifySearch } from './searchParams'
7
7
  import {
8
8
  createControlledPromise,
9
9
  deepEqual,
10
- escapeJSON,
11
10
  functionalUpdate,
12
11
  last,
13
12
  pick,
@@ -421,6 +420,12 @@ export const componentTypes = [
421
420
  ] as const
422
421
 
423
422
  export type RouterEvents = {
423
+ onBeforeNavigate: {
424
+ type: 'onBeforeNavigate'
425
+ fromLocation: ParsedLocation
426
+ toLocation: ParsedLocation
427
+ pathChanged: boolean
428
+ }
424
429
  onBeforeLoad: {
425
430
  type: 'onBeforeLoad'
426
431
  fromLocation: ParsedLocation
@@ -1374,7 +1379,7 @@ export class Router<
1374
1379
  })
1375
1380
  }
1376
1381
 
1377
- navigate: NavigateFn = ({ from, to, ...rest }) => {
1382
+ navigate: NavigateFn = ({ from, to, __isRedirect, ...rest }) => {
1378
1383
  // If this link simply reloads the current route,
1379
1384
  // make sure it has a new key so it will trigger a data refresh
1380
1385
 
@@ -1423,13 +1428,6 @@ export class Router<
1423
1428
  // Cancel any pending matches
1424
1429
  this.cancelMatches()
1425
1430
 
1426
- this.emit({
1427
- type: 'onBeforeLoad',
1428
- fromLocation: prevLocation,
1429
- toLocation: next,
1430
- pathChanged: pathDidChange,
1431
- })
1432
-
1433
1431
  let pendingMatches!: Array<AnyRouteMatch>
1434
1432
 
1435
1433
  this.__store.batch(() => {
@@ -1454,6 +1452,22 @@ export class Router<
1454
1452
  }))
1455
1453
  })
1456
1454
 
1455
+ if (!this.state.redirect) {
1456
+ this.emit({
1457
+ type: 'onBeforeNavigate',
1458
+ fromLocation: prevLocation,
1459
+ toLocation: next,
1460
+ pathChanged: pathDidChange,
1461
+ })
1462
+ }
1463
+
1464
+ this.emit({
1465
+ type: 'onBeforeLoad',
1466
+ fromLocation: prevLocation,
1467
+ toLocation: next,
1468
+ pathChanged: pathDidChange,
1469
+ })
1470
+
1457
1471
  await this.loadMatches({
1458
1472
  matches: pendingMatches,
1459
1473
  location: next,
@@ -1516,7 +1530,7 @@ export class Router<
1516
1530
  if (isResolvedRedirect(err)) {
1517
1531
  redirect = err
1518
1532
  if (!this.isServer) {
1519
- this.navigate({ ...err, replace: true })
1533
+ this.navigate({ ...err, replace: true, __isRedirect: true })
1520
1534
  this.load()
1521
1535
  }
1522
1536
  } else if (isNotFound(err)) {
@@ -2231,11 +2245,6 @@ export class Router<
2231
2245
  return match
2232
2246
  }
2233
2247
 
2234
- /**
2235
- * @deprecated Injecting HTML directly is no longer supported. Use the new <ScriptOnce /> component instead.
2236
- */
2237
- injectHtml = async (html: string | (() => Promise<string> | string)) => {}
2238
-
2239
2248
  // We use a token -> weak map to keep track of deferred promises
2240
2249
  // that are registered on the server and need to be resolved
2241
2250
  registeredDeferredsIds = new Map<string, {}>()