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

Router refresh fix + tRPC improvement #310

Merged
merged 2 commits into from
Aug 12, 2024
Merged

Router refresh fix + tRPC improvement #310

merged 2 commits into from
Aug 12, 2024

Conversation

asutula
Copy link
Contributor

@asutula asutula commented Aug 12, 2024

This fixes a whole class of bugs where, after making a data mutation on the server side, you don't see data update on the client. It turns out that if you refresh the router, it needs to happen after any navigation, or else the router refresh gets cancelled.

This also uses a feature of tRPC I previously didn't know about that makes refreshing data on the client side cleaner.

Copy link

vercel bot commented Aug 12, 2024

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

Name Status Preview Comments Updated (UTC)
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 11:18pm

Comment on lines 25 to +26
router.push(`/${org.slug}/${project.slug}`);
router.refresh();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's an example of how the router refresh needs to happen after the navigation.

Comment on lines +32 to +34
void utils.deployments.deploymentsByEnvironmentId.invalidate({
environmentId: env.id,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's an example of using this tRPC utils feature that lets you imperatively invalidate a query, resulting in any users of that query to refetch their data. This imperative style is cleaner or easier to use in many cases.

@asutula asutula requested a review from joewagner August 12, 2024 23:20
Copy link
Contributor

@joewagner joewagner left a comment

Choose a reason for hiding this comment

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

Looks great!

@asutula asutula merged commit 8e4f983 into main Aug 12, 2024
4 checks passed
@asutula asutula deleted the asutula/refresh-fix branch August 12, 2024 23:32
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.

2 participants