Skip to content

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

Merged
djhi merged 2 commits into
masterfrom
fix-query-component-update
Apr 19, 2019
Merged

djhi merged 2 commits into
masterfrom
fix-query-component-update

Conversation

@fzaninotto

Copy link
Copy Markdown
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

RafeSacks commented Apr 21, 2019 •

Copy link
Copy Markdown

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
Copy Markdown

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