From 51e27a359f0dc1714e5197ba0bfeadaba89f008f Mon Sep 17 00:00:00 2001 From: Ross Chapman Date: Wed, 23 Oct 2024 16:41:18 -0700 Subject: [PATCH] Removes unused `whatwg-fetch` package (#243) --- docs/data-fetching.md | 34 ---------------------------------- package-lock.json | 8 +------- package.json | 3 +-- webpack.config.js | 2 +- 4 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 docs/data-fetching.md diff --git a/docs/data-fetching.md b/docs/data-fetching.md deleted file mode 100644 index 47cda17bb..000000000 --- a/docs/data-fetching.md +++ /dev/null @@ -1,34 +0,0 @@ -## Data Fetching with WHATWG Fetch - -There is isomorphic `core/fetch` module that can be used the same way in both -client-side and server-side code as follows: - -```jsx -import fetch from "../core/fetch"; - -export const path = "/products"; -export const action = async () => { - const response = await fetch("/graphql?query={products{id,name}}"); - const data = await response.json(); - return ( - - - - ); -}; -``` - -When this code executes on the client, the Ajax request will be sent via -GitHub's [fetch](https://github.com/github/fetch) library (`whatwg-fetch`), -that itself uses XHMLHttpRequest behind the scene unless `fetch` is supported -natively by the user's browser. - -Whenever the same code executes on the server, it uses -[node-fetch](https://github.com/bitinn/node-fetch) module behind the scene that -itself sends an HTTP request via Node.js `http` module. It also converts -relative URLs to absolute (see `./core/fetch/fetch.server.js`). - -Both `whatwg-fetch` and `node-fetch` modules have almost identical API. If -you're new to this API, the following article may give you a good introduction: - -https://jakearchibald.com/2015/thats-so-fetch/ diff --git a/package-lock.json b/package-lock.json index 7514cabad..78c33285f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,8 +36,7 @@ "react-modal": "^3.12.1", "react-router-dom": "^6.27.0", "react-tippy": "^1.4.0", - "swr": "^2.2.5", - "whatwg-fetch": "^2.0.1" + "swr": "^2.2.5" }, "devDependencies": { "@babel/cli": "^7.4.4", @@ -22694,11 +22693,6 @@ "node": ">=12" } }, - "node_modules/whatwg-fetch": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", - "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" - }, "node_modules/whatwg-mimetype": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz", diff --git a/package.json b/package.json index 4ef282644..a9ebf5240 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,7 @@ "react-modal": "^3.12.1", "react-router-dom": "^6.27.0", "react-tippy": "^1.4.0", - "swr": "^2.2.5", - "whatwg-fetch": "^2.0.1" + "swr": "^2.2.5" }, "devDependencies": { "@babel/cli": "^7.4.4", diff --git a/webpack.config.js b/webpack.config.js index 655224a68..66fa6b3b3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -52,7 +52,7 @@ const buildDir = path.resolve(__dirname, "build"); module.exports = { mode: process.env.NODE_ENV || "production", context: __dirname, - entry: ["whatwg-fetch", "@babel/polyfill", path.resolve(appRoot, "init.tsx")], + entry: ["@babel/polyfill", path.resolve(appRoot, "init.tsx")], output: { path: buildDir, publicPath: "/dist/",