Bug: create and delete both fail to navigate after success — React #300 / silent no-op due to void navigate race #1318
marcusbellamyshaw-cell
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Bug
Two separate content operations fail to navigate after success due to the same race condition in
router.tsx— the user is left on the wrong page with no error message.1. Deleting a content entry
Deleting from the editor throws a minified React error #300 ("Something went wrong!"). The delete succeeds server-side but the UI crashes during navigation back to the collection list.
2. Creating a new content entry
Saving a new entry from
/content/[collection]/newshows "Saving..." but never navigates to the edit view. The entry is created successfully (HTTP 201) but the user is left stranded on the/newpage with no draft/publish buttons and no indication the save worked. Navigating manually to the collection list confirms the entry exists.Steps to reproduce (creation case)
Root cause
Both flows share the same broken pattern in
router.tsx—voidon async operations with no ordering:The
navigatecalls fire without being awaited. The concurrentinvalidateQueriescalls trigger refetches and React state updates that race against the navigation. If any in-flight mutation (auto-save, or a query refetch resolving after the route has already changed) completes while the component is mid-unmount, it attempts a state update on an unmounting tree — producing the React #300 error or silently swallowing the navigation entirely.Note: the exact mechanism triggering #300 in the delete case is the unordered concurrency between
invalidateQueriesandnavigate— we observed the error consistently in production but haven't isolated whether it's specifically the auto-save mutation, a refetch completing late, or TipTap'sonEditorReady(null)cleanup firing mid-navigation. The fix below addresses all of these.Fix
Await navigate after any query invalidations, and cancel pending mutations before navigating:
Impact
Both bugs leave the user with no feedback that their action worked. The creation case is particularly bad — "Saving..." appears to fail silently, causing users to attempt duplicate saves or think their content was lost.
All reactions