Skip to content
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

Apollo Client cache merging previous (from other route) and new results when using browser back button #9291

Closed
meesfrenkelfrank opened this issue Jan 11, 2022 · 1 comment · Fixed by #9367

Comments

@meesfrenkelfrank
Copy link

meesfrenkelfrank commented Jan 11, 2022

I am using Apollo Client fetchMore function and configured the Apollo Client cache:

The Apollo Client typePolicies configured like:

    typePolicies: {
        NodesTypeOne: {
         keyFields: [],
         fields: {
          nodes: offsetLimitPagination(),
         },
        },
        NodesTypeTwo: {
         keyFields: [],
         fields: {
          nodes: offsetLimitPagination(),
         },
        },,
      },

From the Node detail-page when I use the browser Back button (so it'a navigating back to the overview page, without refreshing the browser) and navigate from this overview page to another Node detail-page, it's merging the results from the previous route and the current route?

In the useQuery hook I am using:

notifyOnNetworkStatusChange: true,

Somehow, when I hit the Back button, I have to reset the cache or something?

How do I have to solve this issue?

@meesfrenkelfrank meesfrenkelfrank changed the title Apollo Client fetchMore cache merging previous (from other route) and new results when using react-router useHistory Apollo Client cache merging previous (from other route) and new results when using react-router useHistory Jan 11, 2022
@meesfrenkelfrank meesfrenkelfrank changed the title Apollo Client cache merging previous (from other route) and new results when using react-router useHistory Apollo Client cache merging previous (from other route) and new results when using browser back button Jan 12, 2022
@bengotow
Copy link

Hey folks! I think this issue is related to #9334 and I put together a repro case there. When notifyOnNetworkStatusChange: true, it seems Apollo is behaving as if returnPartialData: true is also true. When you navigate back, I think useQuery is yielding a partial data object from cache.

It might also be mixing data on object 1 with data about object 2 but I didn't observe that, just that it returned a partial state that wasn't asked for.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants