@tanstack/react-router-devtools 0.0.1-beta.36 → 0.0.1-beta.41

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router-devtools",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.36",
4
+ "version": "0.0.1-beta.41",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router/",
@@ -36,13 +36,13 @@
36
36
  ],
37
37
  "sideEffects": false,
38
38
  "peerDependencies": {
39
- "@tanstack/react-router": "0.0.1-beta.36",
40
39
  "react": ">=16",
41
40
  "react-dom": ">=16"
42
41
  },
43
42
  "dependencies": {
44
43
  "@babel/runtime": "^7.16.7",
45
- "date-fns": "^2.29.1"
44
+ "date-fns": "^2.29.1",
45
+ "@tanstack/react-router": "workspace:^"
46
46
  },
47
47
  "devDependencies": {
48
48
  "babel-plugin-transform-async-to-promises": "^0.8.18"
package/src/devtools.tsx CHANGED
@@ -1,5 +1,12 @@
1
1
  import React from 'react'
2
- import { Router, last, routerContext, invariant } from '@tanstack/react-router'
2
+ import {
3
+ Router,
4
+ last,
5
+ routerContext,
6
+ invariant,
7
+ __useStoreValue,
8
+ useRouterStore,
9
+ } from '@tanstack/react-router'
3
10
  import { formatDistanceStrict } from 'date-fns'
4
11
 
5
12
  import useLocalStorage from './useLocalStorage'
@@ -418,19 +425,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
418
425
  'No router was found for the TanStack Router Devtools. Please place the devtools in the <RouterProvider> component tree or pass the router instance to the devtools manually.',
419
426
  )
420
427
 
421
- const rerender = React.useReducer(() => ({}), {})[1]
422
-
423
- React.useEffect(() => {
424
- let interval = setInterval(() => {
425
- router.cleanMatchCache()
426
- // router.notify()
427
- rerender()
428
- }, 250)
429
-
430
- return () => {
431
- clearInterval(interval)
432
- }
433
- }, [])
428
+ useRouterStore()
434
429
 
435
430
  const [activeRouteId, setActiveRouteId] = useLocalStorage(
436
431
  'tanstackRouterDevtoolsActiveRouteId',
@@ -447,19 +442,22 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
447
442
  }, [activeRouteId])
448
443
 
449
444
  const activeMatch =
450
- Object.values(router.matchCache)?.find(
445
+ Object.values(router.store.matchCache)?.find(
451
446
  (d) => d.match.matchId === activeMatchId,
452
447
  )?.match ??
453
- router.state.currentMatches?.find((d) => d.routeId === activeRouteId)
448
+ router.store.currentMatches?.find((d) => d.routeId === activeRouteId)
454
449
 
455
450
  const matchCacheValues = multiSortBy(
456
- Object.keys(router.matchCache)
451
+ Object.keys(router.store.matchCache)
457
452
  .filter((key) => {
458
- const cacheEntry = router.matchCache[key]!
453
+ const cacheEntry = router.store.matchCache[key]!
459
454
  return cacheEntry.gc > Date.now()
460
455
  })
461
- .map((key) => router.matchCache[key]!),
462
- [(d) => (d.match.isFetching ? -1 : 1), (d) => -d.match.updatedAt!],
456
+ .map((key) => router.store.matchCache[key]!),
457
+ [
458
+ (d) => (d.match.store.isFetching ? -1 : 1),
459
+ (d) => -d.match.store.updatedAt!,
460
+ ],
463
461
  )
464
462
 
465
463
  return (
@@ -599,7 +597,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
599
597
  >
600
598
  Active Matches
601
599
  </div>
602
- {router.state.currentMatches.map((match, i) => {
600
+ {router.store.currentMatches.map((match, i) => {
603
601
  return (
604
602
  <div
605
603
  key={match.routeId || i}
@@ -644,7 +642,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
644
642
  </div>
645
643
  )
646
644
  })}
647
- {router.state.pendingMatches?.length ? (
645
+ {router.store.pendingMatches?.length ? (
648
646
  <>
649
647
  <div
650
648
  style={{
@@ -658,7 +656,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
658
656
  >
659
657
  Pending Matches
660
658
  </div>
661
- {router.state.pendingMatches?.map((match, i) => {
659
+ {router.store.pendingMatches?.map((match, i) => {
662
660
  return (
663
661
  <div
664
662
  key={match.routeId || i}
@@ -725,8 +723,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
725
723
  <div>Match Cache</div>
726
724
  <Button
727
725
  onClick={() => {
728
- router.matchCache = {}
729
- router.notify()
726
+ router.setStore((s) => (s.matchCache = {}))
730
727
  }}
731
728
  >
732
729
  Clear
@@ -836,18 +833,18 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
836
833
  </tr>
837
834
  <tr>
838
835
  <td style={{ opacity: '.5' }}>Status</td>
839
- <td>{activeMatch.status}</td>
836
+ <td>{activeMatch.store.status}</td>
840
837
  </tr>
841
838
  <tr>
842
839
  <td style={{ opacity: '.5' }}>Invalid</td>
843
- <td>{activeMatch.isInvalid.toString()}</td>
840
+ <td>{activeMatch.store.isInvalid.toString()}</td>
844
841
  </tr>
845
842
  <tr>
846
843
  <td style={{ opacity: '.5' }}>Last Updated</td>
847
844
  <td>
848
- {activeMatch.updatedAt
845
+ {activeMatch.store.updatedAt
849
846
  ? new Date(
850
- activeMatch.updatedAt as number,
847
+ activeMatch.store.updatedAt as number,
851
848
  ).toLocaleTimeString()
852
849
  : 'N/A'}
853
850
  </td>
@@ -876,7 +873,6 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
876
873
  type="button"
877
874
  onClick={() => {
878
875
  activeMatch.invalidate()
879
- router.notify()
880
876
  }}
881
877
  style={{
882
878
  background: theme.warning,
@@ -948,12 +944,16 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
948
944
  padding: '.5em',
949
945
  }}
950
946
  >
951
- {Object.keys(last(router.state.currentMatches)?.loaderData || {})
952
- .length ? (
947
+ {Object.keys(
948
+ last(router.store.currentMatches)?.store.loaderData || {},
949
+ ).length ? (
953
950
  <Explorer
954
- value={last(router.state.currentMatches)?.loaderData || {}}
951
+ value={
952
+ last(router.store.currentMatches)?.store.loaderData || {}
953
+ }
955
954
  defaultExpanded={Object.keys(
956
- (last(router.state.currentMatches)?.loaderData as {}) || {},
955
+ (last(router.store.currentMatches)?.store.loaderData as {}) ||
956
+ {},
957
957
  ).reduce((obj: any, next) => {
958
958
  obj[next] = {}
959
959
  return obj
@@ -980,12 +980,12 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
980
980
  padding: '.5em',
981
981
  }}
982
982
  >
983
- {Object.keys(last(router.state.currentMatches)?.search || {})
983
+ {Object.keys(last(router.store.currentMatches)?.store.search || {})
984
984
  .length ? (
985
985
  <Explorer
986
- value={last(router.state.currentMatches)?.search || {}}
986
+ value={last(router.store.currentMatches)?.store.search || {}}
987
987
  defaultExpanded={Object.keys(
988
- (last(router.state.currentMatches)?.search as {}) || {},
988
+ (last(router.store.currentMatches)?.store.search as {}) || {},
989
989
  ).reduce((obj: any, next) => {
990
990
  obj[next] = {}
991
991
  return obj
package/src/utils.ts CHANGED
@@ -26,11 +26,11 @@ type StyledComponent<T> = T extends 'button'
26
26
  : never
27
27
 
28
28
  export function getStatusColor(match: RouteMatch, theme: Theme) {
29
- return match.isFetching
29
+ return match.store.isFetching
30
30
  ? theme.active
31
- : match.status === 'error'
31
+ : match.store.status === 'error'
32
32
  ? theme.danger
33
- : match.status === 'success'
33
+ : match.store.status === 'success'
34
34
  ? theme.success
35
35
  : theme.gray
36
36
  }