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

Odd behavior in StrictMode with array responses #53

Open
brandonwestcott opened this issue Jun 17, 2022 · 5 comments
Open

Odd behavior in StrictMode with array responses #53

brandonwestcott opened this issue Jun 17, 2022 · 5 comments

Comments

@brandonwestcott
Copy link

Thanks for this library, this truly solves a major gap in the apollo caching realm!

We've been using this pkg with apollo-cache-persist for a bit now, but only in a limited scope with a few types. Today I went to add invalidations to more types and ran into the following odd behavior:

When in development with React.StrictMode, queries that return arrays don't refetch upon invalidation.

Code Sandbox:
https://codesandbox.io/s/apollo-cache-policies-strictmode-arrays-w97xhw

Reproduction:

  1. Visit page
  2. Click on Mission within 10s invalidation
  3. Wait for 10s
  4. Click back
  5. List is empty

Also note that if you click back 10s after the first load, but before the individual query Mission expires, you will see that Mission in the array because it's ttl got refreshed on on the show route.
Reproduction:

  1. Visit page
  2. Click on Mission after ~7s
  3. Wait for ~5s
  4. Click back
  5. List contains only the visited Mission

Again, this only occurs in React.StrictMode --- removing that or building the app results in normal behavior.

@danReynolds
Copy link
Collaborator

Thanks for the repro. I'll be looking into this when I have time. We don't use the StrictMode tool so it may take me some time to investigate. If anyone else has thoughts on this feel free to chime in!

@brandonwestcott
Copy link
Author

Thanks @danReynolds.

Initially when diving into this, I thought I was running into the same issue listed in #47 (comment). The bugged behavior seemed similar, but unsure if its related.

Additionally, I did some investigation in the package looking for culprits in any of the dual executed strict mode methods: https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects . Nothing stood out to me immediately, but seems like it could be a likely culprit.

@brandonwestcott
Copy link
Author

Hi @danReynolds, just following up here to see if you've found anything. Of course I'm happy to dive in and help debug the root cause here, but could use a little guidance if you have any ideas where this is likely to occur.

@danReynolds
Copy link
Collaborator

Hey @brandonwestcott yea I haven't had much time to explore this one yet. I should have some cycles upcoming in August, been on vacation through most of July. If anyone has any thoughts feel free to chime in in the meantime. It'll be my first time really using strict mode components so should be interesting

@brandonwestcott
Copy link
Author

Sounds great, thank you! Truly let me know if there is anything I can do to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants