@tanstack/react-router 0.0.1-beta.26 → 0.0.1-beta.28
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/build/cjs/react-router/src/index.js +45 -10
- package/build/cjs/react-router/src/index.js.map +1 -1
- package/build/esm/index.js +45 -10
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +27 -27
- package/build/umd/index.development.js +45 -10
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +55 -8
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
invariant,
|
|
35
35
|
Router,
|
|
36
36
|
} from '@tanstack/router-core'
|
|
37
|
+
import { restElement } from '@babel/types'
|
|
37
38
|
|
|
38
39
|
export * from '@tanstack/router-core'
|
|
39
40
|
|
|
@@ -326,9 +327,9 @@ export function createReactRouter<
|
|
|
326
327
|
} = linkInfo
|
|
327
328
|
|
|
328
329
|
const reactHandleClick = (e: Event) => {
|
|
329
|
-
React.startTransition
|
|
330
|
-
handleClick(e)
|
|
331
|
-
|
|
330
|
+
if (React.startTransition) // This is a hack for react < 18
|
|
331
|
+
React.startTransition(() => {handleClick(e)})
|
|
332
|
+
else handleClick(e)
|
|
332
333
|
}
|
|
333
334
|
|
|
334
335
|
const composeHandlers =
|
|
@@ -615,7 +616,7 @@ export function Outlet() {
|
|
|
615
616
|
return (
|
|
616
617
|
<MatchesProvider value={matches}>
|
|
617
618
|
<React.Suspense fallback={<PendingComponent />}>
|
|
618
|
-
<CatchBoundary errorComponent={errorComponent}>
|
|
619
|
+
<CatchBoundary errorComponent={errorComponent} key={match.routeId}>
|
|
619
620
|
{
|
|
620
621
|
((): React.ReactNode => {
|
|
621
622
|
if (match.status === 'error') {
|
|
@@ -644,7 +645,9 @@ class CatchBoundary extends React.Component<{
|
|
|
644
645
|
}> {
|
|
645
646
|
state = {
|
|
646
647
|
error: false,
|
|
648
|
+
info: undefined,
|
|
647
649
|
}
|
|
650
|
+
|
|
648
651
|
componentDidCatch(error: any, info: any) {
|
|
649
652
|
console.error(error)
|
|
650
653
|
|
|
@@ -653,15 +656,59 @@ class CatchBoundary extends React.Component<{
|
|
|
653
656
|
info,
|
|
654
657
|
})
|
|
655
658
|
}
|
|
659
|
+
|
|
656
660
|
render() {
|
|
657
|
-
|
|
661
|
+
return (
|
|
662
|
+
<CatchBoundaryInner
|
|
663
|
+
{...this.props}
|
|
664
|
+
errorState={this.state}
|
|
665
|
+
reset={() => this.setState({})}
|
|
666
|
+
/>
|
|
667
|
+
)
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
672
|
+
// there has to be a better way to reset error boundaries when the
|
|
673
|
+
// router's location key changes.
|
|
674
|
+
function CatchBoundaryInner(props: {
|
|
675
|
+
children: any
|
|
676
|
+
errorComponent: any
|
|
677
|
+
errorState: { error: unknown; info: any }
|
|
678
|
+
reset: () => void
|
|
679
|
+
}) {
|
|
680
|
+
const [activeErrorState, setActiveErrorState] = React.useState(
|
|
681
|
+
props.errorState,
|
|
682
|
+
)
|
|
683
|
+
const router = useRouter()
|
|
684
|
+
const errorComponent = props.errorComponent ?? DefaultErrorBoundary
|
|
658
685
|
|
|
659
|
-
|
|
660
|
-
|
|
686
|
+
React.useEffect(() => {
|
|
687
|
+
if (activeErrorState) {
|
|
688
|
+
let prevKey = router.state.location.key
|
|
689
|
+
return router.subscribe(() => {
|
|
690
|
+
if (router.state.location.key !== prevKey) {
|
|
691
|
+
prevKey = router.state.location.key
|
|
692
|
+
setActiveErrorState({} as any)
|
|
693
|
+
}
|
|
694
|
+
})
|
|
661
695
|
}
|
|
662
696
|
|
|
663
|
-
return
|
|
697
|
+
return
|
|
698
|
+
}, [activeErrorState])
|
|
699
|
+
|
|
700
|
+
React.useEffect(() => {
|
|
701
|
+
if (props.errorState.error) {
|
|
702
|
+
setActiveErrorState(props.errorState)
|
|
703
|
+
}
|
|
704
|
+
props.reset()
|
|
705
|
+
}, [props.errorState.error])
|
|
706
|
+
|
|
707
|
+
if (activeErrorState.error) {
|
|
708
|
+
return React.createElement(errorComponent, activeErrorState)
|
|
664
709
|
}
|
|
710
|
+
|
|
711
|
+
return props.children
|
|
665
712
|
}
|
|
666
713
|
|
|
667
714
|
export function DefaultErrorBoundary({ error }: { error: any }) {
|