-
Notifications
You must be signed in to change notification settings - Fork 135
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: response throwing error due to javascript bug #117
Conversation
🦋 Changeset detectedLatest commit: 1e0ced2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -11,24 +11,24 @@ const BODY = Symbol(); | |||
const HEADERS = Symbol(); | |||
|
|||
function getString(data) { | |||
if (Buffer.isBuffer(data)) { | |||
if (Buffer.isBuffer(data) || ArrayBuffer.isView(data)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ArrayBuffer be converted like this:
Buffer.from(data).toString("utf8");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm when I do that, the result is empty.
When using NextResponse in middleware, the Uint8Array instance type becomes corrupted in some way due to cross realm context????
eg:
The
data instanceof Uint8Array
returns false b/c the data traveled far across realms: middleware => serverper chatGPT:
In this example, we use
ArrayBuffer.isView()
to check if theuint8Array
is a typed array, and then verify if its constructor matchesUint8Array
.By using specific methods for type checking, you can avoid potential issues with the
instanceof
operator.