Skip to content

Commit c8081ce

Browse files
artongebackportbot-nextcloud[bot]
authored andcommitted
When double-clicking on a file, the behavior is:
First click: open the viewer Second click: close the viewer But the second click does not correctly close the Viewer, as the method used to cancel the requests does not work. This PR use modern API to cancel the requests. The requests are now correctly aborted, and the `openFile` method exit because the request call throws an exception. Fix #893 https://axios-http.com/docs/cancellation https://developer.mozilla.org/en-US/docs/Web/API/AbortController Signed-off-by: Louis Chemineau <louis@chmn.me> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent b41b952 commit c8081ce

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/utils/CancelableRequest.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* @author Marco Ambrosini <marcoambrosini@pm.me>
55
* @author John Molakvoæ <skjnldsv@protonmail.com>
6+
* @author Louis Chemineau <louis@chmn.me>
67
*
78
* @license GNU AGPL version 3 or any later version
89
*
@@ -21,20 +22,14 @@
2122
*
2223
*/
2324

24-
import axios from '@nextcloud/axios'
25-
2625
/**
2726
* Creates a cancelable axios 'request object'.
2827
*
2928
* @param {function} request the axios promise request
3029
* @returns {Object}
3130
*/
3231
const CancelableRequest = function(request) {
33-
/**
34-
* Generate an axios cancel token
35-
*/
36-
const CancelToken = axios.CancelToken
37-
const source = CancelToken.source()
32+
const controller = new AbortController()
3833

3934
/**
4035
* Execute the request
@@ -45,12 +40,12 @@ const CancelableRequest = function(request) {
4540
const fetch = async function(url, options) {
4641
return request(
4742
url,
48-
Object.assign({ cancelToken: source.token }, { options })
43+
{ ...options, signal: controller.signal }
4944
)
5045
}
5146
return {
5247
request: fetch,
53-
cancel: source.cancel,
48+
cancel: () => controller.abort(),
5449
}
5550
}
5651

0 commit comments

Comments
 (0)