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

@wordpress/api-fetch remove window dependency to support node env #17551

Open
isBatak opened this issue Sep 24, 2019 · 6 comments
Open

@wordpress/api-fetch remove window dependency to support node env #17551

isBatak opened this issue Sep 24, 2019 · 6 comments
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Package] API fetch /packages/api-fetch [Type] Enhancement A suggestion for improvement.
Projects

Comments

@isBatak
Copy link

isBatak commented Sep 24, 2019

I'm trying to use @wordpress/api-fetch on node (decoupled WordPress and SSR), but it is not easy to polyfill fetch because of window.fetch usage https://github.com/WordPress/gutenberg/blob/master/packages/api-fetch/src/index.js#L161 and I don't want to reimplement whole defaultFetchHandler logic with setFetchHandler solution. I just want to replace fetch with something else like isomorphic-fetch.

Solution:

  • use just fetch
@swissspidy swissspidy added [Package] API fetch /packages/api-fetch [Type] Enhancement A suggestion for improvement. Needs Technical Feedback Needs testing from a developer perspective. labels Sep 24, 2019
@isBatak
Copy link
Author

isBatak commented Sep 25, 2019

@swissspidy I'm planning to make a PR for this feature, this is the idea isBatak@72e3505 for the API. But, now tests are failing and I have no idea how to fix them. Do you have any suggestion?

@swissspidy
Copy link
Member

Well which tests are failing...? If you'd create the PR already then you could point to the failing tests on Travis CI and more easily get technical feedback from maintainers.

@isBatak
Copy link
Author

isBatak commented Sep 25, 2019

I'll make a PR now, and see what will happen :D

@gziolo gziolo added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label Nov 12, 2019
@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Dec 9, 2019
@talldan talldan removed the Needs Technical Feedback Needs testing from a developer perspective. label Apr 21, 2020
@talldan
Copy link
Contributor

talldan commented Apr 21, 2020

The PR #17574 seems to have plenty of technical feedback, so I'm removing that label.

Also removing In Progress, since the PR hasn't had recent updates.

@talldan talldan removed the [Status] In Progress Tracking issues with work in progress label Apr 21, 2020
@hypest hypest added this to Triage in Mobile Apps via automation Aug 11, 2020
@hypest hypest moved this from Triage to To do in Mobile Apps Aug 11, 2020
@hypest
Copy link
Contributor

hypest commented Aug 11, 2020

FYI, added this to the "Mobile Apps" project board to cover the apps side of the issue.

@iamandrewluca
Copy link

iamandrewluca commented Sep 5, 2020

Besides this solutions

another solution would be to export a factory function

import { createApiFetch } from '@wordpress/api-fetch'

// Browser
const apiFetch = createApiFetch({ fetch: window.fetch })

// Node
const apiFetch = createApiFetch({ fetch: require('node-fetch') })

My workaround

import fetch from 'node-fetch'
global.window = { fetch }
import apiFetch from '@wordpress/api-fetch'

apiFetch({ path: '/wp-json/wp/v2/users' }).then(console.log)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Package] API fetch /packages/api-fetch [Type] Enhancement A suggestion for improvement.
Projects
Mobile Apps
  
To do
Development

No branches or pull requests

6 participants