fix sveltekit type error in firebase-frameworks - #673
Open
leoortizz wants to merge 1 commit into
Open
Conversation
Node 24 / current @types/node no longer lets Buffer satisfy the DOM BodyInit type, breaking tsc. Wrap rawBody as new Uint8Array(...) at the Request construction site; runtime behavior is unchanged.
There was a problem hiding this comment.
Code Review
This pull request updates the SvelteKit request handler to wrap the request's raw body in a Uint8Array. The reviewer pointed out that instantiating a new Uint8Array creates an unnecessary memory copy, and suggested casting the existing buffer to Uint8Array instead to improve performance and reduce memory overhead.
| method: request.method, | ||
| headers: toSvelteKitHeaders(request.headers), | ||
| body: request.rawBody ? request.rawBody : null, | ||
| body: request.rawBody ? new Uint8Array(request.rawBody) : null, |
There was a problem hiding this comment.
Using new Uint8Array(request.rawBody) creates a copy of the entire buffer in memory, which introduces unnecessary performance and memory overhead, especially for large request bodies. Since Buffer inherits from Uint8Array at runtime, you can safely cast it to Uint8Array to satisfy the TypeScript compiler without any runtime overhead.
Suggested change
| body: request.rawBody ? new Uint8Array(request.rawBody) : null, | |
| body: request.rawBody ? (request.rawBody as Uint8Array) : null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tscfails under Node 24 / latest@types/nodebecauseBufferno longer satisfies the DOMBodyInittype:Wrap
request.rawBodyasnew Uint8Array(...). ValidBodyInit, runtime unchanged (Bufferis aUint8Arraysubclass).Verified: build passes, and POST bodies still round-trip through a real SvelteKit app.