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

Switch to fetch away from axios #592

Open
1 task
sarayourfriend opened this issue Mar 21, 2022 · 4 comments
Open
1 task

Switch to fetch away from axios #592

sarayourfriend opened this issue Mar 21, 2022 · 4 comments
Assignees
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: frontend Related to the Nuxt frontend 💬 talk: discussion Open for discussions and feedback 🟨 tech: javascript Involves JavaScript

Comments

@sarayourfriend
Copy link
Collaborator

Problem

Currently we use axios to manage making HTTP requests on the client. Bytes over the network aren't free and now that browsers and Node have the same fetch api, we could switch to using fully native APIs for network requests that won't add bytes to the bundle.

Description

Explore switching from axios to fetch. Axios has some nice features like middleware and easy-to-use request making. It also has different symantics around what constitutes an "error" (fetch only throws on status codes > 499 whereas axios throws > 399).

Alternatives

Stick with axios. It's not that heavy of a dependency and there are probably less critical paths we can do dependency optimization for (I'm assuming, I'm not sure).

Implementation

  • 🙋 I would be interested in implementing this feature.
@sarayourfriend sarayourfriend added 🟩 priority: low Low priority and doesn't need to be rushed ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🟨 tech: javascript Involves JavaScript 💬 talk: discussion Open for discussions and feedback labels Mar 21, 2022
@obulat obulat transferred this issue from WordPress/openverse-frontend Feb 22, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Openverse Backlog Feb 23, 2023
@obulat obulat added the 🧱 stack: frontend Related to the Nuxt frontend label Feb 24, 2023
@sarayourfriend
Copy link
Collaborator Author

@obulat Any thoughts on whether this is worth doing? It looks like most of our axios usage is concentrated in the API service of the frontend, along with usage in the i18n utils. Axios is 30.2 kB minified: https://bundlephobia.com/package/[email protected]

Could be a good "help wanted" issue?

@dhruvkb
Copy link
Member

dhruvkb commented Nov 23, 2023

The i18n utils are quite decoupled from the frontend so switching them could very well be a standalone "good first"/"help wanted" issue. But it would be good to have consistency in the library used across the codebase or at least within a stack layer so we should only switch if we plan on going all in with it.

@sarayourfriend
Copy link
Collaborator Author

Would it help to separate this into two issues, then? One for the application code and one for the i18n code? The i18n utilities would need to use node-fetch anyway, so it's good to handle as a separate issue, I think.

@sarayourfriend
Copy link
Collaborator Author

Actually, we need node-fetch for SSR as well, so maybe that point is moot.

We do need to make sure node-fetch doesn't accidentally get used in the client bundle, so we might need to have separate files exporting the fetch function to use:

// utils/fetch.client.ts
export const fetch = window.fetch;


// utils/fetch.server.ts
export fetch from 'node-fetch'

Something along those lines.

@obulat obulat mentioned this issue Nov 22, 2024
8 tasks
@obulat obulat self-assigned this Dec 4, 2024
@openverse-bot openverse-bot moved this from 📋 Backlog to 📅 To Do in Openverse Backlog Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: frontend Related to the Nuxt frontend 💬 talk: discussion Open for discussions and feedback 🟨 tech: javascript Involves JavaScript
Projects
Status: 📅 To Do
Development

No branches or pull requests

3 participants