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

[RFR] Fix query component does not fetch again when updated #3146

Merged
merged 2 commits into from
Apr 19, 2019

Conversation

fzaninotto
Copy link
Member

Closes #3126

@fzaninotto fzaninotto added this to the 2.8.6 milestone Apr 19, 2019
@djhi djhi merged commit 5ec9cd6 into master Apr 19, 2019
@djhi djhi deleted the fix-query-component-update branch April 19, 2019 10:02
@RafeSacks
Copy link

RafeSacks commented Apr 21, 2019

Hi,

I was about to work on a PR myself and then I saw this. Thanks!!

An issue I came across while testing my original posted solution is that the promise has to be "cancelable" to avoid races with components being unmounted. Does this PR handle this issue?

After a bunch of research I ended up adding a dependency to trashable-component. which provides a higher-order component to handle it.

I import:

/*
 * Reason for `trashable-react` dependency. Handle promise canceling on unmount
 * that also handles garbage collection correctly. Since this package has a
 * solution with testing that proves it, why not use it? Ref:
 *   - https://reactjs.org/blog/2015/12/16/ismounted-antipattern.html
 *   - https://github.com/facebook/react/issues/5465
 *   - https://github.com/hjylewis/trashable
 */
import makeComponentTrashable from "trashable-react";

...and wrap:

export default makeComponentTrashable(withDataProvider(Query));

Then just wrap the dataProvider promise:

    registerPromise(dataProvider(type, resource, payload, options))
      .then(({ data, total }) => { ...

Note: registerPromise is in this.props thanks to the HOC

@RafeSacks
Copy link

I was also wondering if fetchStart and fetchEnd (in promise finally) is needed? I found a number of places in the docs where these are used but they are not used in Query.

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

Successfully merging this pull request may close these issues.

Query component does not update
3 participants