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

feat: request cancellation #369

Merged
merged 1 commit into from
Sep 9, 2021
Merged

Conversation

DorianMaliszewski
Copy link
Member

Possibility to cancel a Promise with an enhanced promise type

@codecov
Copy link

codecov bot commented Sep 8, 2021

Codecov Report

Merging #369 (b597284) into master (08581aa) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #369   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        11           
  Lines          346       360   +14     
  Branches        56        60    +4     
=========================================
+ Hits           346       360   +14     
Impacted Files Coverage Δ
packages/use-dataloader/src/useDataLoader.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08581aa...b597284. Read the comment docs.

@vincentaudebert
Copy link
Contributor

vincentaudebert commented Sep 8, 2021

I get this

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
          at TestComponent (/Volumes/Projets/scaleway-lib/node_modules/@testing-library/react-hooks/lib/helpers/createTestHarness.js:22:5)
          at DataLoaderProvider (/Volumes/Projets/scaleway-lib/packages/use-dataloader/src/DataLoaderProvider.tsx:33:31)
          at wrapper (/Volumes/Projets/scaleway-lib/packages/use-dataloader/src/__tests__/useDataLoader.tsx:28:20)
          at Suspense
          at ErrorBoundary (/Volumes/Projets/scaleway-lib/node_modules/react-error-boundary/dist/react-error-boundary.cjs.js:40:35)

      123 |     async cacheKey => {
      124 |       try {
    > 125 |         dispatch(Actions.createOnLoading())
          |         ^
      126 |         const promise = method()
      127 |         cancelMethodRef.current = promise.cancel
      128 |         const result = await promise.then(res => res)

in the tests. Is there no way to avoid this?

(Tests are fairly long)

adriengibrat
adriengibrat previously approved these changes Sep 9, 2021
Copy link
Contributor

@adriengibrat adriengibrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fan of enhanced promise type :

Why not using the native fetch abort mechanism?

the fetch() promise rejects with an "AbortError" DOMException.

https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal

@adriengibrat adriengibrat dismissed their stale review September 9, 2021 08:04

using standards may be a better way than enhanced promise type

@DorianMaliszewski DorianMaliszewski force-pushed the feat/request-cancellation branch 2 times, most recently from 0e27464 to 4f96063 Compare September 9, 2021 08:30
@DorianMaliszewski
Copy link
Member Author

DorianMaliszewski commented Sep 9, 2021

I'm not fan of enhanced promise type :

Why not using the native fetch abort mechanism?

the fetch() promise rejects with an "AbortError" DOMException.

https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal

@adriengibrat We should handle both Axios and Fetch behaviour so we need to keep something flexible to ensure a compatibility between both. May in the fututre we will directly integrate a custom hook for each ones.

Copy link
Contributor

@vincentaudebert vincentaudebert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@DorianMaliszewski DorianMaliszewski merged commit 78d26b2 into master Sep 9, 2021
@DorianMaliszewski DorianMaliszewski deleted the feat/request-cancellation branch September 9, 2021 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants