-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Close the active thread when it is deleted from another client #4091
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
Open
alfredmouelle
wants to merge
1
commit into
pingdotgg:main
Choose a base branch
from
alfredmouelle:fix/close-deleted-active-thread
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−14
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Delete redirect races fallback navigation
Medium Severity
Forwarding
thread.deletedclears detail state sorouteThreadExistscan become false whileuseThreadActions.deleteThreadis still navigating to a fallback thread. This effect then fires an unawaitednavigateto/, which can finish after the fallback navigation and leave same-client deletes on the empty state instead of the next thread.Additional Locations (1)
apps/server/src/ws.ts#L263-L275Reviewed by Cursor Bugbot for commit 47b4ed3. Configure here.
Uh oh!
There was an error while loading. Please reload this page.
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.
I looked into this specific scenario (same-client delete of the active thread while other threads remain, expecting to land on the fallback thread). I could not reproduce the bad outcome, and I believe the ordering makes it safe. Details below.
Empirical: with two threads present, deleting the active one from the same client consistently lands on the fallback thread and stays there (verified stable over ~1.5s, no transient flash to
/). Local dev has near-zero WS latency, which is the worst case forthread.deletedarriving ahead of the mutation ack, and it still resolved correctly.Why the ordering holds. In
useThreadActions.deleteThread, everything between the mutation resolving and the fallback navigation is synchronous:Two possible orderings:
thread.deletedhandler (a separate task) can't fire the route guard beforenavigate(fallback)is issued. Fallback wins.navigate({ to: "/" }), thendeleteThreadissuesnavigate(fallback)second. TanStack Router supersedes the pending navigation with the latest one, so the fallback still wins.The only way to land on
/would be case 2 plus the tworeplacenavigations applying out of order, which the router's supersede behavior prevents. Production network latency delays the event relative to the ack, pushing things further toward case 1.Worth noting the two navigations target different destinations by design: the guard is the cross-client safety net (goes to the empty state), while
deleteThreadpicks a same-project fallback for local deletes. Even in the improbable event this raced, the worst case would be landing on the empty state instead of the next thread on a same-client delete, still a strict improvement over the current behavior, where the deleted thread stays fully rendered.Happy to add a defensive guard (e.g. having
deleteThreadnavigate before dispatch, or skipping the route redirect for in-flight local deletes) if you'd prefer belt-and-suspenders here.