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

[fix] adapter-netlify: encode UInt8Array response bodies as base64 #2630

Merged
merged 2 commits into from
Oct 20, 2021
Merged

[fix] adapter-netlify: encode UInt8Array response bodies as base64 #2630

merged 2 commits into from
Oct 20, 2021

Conversation

Xenonym
Copy link
Contributor

@Xenonym Xenonym commented Oct 18, 2021

If an endpoint returns a UInt8Array body (e.g. for binary content), the function handler will fail as a Netlify function response body needs to be either a string or base64 encoded.

Let's encode UInt8Array response bodies as base64 so that endpoints returning UInt8Arrays function properly with the Netlify adapter.

@changeset-bot
Copy link

changeset-bot bot commented Oct 18, 2021

🦋 Changeset detected

Latest commit: d1acf08

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-netlify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

If an endpoint returns a UInt8Array body (e.g. for binary content), the
function handler will fail as a Netlify function response body needs to
be either a string or base64 encoded.

Let's encode UInt8Array response bodies as base64 so that endpoints
returning UInt8Arrays function properly with the Netlify adapter.
splitHeaders is an internal variable, so it should be snake_cased.
@benmccann benmccann merged commit 5b0a4c5 into sveltejs:master Oct 20, 2021
@Xenonym Xenonym deleted the fix/adapter-netlify-binary-response branch October 20, 2021 17:06
@Egnus
Copy link

Egnus commented Oct 25, 2021

Hi team, since this has been merged into version 1.0.0-next.34 I am getting in my netlify server this:

{
  "errorType": "TypeError",
  "errorMessage": "The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined",
  "trace": [
  "TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined",
  "    at Function.from (buffer.js:330:9)",
  "    at Runtime.handler (/var/task/.netlify/functions-internal/__render.js:21073:18)"
  ]
}

The given line in the __render.jswas like this:

var SignInSection = create_ssr_component(($$result, $$props, $$bindings, slots) => {

I believe more people are going to start having this issue as well.
I had to lock my version to 1.0.0-next.33 to avoid this problem.
For a little bit of more context, the page fails to load when there is a redirect in the first load to another page (signIn), where I did an initial fetch and some promises during the load phase.
But if I put the correct expected path then the page is loaded without issues. In earlier versions than 34, there is a SSR redirect and the page goes directly to the Signin page without issues.

@JeanJPNM
Copy link
Contributor

I will fix it as soon as I get home

@Xenonym
Copy link
Contributor Author

Xenonym commented Oct 25, 2021

@JeanJPNM there's already a fix #2682 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants