Skip to content

Fix optimistic query invalidation and avoid invalidating the same query twice#11017

Merged
djhi merged 2 commits intomasterfrom
fix-optimistic-query-invalidation-2
Nov 3, 2025
Merged

Fix optimistic query invalidation and avoid invalidating the same query twice#11017
djhi merged 2 commits intomasterfrom
fix-optimistic-query-invalidation-2

Conversation

@slax57
Copy link
Contributor

@slax57 slax57 commented Nov 3, 2025

Problem

#11013 introduced a fix for optimistic query invalidation, but it was reverted in #11016 because it resulted in duplicate dataProvider calls in some scenarios.

Solution

The initial implementation of #11013 introduced invalidating queries using the provided query keys list, but also kept invalidating queries from the snapshot. This could result in calling queryClient.invalidateQueries() twice on overlapping query keys.

For instance:

[
    "posts",
    "getList"
]

and

[
    "posts",
    "getList",
    {
        "pagination": {
            "page": 1,
            "perPage": 10
        },
        "sort": {
            "field": "published_at",
            "order": "DESC"
        },
        "filter": {}
    }
]

This is what caused the duplicate call to getList.

The solution is to only keep the provided query keys list, because the snapshot is created from this provided list, so the query keys from the snapshot are a subset of the provided query keys set.

How To Test

  • Open the simple example
  • Edit a post and save
  • Make sure there is only 1 getList call

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

@slax57 slax57 added the RFR Ready For Review label Nov 3, 2025
@djhi djhi self-requested a review November 3, 2025 09:53
@djhi djhi merged commit 77d1756 into master Nov 3, 2025
15 checks passed
@djhi djhi deleted the fix-optimistic-query-invalidation-2 branch November 3, 2025 10:08
@djhi djhi added this to the 5.12.3 milestone Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

2 participants