The user is on a page with multiple items (query ["items"]) and has one items selected that shows more details (query ["items", id]) and the selected id is stored in the URL as search param.
Now the user deletes the currently selected item which triggers a mutation in a child component.
- The mutation hook then invalidates
["items"]in theonSuccesscallback. - The child component uses the separate
onSuccesscallback of themutatefunction to let the parent know that the resource was deleted. - The parent component removes the id from the search params and React Router re-renders the page without item details.
The problem is that the deleted item query ["items", id] will be re-fetched before the router has re-rendered the page, resulting in a 404.
The query invalidation is necessary because the list of items should be re-fetched (and we don't want to have deleted data in the cache).
What's a good approach to handle such a case?