Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 123 commits into from
Jun 12, 2024

Conversation

juliusmarminge
Copy link
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

Copy link

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

Copy link

github-actions bot commented Feb 6, 2024

Diagnostics Comparison

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)

@juliusmarminge
Copy link
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
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
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
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

@juliusmarminge juliusmarminge merged commit ab71a1b into next Jun 12, 2024
38 checks passed
@juliusmarminge juliusmarminge deleted the app-router-example branch June 12, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet