-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see facebook/react-native#18115 what i tried: - using fetch patch from abortcontroller polyfill - 'abortcontroller-polyfill/dist/polyfill-patch-fetch' - did not get it to work (weird error inside whatwg-fetch) - patching react-native to use cross-fetch (by changing react-native/Libraries/Network/fetch.js) - did not get it to work (weird error inside cross-fetch) - removing vendored whatwg-fetch from react-native source code (so the app loads real whatwg-fetch) - did not work
- Loading branch information
Showing
5 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// @flow | ||
|
||
// Compat issue 1: Needed due to https://github.com/facebook/react-native/issues/18115 | ||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'; | ||
|
||
import equal from 'deep-equal'; | ||
|
||
import { Component } from 'react'; | ||
|
||
import { AbortError } from 'tg-resources'; | ||
import { FetchResource as Resource } from '@tg-resources/fetch'; | ||
|
||
|
||
type Props = { | ||
apiRoot: string, | ||
|
||
onError: (e) => *, | ||
onSuccess: () => *, | ||
}; | ||
|
||
type State = { | ||
controller: AbortController, | ||
} | ||
|
||
// TODO: Currently does not work see (https://github.com/facebook/react-native/issues/18115) | ||
class AbortTest extends Component<Props, State> { | ||
state = { | ||
controller: new AbortController(), | ||
}; | ||
|
||
async componentDidMount() { | ||
const { apiRoot, onError, onSuccess } = this.props; | ||
const { controller } = this.state; | ||
|
||
setTimeout(() => { | ||
controller.abort(); | ||
}, 100); | ||
|
||
try { | ||
await new Resource('/abort', { | ||
apiRoot, | ||
}).fetch(null, null, { | ||
signal: controller.signal, | ||
}); | ||
|
||
onError(new Error('Request should be aborted!')); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
if (!e || !e.isAbortError) { | ||
onError(new Error('Raised error should be an instance of AbortError')); | ||
return; | ||
} | ||
|
||
if (!e.isAbortError || e.type !== 'aborted' || e.name !== 'AbortError') { | ||
onError(new Error(`AbortError signature is invalid: got=${JSON.stringify(e)}`)); | ||
return; | ||
} | ||
|
||
onSuccess(); | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
export default AbortTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters