Comments (12)
It sounds like something about the way that createUrqlClient
is calling the fetch
method is triggering the problem. If I had to guess, I'd say it's something either with the headers provided, or with the way that createUrqlClient
is handling the response body. Since you have a reproducible case, can you try the next level of debugging to find an axios-fetch
only testcase?
from axios-fetch.
Hey @mdlavin ,
Just did an axios-fetch only test case, same error
const axios = inject<AxiosInstance>('axios');
const myFetch = buildAxiosFetch(axios);
const data = {
query: `
query ingredients(
$cursor: IngredientWhereUniqueInput
$distinct: [IngredientScalarFieldEnum!]
$orderBy: [IngredientOrderByWithRelationAndSearchRelevanceInput!]
$skip: Int
$take: Int
$where: IngredientWhereInput
) {
ingredients(
cursor: $cursor
distinct: $distinct
orderBy: $orderBy
skip: $skip
take: $take
where: $where
) {
id
name
}
ingredientsCount(
cursor: $cursor
distinct: $distinct
orderBy: $orderBy
where: $where
)
}
`
}
const endpoint = process.env.API_URL + '/graphql';
const headers = {
'content-type': 'application/json'
};
const graphqlQuery = {
'operationName': 'ingredients',
'query': data.query,
'variables': {}
};
const options = {
'method': 'POST',
'headers': headers,
'body': JSON.stringify(graphqlQuery)
};
const response = await myFetch(endpoint, options);
const myFetchResult = await response.json();
from axios-fetch.
Thanks for following up. Is it possible to include the headers, and ideally the exact body, from the response? Since the failure has to do with decoding non-ascii characters, it seems related to headers to body encoding.
from axios-fetch.
Headers:
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: http://localhost:9000
Vary: Origin
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
Content-Length: 120
ETag: W/"78-AYBikrrtlHMhCBQZAFVfBdXEm00"
Date: Tue, 20 Sep 2022 21:30:52 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Body:
{"data":{"ingredients":[{"id":"cl7l1blyy0080q0imzc0t4z4e","name":{"fr":"Blé","en-US":"Wheat"}}],"ingredientsCount":1}}
The "Blé" appear as "Blé" on the page
from axios-fetch.
I tried to reproduce this many times in a testcase, both with utf-8 and with other character encodings. I can't reproduce a difference between Axios and standard fetch. The only thing I can guess is that something about the bytes in the body that's causing trouble. When I test with your body exactly, it renders correctly for me.
Are you reproducing this in a browser or on a server? Either way, can you provide the exact details like Browser version or Node version
from axios-fetch.
I use latest versions of chrome and firefox to access the page.
I also use a nestjs version 9.1.1 and A postgres database.
Node version is 16.16.0
from axios-fetch.
Wow, you've been so helpful. Can you do me another favor to help debug? Can you:
- Change the server to send back a response with 25
é
- Can you send the full headers and response body for that response?
I have a new theory about what might be happening
from axios-fetch.
Response Header
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: http://localhost:9000
Vary: Origin
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=utf-8
Content-Length: 166
ETag: W/"a6-bnb4urLrClKuVnqkVNu3NQVR/gU"
Date: Fri, 23 Sep 2022 18:30:48 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Response Body
{"data":{"ingredients":[{"id":"cl7l1blyy0080q0imzc0t4z4e","name":{"fr":"ééééééééééééééééééééééééé","en-US":"Wheat"}}],"ingredientsCount":1}}
from axios-fetch.
I really want to figure this bug out. I ended up creating a Next.JS app to mock the server and browser side of things. When I test it, it all works ok for me. Here is my reproduction - https://github.com/mdlavin/axios-fetch-issue-118
Can you try that and suggest a change to demonstrate the problem?
from axios-fetch.
Hey, sorry it took so long.
I created a repo containing a server, a working client and a client with the problem I described here.
I don't know how to reproduce it but you can check it here https://github.com/lukadriel7/encoding-axios-fetch
from axios-fetch.
Thanks for putting your repo up. I reproduced it and then debugged the problem. Here is a fix for your problem (well, it avoids the issue on modern browsers). The problem is that the polyfill from cross-fetch
is not handling utf-8 encoded characters correctly when the body of the request is an arraybuffer
. It appears that the bug is here. That code is not treating the arraybuffer as utf-8 encoded like it does if a Blob is used for the body. Because removing the polyfill fixes the issue, I'm 95% that the polyfill is implemented incorrectly.
from axios-fetch.
Thank you very much
from axios-fetch.
Related Issues (20)
- Form-data not serializing correctly
- buildAxiosFetch not adding X-XSRF-TOKEN header on requests HOT 3
- node-fetch vulnerability HOT 1
- TypeError: Cannot read properties of undefined (reading 'name') HOT 1
- Support 204 no-content for node 18
- Unable to integrate with Angular
- Not working in IE11 HOT 5
- An in-range update of nock is breaking the build 🚨 HOT 2
- axios-fetch won't let me intercept 401 failed requests HOT 3
- 1.5.0 Release breaks Apollo HOT 4
- `.finally()` is not a function HOT 5
- GET requests have data as string "undefined"
- Error raised if someone goes offline and attempts a request HOT 5
- Unable to import useAxiosFetch as an ES6 module HOT 1
- Promise<Response>' is not assignable to type 'AxiosFetch'
- Abort requests via FetchInit signal abort HOT 1
- `fetch` should also accept `Request` object
- Do not require `node-fetch` for browser targets HOT 1
- Update package.json types to reference index.d.ts HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios-fetch.