Debug post deletion redirect error
Loading...
when i deleted a post, i saw an application error instead of being redirected to the repo index. next.js bug? or our bug?
Our bug, not Next.js! š
I found and fixed the issue. Here's what was happening:
##The Problem
When you delete a post, both delete dialogs were calling:
router.push(`/${owner}/${repo}`) // Navigate to repo index
router.refresh() // Refresh the page
The router.refresh() after router.push() creates a race condition. The server action deletePost also calls updateTag(post:${postId}) which tells Next.js to revalidate the post page cache. When refresh() runs, Next.js tries to re-render the current page (the now-deleted post), which fails because the post no longer exists.
##The Fix
delete-comment-dialog.tsx: Only callrouter.refresh()when staying on the same page (i.e., when deleting a comment, not the whole post)moderator-delete-post-dialog.tsx: Removerouter.refresh()entirely since we're always navigating away
Created PR: https://github.com/basehub-ai/forums/pull/130
END OF POST