@tanstack/react-router-devtools 0.0.1-alpha.4 → 0.0.1-alpha.6

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-alpha.4",
4
+ "version": "0.0.1-alpha.6",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://react-router.tanstack.com/",
@@ -35,7 +35,7 @@
35
35
  "src"
36
36
  ],
37
37
  "peerDependencies": {
38
- "@tanstack/react-router": "0.0.1-alpha.4",
38
+ "@tanstack/react-router": "0.0.1-alpha.6",
39
39
  "react": ">=16",
40
40
  "react-dom": ">=16"
41
41
  },
package/src/Explorer.tsx CHANGED
@@ -67,7 +67,7 @@ type Entry = {
67
67
  }
68
68
 
69
69
  type RendererProps = {
70
- HandleEntry: HandleEntryComponent
70
+ handleEntry: HandleEntryFn
71
71
  label?: React.ReactNode
72
72
  value: unknown
73
73
  subEntries: Entry[]
@@ -102,7 +102,7 @@ export function chunkArray<T>(array: T[], size: number): T[][] {
102
102
  type Renderer = (props: RendererProps) => JSX.Element
103
103
 
104
104
  export const DefaultRenderer: Renderer = ({
105
- HandleEntry,
105
+ handleEntry,
106
106
  label,
107
107
  value,
108
108
  subEntries = [],
@@ -134,9 +134,7 @@ export const DefaultRenderer: Renderer = ({
134
134
  {expanded ? (
135
135
  subEntryPages.length === 1 ? (
136
136
  <SubEntries>
137
- {subEntries.map((entry) => (
138
- <HandleEntry key={entry.label} entry={entry} />
139
- ))}
137
+ {subEntries.map((entry, index) => handleEntry(entry))}
140
138
  </SubEntries>
141
139
  ) : (
142
140
  <SubEntries>
@@ -157,9 +155,7 @@ export const DefaultRenderer: Renderer = ({
157
155
  </LabelButton>
158
156
  {expandedPages.includes(index) ? (
159
157
  <SubEntries>
160
- {entries.map((entry) => (
161
- <HandleEntry key={entry.label} entry={entry} />
162
- ))}
158
+ {entries.map((entry) => handleEntry(entry))}
163
159
  </SubEntries>
164
160
  ) : null}
165
161
  </Entry>
@@ -198,7 +194,7 @@ export const DefaultRenderer: Renderer = ({
198
194
  )
199
195
  }
200
196
 
201
- type HandleEntryComponent = (props: { entry: Entry }) => JSX.Element
197
+ type HandleEntryFn = (entry: Entry) => JSX.Element
202
198
 
203
199
  type ExplorerProps = Partial<RendererProps> & {
204
200
  renderer?: Renderer
@@ -273,11 +269,14 @@ export default function Explorer({
273
269
  const subEntryPages = chunkArray(subEntries, pageSize)
274
270
 
275
271
  return renderer({
276
- HandleEntry: React.useCallback(
277
- ({ entry }) => (
278
- <Explorer value={value} renderer={renderer} {...rest} {...entry} />
279
- ),
280
- [value, renderer],
272
+ handleEntry: (entry) => (
273
+ <Explorer
274
+ key={entry.label}
275
+ value={value}
276
+ renderer={renderer}
277
+ {...rest}
278
+ {...entry}
279
+ />
281
280
  ),
282
281
  type,
283
282
  subEntries,
package/src/devtools.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { Router, useRouter, last } from '@tanstack/react-router'
2
+ import { Router, last } from '@tanstack/react-router'
3
3
  import { formatDistanceStrict } from 'date-fns'
4
4
 
5
5
  import useLocalStorage from './useLocalStorage'
@@ -52,7 +52,7 @@ interface DevtoolsOptions {
52
52
  /**
53
53
  * A boolean variable indicating if the "lite" version of the library is being used
54
54
  */
55
- useRouter?: () => unknown
55
+ router: Router<any, any>
56
56
  }
57
57
 
58
58
  interface DevtoolsPanelOptions {
@@ -79,7 +79,7 @@ interface DevtoolsPanelOptions {
79
79
  /**
80
80
  * A boolean variable indicating if the "lite" version of the library is being used
81
81
  */
82
- useRouter: () => unknown
82
+ router: Router<any, any>
83
83
  }
84
84
 
85
85
  const isServer = typeof window === 'undefined'
@@ -91,7 +91,7 @@ export function TanStackRouterDevtools({
91
91
  toggleButtonProps = {},
92
92
  position = 'bottom-left',
93
93
  containerElement: Container = 'footer',
94
- useRouter: useRouterImpl = useRouter,
94
+ router,
95
95
  }: DevtoolsOptions): React.ReactElement | null {
96
96
  const rootRef = React.useRef<HTMLDivElement>(null)
97
97
  const panelRef = React.useRef<HTMLDivElement>(null)
@@ -230,7 +230,7 @@ export function TanStackRouterDevtools({
230
230
  <TanStackRouterDevtoolsPanel
231
231
  ref={panelRef as any}
232
232
  {...otherPanelProps}
233
- useRouter={useRouterImpl}
233
+ router={router}
234
234
  style={{
235
235
  position: 'fixed',
236
236
  bottom: '0',
@@ -360,17 +360,43 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
360
360
  isOpen = true,
361
361
  setIsOpen,
362
362
  handleDragStart,
363
- useRouter,
363
+ router,
364
364
  ...panelProps
365
365
  } = props
366
-
367
- const router = useRouter() as Router
366
+ const routerExplorerValue = React.useMemo(() => {
367
+ const {
368
+ listeners,
369
+ buildLocation,
370
+ mount,
371
+ update,
372
+ buildNext,
373
+ navigate,
374
+ cancelMatches,
375
+ loadLocation,
376
+ cleanPreloadCache,
377
+ loadRoute,
378
+ matchRoutes,
379
+ loadMatches,
380
+ invalidateRoute,
381
+ resolvePath,
382
+ matchRoute,
383
+ buildLink,
384
+ __experimental__createSnapshot,
385
+ destroy,
386
+ ...rest
387
+ } = router
388
+
389
+ return rest
390
+ }, [router.state])
391
+
392
+ const rerender = React.useReducer(() => ({}), {})[1]
368
393
 
369
394
  React.useEffect(() => {
370
395
  let interval = setInterval(() => {
371
396
  router.cleanPreloadCache()
372
- router.notify()
373
- }, 1000)
397
+ // router.notify()
398
+ rerender()
399
+ }, 250)
374
400
 
375
401
  return () => {
376
402
  clearInterval(interval)
@@ -386,6 +412,27 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
386
412
  (d) => d.routeId === activeRouteId,
387
413
  )
388
414
 
415
+ const activeMatchExplorerValue = React.useMemo(() => {
416
+ if (!activeMatch) {
417
+ return {}
418
+ }
419
+
420
+ const {
421
+ cancel,
422
+ load,
423
+ router,
424
+ Link,
425
+ MatchRoute,
426
+ buildLink,
427
+ linkProps,
428
+ matchRoute,
429
+ navigate,
430
+ ...rest
431
+ } = activeMatch
432
+
433
+ return rest
434
+ }, [activeMatch])
435
+
389
436
  return (
390
437
  <ThemeProvider theme={theme}>
391
438
  <Panel ref={ref} className="TanStackRouterDevtoolsPanel" {...panelProps}>
@@ -505,30 +552,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
505
552
  >
506
553
  <Explorer
507
554
  label="Router"
508
- value={(() => {
509
- const {
510
- listeners,
511
- buildLocation,
512
- mount,
513
- update,
514
- buildNext,
515
- navigate,
516
- cancelMatches,
517
- loadLocation,
518
- cleanPreloadCache,
519
- loadRoute,
520
- matchRoutes,
521
- loadMatches,
522
- invalidateRoute,
523
- resolvePath,
524
- matchRoute,
525
- buildLink,
526
- __experimental__createSnapshot,
527
- destroy,
528
- ...rest
529
- } = router
530
- return rest
531
- })()}
555
+ value={routerExplorerValue}
532
556
  defaultExpanded={{}}
533
557
  />
534
558
  </div>
@@ -822,7 +846,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
822
846
  <Button
823
847
  type="button"
824
848
  onClick={() => {
825
- router.invalidateRoute(activeMatch as any)
849
+ activeMatch.invalidate()
826
850
  router.notify()
827
851
  }}
828
852
  style={{
@@ -834,7 +858,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
834
858
  </Button>{' '}
835
859
  <Button
836
860
  type="button"
837
- onClick={() => router.reload()}
861
+ onClick={() => activeMatch.load()}
838
862
  style={{
839
863
  background: theme.gray,
840
864
  }}
@@ -860,22 +884,7 @@ export const TanStackRouterDevtoolsPanel = React.forwardRef<
860
884
  >
861
885
  <Explorer
862
886
  label="Match"
863
- value={(() => {
864
- const {
865
- cancel,
866
- load,
867
- router,
868
- Link,
869
- MatchRoute,
870
- buildLink,
871
- linkProps,
872
- matchRoute,
873
- navigate,
874
- ...rest
875
- } = activeMatch
876
-
877
- return rest
878
- })()}
887
+ value={activeMatchExplorerValue}
879
888
  defaultExpanded={{}}
880
889
  />
881
890
  </div>