-
-
Notifications
You must be signed in to change notification settings - Fork 432
Export and cross-fetch don't play nice together #908
Comments
i think this neglects the reason this.fetch exists in the first place. it argues for better documentation on why sapper needs you to use this.fetch. |
Something else that's come up as a possibility is allowing users to attach their own stuff to the |
This isn't particularly viable as far as I can tell, as the |
Agreed. Arguably, I think my complaint is probably both a valid one, but arguably we also probably shouldn't do anything about it (necessarily). I mostly just wanted to explore the options. I'll probably close this in a day or two, unless someone comes up with a really bright idea on how to make it easier to wrap |
On second thought, this makes a good point. I even knew this.fetch was behaving differently on client and server—but I've noticed it's a Q that comes up all the time in the forums. "What can I use for server side fetching." And I wonder if it shouldn't be attached to import { fetch } from `@sapper/app` To be available everywhere? Then when people ask which fetch lib to use, we just tell them to use the internal one...??? |
again, that would likely be impractical if you thought through the implementation. imports are by design far more static than keep ideating tho, i can see you’re exploring different solutions bc it doesn’t feel right to you. perhaps more compiler magic...? |
Yeah, using an import from a module for this is also not too viable. You'd need the import to be different things on the client and on the server (which is doable, but fiddly), but on the server side you'd also need the import to somehow be aware of the relevant It's a lot simpler to just call |
+1 for preload helpers. Or maybe this pattern:
Could preload be a hook that receives context? |
The server's |
I understand that, sorry if I wasn't clear. I'm proposing that in the |
[Is your feature request related to a problem? Please describe.]
I spent a day and a half trying to figure out why export wasn't crawling any of my
*.json.js
files. The files were generated on export, just not crawled. These are from fetch API calls in preload functions/scripts.I'm tempted to call this a bug, but I discovered that when I started using
this.fetch
instead of cross-fetch, it started working correctly. So technically this isn't a bug if you use the preloaderthis.fetch
API correctly.[Describe the solution you'd like]
But that makes creating fetch API wrappers hard. I either have to explicitly pass
this.fetch
as an argument to a wrapper function. (I create reusableGET
andPOST
utility libraries/functions). Or I have to write out the same boilerplate again and again.I don't have a strict recommendation—maybe one would be to make
this.fetch
universally available—that's problematic too though. I'm tempted to say, let's actually strip out thethis.fetch
feature entirely, recommend using something like cross-fetch in its place, and then just fix that "bug."[Describe alternatives you've considered]
None.
[How important is this feature to you?]
Dunno. Maybe this is a "just me" issue, and it should be closed—maybe no one else will run into this. I thought it was worth discussing though.
The text was updated successfully, but these errors were encountered: