Skip to content

fix: don't call router.refresh() after deleting a post#130

Open
julianbenegas wants to merge 1 commit intomainfrom
forums/fix-delete-redirect-92e5c
Open

fix: don't call router.refresh() after deleting a post#130
julianbenegas wants to merge 1 commit intomainfrom
forums/fix-delete-redirect-92e5c

Conversation

@julianbenegas
Copy link
Member

When a post is deleted, calling router.refresh() after router.push() causes
an application error because Next.js tries to revalidate/render the deleted
post page before the navigation completes.

The fix:

  • In delete-comment-dialog: only call router.refresh() when a comment is
    deleted (not the whole post). When a post is deleted, just navigate away.
  • In moderator-delete-post-dialog: remove router.refresh() entirely since
    we're always navigating to a different page after deletion.

This was our bug, not a Next.js bug - the race condition between push and
refresh on a deleted resource caused the error.

When a post is deleted, calling router.refresh() after router.push() causes
an application error because Next.js tries to revalidate/render the deleted
post page before the navigation completes.

The fix:
- In delete-comment-dialog: only call router.refresh() when a comment is
  deleted (not the whole post). When a post is deleted, just navigate away.
- In moderator-delete-post-dialog: remove router.refresh() entirely since
  we're always navigating to a different page after deletion.

This was our bug, not a Next.js bug - the race condition between push and
refresh on a deleted resource caused the error.
@vercel
Copy link
Contributor

vercel bot commented Jan 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
forums Ready Ready Preview, Comment Jan 25, 2026 6:25am

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Calling router.refresh() after router.push() when deleting a post causes unnecessary revalidation of the deleted post page

Fix on Vercel

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.

1 participant