react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Provide shouldInvalidatePreviousData prop

Open jcready opened this issue 5 years ago • 6 comments

Fixes #2202

Checklist:

  • [x] If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • [ ] Make sure all of the significant new logic is covered by tests
  • [ ] If this was a change that affects the external API used in GitHunt-React, update GitHunt-React and post a link to the PR in the discussion.

jcready avatar Mar 21 '19 15:03 jcready

@jcready: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

apollo-cla avatar Mar 21 '19 15:03 apollo-cla

Thanks for this PR @jcready! I'm wondering if we're over-complicating things here a bit. What if we just added something like a clearPreviousDataOnLoad prop. When it's true, we make sure previousData is emptied. This would simplify the RA codebase, and if an application really only wants to disable previousData based on previous / current variable differences, they can track variables and do the comparison outside of the Query component, and just pass the boolean result in via clearPreviousDataOnLoad.

hwillson avatar Apr 12 '19 09:04 hwillson

@hwillson clearPreviousDataOnLoad makes it sound like you would only clear the previous data once the network call finished. I think many people want the previous data cleared the moment their variables change. Additionally I know that many people wanted this to be the default behavior (e.g. pagination should be the exception).

[...] if an application really only wants to disable previousData based on previous / current variable differences, they can track variables and do the comparison outside of the Query component, and just pass the boolean result in via clearPreviousDataOnLoad.

To me that sounds like it would make things more difficult for the consumer since they would then have to keep track of the previous variables themselves. The Query component's componentWillReceiveProps already has access to both and can easily provide them to a passed in function.

jcready avatar Apr 12 '19 13:04 jcready

Thanks for the feedback @jcready. Regarding making this the default behavior, I agree, but we're kinda of stuck with things the way they are now (due to backwards compatibility issues). You touched on part of the bigger issue when you mentioned componentWillReceiveProps - we're in the process of moving away from React lifecycle methods in react-apollo 3.0. Another part of the issue I see here is that people will likely want similar behavior when they change other things, like changing the query for example. Hmmm ... thinking ...

hwillson avatar Apr 12 '19 18:04 hwillson

@hwillson This is still an issue, and after the 3.1 release, it is not fixed. By the way, you might want to reopen #2202. If you want a CodeSandbox reproducing this: https://codesandbox.io/s/context-vs-queries-f2079.

Also see: https://github.com/apollographql/react-apollo/issues/3572

Titozzz avatar Oct 22 '19 13:10 Titozzz

is it getting merged?

iamswain25 avatar May 06 '20 09:05 iamswain25