FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: too many suspenses! · evdeveloper/Tanstack-Router-@a7d5975 · GitHub

Commit a7d5975

Browse files
committed
fix: too many suspenses!
1 parent 642a334 commit a7d5975

4 files changed

Lines changed: 406 additions & 425 deletions

File tree

‎examples/react/quickstart/src/main.tsx‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const rootRoute = new RootRoute({
1717
<>
1818
<div>
1919
<Link to="/">Home</Link>{' '}
20-
<Link to="/lazy-without-suspsense">Lazy without suspense</Link>{' '}
21-
<Link to="/lazy-with-suspsense">Lazy with suspense</Link>{' '}
20+
<Link to="/lazy-without-suspense">Lazy without suspense</Link>{' '}
21+
<Link to="/lazy-with-suspense">Lazy with suspense</Link>{' '}
2222
<Link to="/with-loader">With loader</Link>
2323
</div>
2424
<hr />
@@ -38,31 +38,31 @@ const indexRoute = new Route({
3838

3939
const lazyWithoutSuspense = new Route({
4040
getParentRoute: () => rootRoute,
41-
path: '/lazy-without-suspsense',
41+
path: '/lazy-without-suspense',
4242
component: lazyRouteComponent(
4343
() =>
4444
new Promise<Record<string, SyncRouteComponent<any>>>((res) => {
4545
setTimeout(() => {
4646
res({
4747
default: () => <h1>Hello world from "lazy-without-suspense"</h1>,
4848
})
49-
}, 1500)
49+
}, 1000)
5050
}),
5151
),
52-
wrapInSuspense: false,
5352
})
5453

5554
const lazyWithSuspense = new Route({
5655
getParentRoute: () => rootRoute,
57-
path: '/lazy-with-suspsense',
56+
path: '/lazy-with-suspense',
5857
component: lazyRouteComponent(
5958
() =>
6059
new Promise<Record<string, SyncRouteComponent<any>>>((res) => {
6160
setTimeout(() => {
61+
console.log('res')
6262
res({
6363
default: () => <h1>Hello world from "lazy-with-suspense"</h1>,
6464
})
65-
}, 1500)
65+
}, 1000)
6666
}),
6767
),
6868
pendingComponent: () => <h1>I'm loading</h1>,
@@ -98,11 +98,5 @@ declare module '@tanstack/router' {
9898
const rootElement = document.getElementById('app')!
9999
if (!rootElement.innerHTML) {
100100
const root = ReactDOM.createRoot(rootElement)
101-
root.render(
102-
<StrictMode>
103-
<Suspense>
104-
<RouterProvider router={router} />
105-
</Suspense>
106-
</StrictMode>,
107-
)
101+
root.render(<RouterProvider router={router} />)
108102
}

‎packages/router/__tests__/createRoutes.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { describe, it, expect } from 'vitest'
1+
import { describe, it } from 'vitest'
22
import { z } from 'zod'
3-
import { createMemoryHistory, RootRoute, Route, Router, lazy } from '../src'
3+
import {
4+
createMemoryHistory,
5+
RootRoute,
6+
Route,
7+
Router,
8+
lazyRouteComponent,
9+
} from '../src'
410

511
// Write a test
612
describe('everything', () => {
@@ -20,7 +26,10 @@ describe('everything', () => {
2026

2127
const testRoute = new Route({
2228
getParentRoute: () => rootRoute,
23-
component: lazy(() => import('./TestComponent'), 'NamedComponent'),
29+
component: lazyRouteComponent(
30+
() => import('./TestComponent'),
31+
'NamedComponent',
32+
),
2433
path: 'test',
2534
validateSearch: (search) =>
2635
z

‎packages/router/src/router.ts‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ export class Router<
431431
this.state.location.pathname,
432432
this.state.location.search,
433433
{
434-
// throwOnError: true,
434+
throwOnError: true,
435435
},
436436
)
437437

@@ -781,20 +781,15 @@ export class Router<
781781

782782
let latestPromise
783783

784-
const componentsPromise = (async () => {
785-
// then run all component and data loaders in parallel
786-
// For each component type, potentially load it asynchronously
784+
const componentsPromise = Promise.all(
785+
componentTypes.map(async (type) => {
786+
const component = route.options[type]
787787

788-
await Promise.all(
789-
componentTypes.map(async (type) => {
790-
const component = route.options[type]
791-
792-
if (component?.preload) {
793-
await component.preload()
794-
}
795-
}),
796-
)
797-
})()
788+
if (component?.preload) {
789+
await component.preload()
790+
}
791+
}),
792+
)
798793

799794
const loaderPromise = Promise.resolve().then(() => {
800795
if (route.options.loader) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL