Skip to content

feat(react-query): next-app-router example with prefetch helpers#5451

Merged
juliusmarminge merged 123 commits intonextfrom
app-router-example
Jun 12, 2024
Merged

feat(react-query): next-app-router example with prefetch helpers#5451
juliusmarminge merged 123 commits intonextfrom
app-router-example

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Feb 6, 2024

More integrated version of t3-oss/create-t3-turbo#877

adds a wrapped proxy around createCaller that puts the promise into a server-side QueryClient. devs can then choose to wrap some client component that needs some server prefetched data with the <HydrateClient> component. no network requests will be made from client components until the prefetched data goes stale:

https://utfs.io/f/8278fdc7-572e-4b14-9f10-5f9fece747bb-yl67w4.15.58.mp4

you choose if you want to await the promise or not depending on if you also need to use the data in the RSC. if you void it, rendering wont be blocked until a useSuspenseQuery consumes the promise

This gives the same behavior as the ReactQueryStreamedProvider, but you can do authed procedures since there's no fetching in client componetns, even on the server, so no need to hack the RSC headers into the CC which causes some weird security concerns

CleanShot.2024-03-07.at.23.03.56.mp4

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-prisma-starter ✅ Ready (Inspect) Visit Preview Jun 12, 2024 2:31pm
og-image ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 2:31pm
trpc-next-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 2:31pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 2:31pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2024

Diagnostics Comparison

Details

Numbers

Metric PR next
Files 797 799 (🔽🟢 -2)
Lines of Library 40,640 40,640 (➖ 0)
Lines of Definitions 120,515 120,877 (🔽🟢 -362)
Lines of TypeScript 4,967 4,967 (➖ 0)
Lines of JavaScript 0 0 (➖ 0)
Lines of JSON 0 0 (➖ 0)
Lines of Other 0 0 (➖ 0)
Identifiers 176,252 176,742 (🔽🟢 -490)
Symbols 109,594 109,953 (🔽🟢 -359)
Types 89 89 (➖ 0)
Instantiations 0 0 (➖ 0)
Memory used 172,910 178,189 (🔽🟢 -5,279)
Assignability cache size 0 0 (➖ 0)
Identity cache size 0 0 (➖ 0)
Subtype cache size 0 0 (➖ 0)
Strict subtype cache size 0 0 (➖ 0)

Timings and averages

Metric PR next
max (s) 4.404 4.289 (🔺 0.11)
min (s) 4.404 4.289 (🔺 0.11)
avg (s) 4.404 4.289 (🔺 0.11)
median (s) 4.404 4.289 (🔺 0.11)
length 1 1 (➖ 0)
unstable timings

Unstable

Timings are not reliable in here

Metric PR next
I/O Read time 0.04 0.05 (🔽🟢 -0.01)
Parse time 0.69 0.71 (🔽🟢 -0.02)
ResolveTypeReference time 0.03 0.03 (➖ 0)
ResolveModule time 0.12 0.1 (🔺 0.02)
ResolveLibrary time 0.03 0.02 (🔺 0.01)
Program time 1.02 1.03 (🔽🟢 -0.01)
Bind time 0.42 0.43 (🔽🟢 -0.01)
Total time 1.44 1.47 (🔽🟢 -0.03)

KATT
KATT previously approved these changes Jun 8, 2024
Copy link
Copy Markdown
Member

@KATT KATT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!!!!!!!!!

Should we combine all "kitchen sink"-y things inside the existing next-app-dir-project-project perhaps? I'm personally almost loosing track of all of our parallel experimental approaches 😅

@juliusmarminge
Copy link
Copy Markdown
Member Author

This is great!!!!!!!!!

Should we combine all "kitchen sink"-y things inside the existing next-app-dir-project-project perhaps? I'm personally almost loosing track of all of our parallel experimental approaches 😅

Yea probably a good idea.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this patch is implemented upstream here: TanStack/query#7538

@juliusmarminge
Copy link
Copy Markdown
Member Author

Promise transformation landed in RQ:

CleanShot 2024-06-12 at 16 15 51

export const dynamic = 'force-dynamic';

export default function Home() {
void trpc.getLatestPost.prefetch();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if a promise fails in a place like this?

is it safe / will node crash with "unhandled promise rejection"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void will ignore errors?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the query will be retried when it mounts on the client depending on your retry options

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.