Bug occurs when I use `revalidate` and `router.push`
Answered
Scaly-naped Pigeon posted this in #help-forum
Scaly-naped PigeonOP
'use server';
import { revalidateTag } from 'next/cache';
export default async function revalidate(tag: string) {
revalidateTag(tag);
}const onLoginSuccess = () => {
// ...
revalidate("accessToken");
router.push("/");
}URL is changed "/", but contents are not rendered
How to fix it? TT.
Answered by Ray
because you use
router.push and there is a 30 sec router cache, you should use redirect in server action instead13 Replies
@Scaly-naped Pigeon tsx
'use server';
import { revalidateTag } from 'next/cache';
export default async function revalidate(tag: string) {
revalidateTag(tag);
}
tsx
const onLoginSuccess = () => {
// ...
revalidate("accessToken");
router.push("/");
}
URL is changed "/", but contents are not rendered
How to fix it? TT.
try
const onLoginSuccess = () => {
// ...
revalidate("accessToken");
router.push("/");
router.refresh();
}Scaly-naped PigeonOP
Oh!!..
fixed!
why I have to use refresh??
@Scaly-naped Pigeon why I have to use refresh??
because you use
router.push and there is a 30 sec router cache, you should use redirect in server action insteadAnswer
@Scaly-naped Pigeon why I have to use refresh??
or try this
export default async function revalidate(tag: string) {
revalidateTag(tag);
redirect("/")
}and remove this from
onLoginSuccess-router.push("/");
-router.refresh();Scaly-naped PigeonOP
It works very well.
I have one more question.
I use popup this service. When I use
I don't know how to fix it.
I have one more question.
I use popup this service. When I use
revalidate, Re-render occurs.I don't know how to fix it.
@Scaly-naped Pigeon It works very well.
I have one more question.
I use popup this service. When I use `revalidate`, Re-render occurs.
I don't know how to fix it.
can you show more code on where you call the popup?
or try to call the popup after the server action here
const onLoginSuccess = async () => {
// ...
await revalidate("accessToken");
// show popup
}Scaly-naped PigeonOP
It works!
Thank you so much TTT