-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use native fetch if available (#62)
If you are in the Electron Renderer process, native fetch is available but it's ignored because the renderer does not respect the browser field of package.json, so we end up with `node-fetch` that uses a browser polyfill of the node `http` module which is very slow on Electron. Instead use native fetch if it's available or `node-fetch` if not, unless you're on the Electron Main process in which case use `electron-fetch` which uses the Electron `net` module which is faster than the node `http` module in that environment.
- Loading branch information
1 parent
78edc8b
commit 9b0ff2f
Showing
4 changed files
with
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const { isElectronMain } = require('./env') | ||
|
||
if (isElectronMain) { | ||
module.exports = require('@achingbrain/electron-fetch') | ||
} else { | ||
// use window.fetch if it is available, fall back to node-fetch if not | ||
module.exports = require('native-fetch') | ||
} |
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