Comments (8)
Proposal:
If document.baseURI
doesn't exist and the input
is a relative URL:
- ...if the
prefixUrl
option is not set, we throw an error recommending the user to set that option. - ...if the
prefixUrl
option is set, we just don't usedocument.baseURI
.
Thoughts?
from ky.
After further investigation it seems to come from the following line of code:
Line 138 in 5dbd4a2
This was added in the 0.5.1 with commit d6f8176 which fixed issue #59. As document is not available in React-Native I am not sure if this issue is in the scope for this library and what a clean fix would be if it is in the scope.
from ky.
This is also a problem when trying to use ky in a SSR React app. I'd love to use ky, as it's much easier to handle than direct fetch
or alternatives.
Is support for SSR something you'd still consider part of this library? The _globalThis
polyfill in the main index.js
seems to suggest that.
from ky.
Is support for SSR something you'd still consider part of this library?
Yes
from ky.
We just need to decide how Ky should handle document.baseURI
not being available.
from ky.
Cool! In the meantime, I solved the situation in my NextJS app by adding things like Headers
and document
to the global object server side. I used node-fetch to get working implementations of these.
import fetch, { Headers } from 'node-fetch'
const BASE_URL = 'http://some.url'
if (typeof window === 'undefined') {
global.document = {
baseURI: BASE_URL,
}
global.fetch = fetch
global.Headers = Headers
}
Ky's _globalThis
polyfill automatically picks up global
and things work as expected.
@sindresorhus, are you already tracking this topic in a different issue? Do you have an intuition for how you'd want to see this handled?
from ky.
Presumably these environments have some way to get the current URL, right? For example, an equivalent of location.href
.
That would be the appropriate fallback when no DOM is present.
from ky.
@sholladay, well when you are running in plain node, then I would think, no. Most common scenario that comes to mind, and which I ran into, is a React page being rendered inside of an express app. I don't see how ky could be made aware of the original HTTP request causing the page render, without requiring quite some developer effort.
from ky.
Related Issues (20)
- [TypeError: signal.throwIfAborted is not a function (it is undefined)] in React Native context HOT 5
- feat: consider cookiejar support HOT 4
- Set TimeoutError#cause to be Request or URL HOT 2
- New request in afterResponse hook with formData content HOT 1
- How to download files from external host
- Allow for logging network errors and JSON parse errors HOT 5
- retry and beforeRetry not triggered HOT 8
- Use `X-RateLimit-Reset` header to determine retry delay HOT 9
- Consider extracting the HTTPError logic to an external module HOT 4
- Add generic for HTTPError to type the response HOT 2
- Aggregated error on server side. HOT 1
- [Question] Does it support HTTP/2 ? (compraison with Got) HOT 2
- Change the default retry amount HOT 2
- request.d.ts compile error for browsers HOT 3
- feature request: errors as returned values HOT 2
- Using FormData With Ky Causes Script to Never Terminate HOT 2
- Error in Safari: TypeError: Object.hasOwn is not a function HOT 1
- headers prop missing HOT 2
- Introduction of Object.hasOwn in Release 1.6.0 HOT 1
- Memory leak with deno/bun when catching errors
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 ky.