Skip to content

fix(core): match optimistic queries and execute pending undoable mutations on consecutive saves (#7653) - #7675

Open
ghazy2001 wants to merge 1 commit into
refinedev:mainfrom
ghazy2001:fix/optimistic-undoable-list-update-7653
Open

ghazy2001 wants to merge 1 commit into
refinedev:mainfrom
ghazy2001:fix/optimistic-undoable-list-update-7653

Conversation

@ghazy2001

Copy link
Copy Markdown

Description

Fixes #7653

This PR resolves two critical issues affecting undoable and optimistic mutation modes in @refinedev/core:

  1. Optimistic List & Detail Query Key Matching:

    • useUpdate, useDelete, useUpdateMany, and useDeleteMany were querying queryClient.setQueriesData with resourceKeys.action("list").params(preferredMeta ?? {}).get() and resourceKeys.action("one").id(id).params(preferredMeta ?? {}).get().
    • In standard CRUD forms, useMeta inherits route parameters from useParsed(), leaking id into preferredMeta.
    • Because list queries never include record IDs in their query keys, TanStack Query's partialDeepEqual failed to match, leaving cached list queries completely un-updated.
    • Fixed by aligning list and detail query matching with action("many") and useInvalidate (resourceKeys.action("list").get() and resourceKeys.action("one").id(id).get()), where record-specific filtering is cleanly handled by record.id === id inside the updater.
  2. Preservation of Pending Mutations in Consecutive Saves (Undoable Mode):

    • In undoableQueueReducer, dispatching ActionTypes.ADD for an (id, resource) that was already pending filtered out the previous item from state without calling its doMutation(), dropping the first save and leaving its promise unsettled.
    • Fixed by immediately executing existing.doMutation?.() to flush the previous mutation before registering the new one, and adding isSettled idempotency guards to doMutation and cancelMutation in the mutation hooks to prevent double execution.

Changeset

  • Added .changeset/fix-optimistic-undoable-queue-loss.md for @refinedev/core (patch).

Tests

  • Added regression unit tests in packages/core/src/contexts/undoableQueue/index.spec.tsx verifying that consecutive ADD dispatches execute doMutation on the existing item.
  • Added regression unit tests in packages/core/src/hooks/data/useUpdate.spec.tsx verifying optimistic list and detail updates succeed even when meta contains route parameters such as id.

@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2837653

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@refinedev/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant