Potential pitfall around filterSerializedResponseHeaders
#7027
Replies: 3 comments 6 replies
-
@Nickersoft How did you set up |
Beta Was this translation helpful? Give feedback.
-
Trying to implement a fetch call to a paginated api that uses headers Total, Per-Page, I setup the filterSerializedResponseHeaders to work on serverside calls, but the clientside load calls do not get the headers back. |
Beta Was this translation helpful? Give feedback.
-
I had the same problem with my response headers in page load function. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey SK folks,
Just wanted to start a discussion regarding the
filterSerializedResponseHeaders
option, as I just spent the better part of the last week trying to chase down why my code wasn't working 😅 Like many other devs, I've been using URQL to call GraphQL in my app, and have quite a few server-side queries I use to pre-render pages. Something I didn't realize, however, is that with most GraphQL clients, receiving anything from the server that isn't ofcontent-type
application/json
is interpreted as an error by the client. By default, SvelteKit doesn't serialize any headers during SSR, which causes the rehydration of my GraphQL queries to havecontent-type
text/plain
(the default content type ofnew Response()
) and leads to a crash of my page.It wasn't until I added breakpoints throughout SvelteKit's
fetch
implementation that I realized what was going on and stumbled acrossfilterSerializedResponseHeaders
. Using this option to whitelistcontent-type
in myhandle()
method naturally fixed my issue.However, given the plethora of devs who use GraphQL, I can't help but feel this could be a potential pitfall for newcomers to SvelteKit. I wanted to start this thread for a couple of reasons:
content-type
should be required by SvelteKit apps?I know a lot of folks have said that the SK docs should be improved, and I also know that there's already been some confusion regarding getting empty response headers on page rehydration. So I'm curious how everyone feels about all this.
Thanks! Looking forward to 1.0 🚀
Beta Was this translation helpful? Give feedback.
All reactions