Skip to content

Commit

Permalink
fix(start): do not interfere with deferred promise resolution (#2974)
Browse files Browse the repository at this point in the history
* fix(start): do not interfere with deferred promise resolution

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
schiller-manuel and autofix-ci[bot] authored Dec 10, 2024
1 parent 3b57424 commit 8dae0ca
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 15 deletions.
10 changes: 4 additions & 6 deletions e2e/start/basic/app/routes/deferred.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Await, createFileRoute, defer } from '@tanstack/react-router'
import { Await, createFileRoute } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/start'
import { Suspense, useState } from 'react'

Expand All @@ -18,12 +18,10 @@ const slowServerFn = createServerFn({ method: 'GET' })
export const Route = createFileRoute('/deferred')({
loader: async () => {
return {
deferredStuff: defer(
new Promise<string>((r) =>
setTimeout(() => r('Hello deferred!'), 2000),
),
deferredStuff: new Promise<string>((r) =>
setTimeout(() => r('Hello deferred!'), 2000),
),
deferredPerson: defer(slowServerFn({ data: { name: 'Tanner Linsley' } })),
deferredPerson: slowServerFn({ data: { name: 'Tanner Linsley' } }),
person: await personServerFn({ data: { name: 'John Doe' } }),
}
},
Expand Down
2 changes: 0 additions & 2 deletions packages/react-router/src/awaited.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function useAwaited<T>({
}
}
}
console.log('useAwaited', promise[TSR_DEFERRED_PROMISE])
return [promise[TSR_DEFERRED_PROMISE].data, promise]
}

Expand All @@ -66,7 +65,6 @@ function AwaitInner<T>(
},
): React.JSX.Element {
const [data] = useAwaited(props)
console.log('AwaitInner', data)

return props.children(data) as React.JSX.Element
}
1 change: 0 additions & 1 deletion packages/react-router/src/defer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function defer<T>(
.then((data) => {
promise[TSR_DEFERRED_PROMISE].status = 'success'
promise[TSR_DEFERRED_PROMISE].data = data
console.log('defer then', promise[TSR_DEFERRED_PROMISE])
})
.catch((error) => {
promise[TSR_DEFERRED_PROMISE].status = 'error'
Expand Down
6 changes: 0 additions & 6 deletions packages/start/src/client/serialization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ export function afterHydrate({ router }: { router: AnyRouter }) {

if (extracted) {
Object.entries(extracted).forEach(([_, ex]: any) => {
if (ex.value instanceof Promise) {
const og = ex.value
ex.value = og.then((data: any) => {
return data
})
}
deepMutableSetByPath(match, ['loaderData', ...ex.path], ex.value)
})
}
Expand Down

0 comments on commit 8dae0ca

Please sign in to comment.