-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: support network request aborting and refetching #34
Conversation
@varl is there a reason we aren't using any eslint plugins (most notable |
Keeping it "JavaScript" generic:
We could add a group for React though, so you get a different ESLint configuration by doing e.g. The "base" ESLint should be kept agnostic and only enforce vanilla JavaScript standards. |
Cool cool, though so. I think having a React group might make sense, but for now I've just added some eslint React rules here. @varl thoughts this change and particularly whether or not to include an imperative |
Agreed. The reason we don't have it yet is this:
|
Generally it would be nice to not have to think about it, but there might be scenarios where we do need to manually abort a request. Unless we actually need it now, my vote goes to only aborting when the component unmounts for now and adding it when we have use case we want to support. |
Cool, I think I agree. I'll leave it out for now, will be adding imperative refetch shortly which is probably more useful and has actually been requested |
@varl updated to remove the imperative abort for now. Also refactored the hook implementation to be cleaner and prepare for refetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except for the typo. Fix that and .
There's a known issue with duplicate typings in |
@varl thanks for the reviews! Fixed the typo. I went ahead and added the refetch feature here so that we don't need a second minor version bump, so I dismissed your approval. I added an imperative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@HendrikThePendric made a good point about AbortController in IE11 - we'll either need to polyfill it (not difficult) or guarantee that this will only be used in 2.33+ |
(Note: IE 11 also doesn't have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one comment reg. IE11 support
}, []) | ||
|
||
return state | ||
const controller = new AbortController() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE11 lacks support for the AbortController
. From DHIS 2 version 2.33 we will drop support for IE 11, so most apps using this hook won't suffer from this problem. However, there may be some exceptions:
- Apps that transitioned to feature toggling prior to 2.33: if at a later stage a developer decides to introduce the DataQuery component, this could cause problems (they can probably be avoided somehow)
- The new HeaderBar component: I believe this uses the DataQuery too, and it is being used in a lot of v2.32 apps. So this could be another potential source of problems.
My preferred solution would be to do the following:
- Keep the code as it is
- Add a section to the README (preferably fairly prominently displayed) mentioning:
- That this lib relies on the
Fetch
,AbortController
andAbortSignal
APIs which are unsupported in IE11 - If your app requires IE11 support, add a polyfill for all these APIs
- Include some instructions on how to do so, i.e. linking to whatwg-fetch and abortcontroller-polyfill
- That this lib relies on the
This way each app can handle things as it sees fit.
@HendrikThePendric @amcgee We use a similar approach in ui-core where the App needs to provide polyfills: https://github.com/dhis2/ui-core#requires-polyfills |
Great thanks @varl @HendrikThePendric! I’ll update the readme and merge tomorrow Would be SO COOL to formally expose lib poly fill reqs to consuming apps! One day... |
Merging abort and refetch for a 1.5 release! |
🎉 This PR is included in version 1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This automatically aborts requests when the component is unmounted, the query changed, or a refetch initiated (new feature 👍).
This also adds
eslint-plugin-react-hooks
to eslint, allowing us to better check hooks. **We should probably add these tocli-style
!This does not expose an imperative
abort
interface, though that could be added later if there's a need for it. As it stands, I think it's better to let the component lifecycle handle the inflight requests, especially since we might not always have 1-to-1 query-to-request relationships.We were missing dependencies for the
useEffect
inuseDataQuery
, which I've added here, so now the data will be re-requested if the query changes.