-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
router.push(`/${org.slug}/${project.slug}`); | ||
router.refresh(); |
There was a problem hiding this comment.
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.
void utils.deployments.deploymentsByEnvironmentId.invalidate({ | ||
environmentId: env.id, | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
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.