Unverified Commit d2838ce3 authored by Ethan Arrowood's avatar Ethan Arrowood Committed by GitHub

Simplify `createRootLayoutValidatorStream` (#63484)

This PR is a follow up to #63427 and simplifies the
`createRootLayoutValidatorStream` function to check each chunk
individually instead of combining all of them into one. This should
improve performance

Closes NEXT-2868
parent d4f5368f
...@@ -439,38 +439,26 @@ export function createRootLayoutValidatorStream(): TransformStream< ...@@ -439,38 +439,26 @@ export function createRootLayoutValidatorStream(): TransformStream<
> { > {
let foundHtml = false let foundHtml = false
let foundBody = false let foundBody = false
let chunks: Uint8Array[] = []
let size = 0
return new TransformStream({ return new TransformStream({
async transform(chunk, controller) { async transform(chunk, controller) {
chunks.push(chunk)
size += chunk.length
controller.enqueue(chunk)
},
flush(controller) {
const content = new Uint8Array(size)
let offset = 0
for (const chunk of chunks) {
content.set(chunk, offset)
offset += chunk.length
}
// Peek into the streamed chunk to see if the tags are present. // Peek into the streamed chunk to see if the tags are present.
if (!foundHtml || !foundBody) {
if ( if (
!foundHtml && !foundHtml &&
indexOfUint8Array(content, ENCODED_TAGS.OPENING.HTML) > -1 indexOfUint8Array(chunk, ENCODED_TAGS.OPENING.HTML) > -1
) { ) {
foundHtml = true foundHtml = true
} }
if ( if (
!foundBody && !foundBody &&
indexOfUint8Array(content, ENCODED_TAGS.OPENING.BODY) > -1 indexOfUint8Array(chunk, ENCODED_TAGS.OPENING.BODY) > -1
) { ) {
foundBody = true foundBody = true
} }
}
controller.enqueue(chunk)
},
flush(controller) {
const missingTags: typeof window.__next_root_layout_missing_tags = [] const missingTags: typeof window.__next_root_layout_missing_tags = []
if (!foundHtml) missingTags.push('html') if (!foundHtml) missingTags.push('html')
if (!foundBody) missingTags.push('body') if (!foundBody) missingTags.push('body')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment