Unverified Commit 4bfc1eaf authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Revert "Optimize inlined Flight data array format" (#52039)

Reverts vercel/next.js#52028

revert temporarily and will re-land in next round release
parent 0123a9d5
...@@ -41,19 +41,19 @@ let initialServerDataWriter: ReadableStreamDefaultController | undefined = ...@@ -41,19 +41,19 @@ let initialServerDataWriter: ReadableStreamDefaultController | undefined =
let initialServerDataLoaded = false let initialServerDataLoaded = false
let initialServerDataFlushed = false let initialServerDataFlushed = false
type IsBootStrap = 0 function nextServerDataCallback(
type ResponsePartial = string seg: [isBootStrap: 0] | [isNotBootstrap: 1, responsePartial: string]
function nextServerDataCallback(seg: IsBootStrap | ResponsePartial): number { ): number {
if (seg === 0) { if (seg[0] === 0) {
initialServerDataBuffer = [] initialServerDataBuffer = []
} else { } else {
if (!initialServerDataBuffer) if (!initialServerDataBuffer)
throw new Error('Unexpected server data: missing bootstrap script.') throw new Error('Unexpected server data: missing bootstrap script.')
if (initialServerDataWriter) { if (initialServerDataWriter) {
initialServerDataWriter.enqueue(encoder.encode(seg)) initialServerDataWriter.enqueue(encoder.encode(seg[1]))
} else { } else {
initialServerDataBuffer.push(seg) initialServerDataBuffer.push(seg[1])
} }
} }
return 0 return 0
......
...@@ -10,10 +10,10 @@ declare global { ...@@ -10,10 +10,10 @@ declare global {
var __next_require__: (id: string) => any var __next_require__: (id: string) => any
var __next_chunk_load__: (id: string) => Promise var __next_chunk_load__: (id: string) => Promise
var __next_f: (
type isBootStrap = 0 | [isBootStrap: 0]
type responsePartial = string | [isNotBootstrap: 1, responsePartial: string]
var __next_f: (isBootStrap | responsePartial)[] )[]
var next: { var next: {
version: string version: string
appDir?: boolean appDir?: boolean
......
...@@ -116,19 +116,19 @@ let initialServerDataWriter: ReadableStreamDefaultController | undefined = ...@@ -116,19 +116,19 @@ let initialServerDataWriter: ReadableStreamDefaultController | undefined =
let initialServerDataLoaded = false let initialServerDataLoaded = false
let initialServerDataFlushed = false let initialServerDataFlushed = false
type IsBootStrap = 0 function nextServerDataCallback(
type ResponsePartial = string seg: [isBootStrap: 0] | [isNotBootstrap: 1, responsePartial: string]
function nextServerDataCallback(seg: IsBootStrap | ResponsePartial): void { ): void {
if (seg === 0) { if (seg[0] === 0) {
initialServerDataBuffer = [] initialServerDataBuffer = []
} else { } else {
if (!initialServerDataBuffer) if (!initialServerDataBuffer)
throw new Error('Unexpected server data: missing bootstrap script.') throw new Error('Unexpected server data: missing bootstrap script.')
if (initialServerDataWriter) { if (initialServerDataWriter) {
initialServerDataWriter.enqueue(encoder.encode(seg)) initialServerDataWriter.enqueue(encoder.encode(seg[1]))
} else { } else {
initialServerDataBuffer.push(seg) initialServerDataBuffer.push(seg[1])
} }
} }
} }
......
...@@ -53,7 +53,7 @@ export function useFlightResponse( ...@@ -53,7 +53,7 @@ export function useFlightResponse(
writer.write( writer.write(
encodeText( encodeText(
`${startScriptTag}(self.__next_f=self.__next_f||[]).push(${htmlEscapeJsonString( `${startScriptTag}(self.__next_f=self.__next_f||[]).push(${htmlEscapeJsonString(
JSON.stringify(0) JSON.stringify([0])
)})</script>` )})</script>`
) )
) )
...@@ -63,14 +63,8 @@ export function useFlightResponse( ...@@ -63,14 +63,8 @@ export function useFlightResponse(
writer.close() writer.close()
} else { } else {
const responsePartial = decodeText(value, textDecoder) const responsePartial = decodeText(value, textDecoder)
const scripts = `${startScriptTag}__next_f.push(${htmlEscapeJsonString( const scripts = `${startScriptTag}self.__next_f.push(${htmlEscapeJsonString(
// Since the inlined payload is always a JSON-ish encoded string with JSON.stringify([1, responsePartial])
// many double quotes, we can safely un-escape these quotes and use
// a single quote to wrap the string. This saves a lot of bytes.
JSON.stringify(responsePartial)
.replace(/\\"/g, '"')
.replace(/'/g, "\\'")
.replace(/(^")|("$)/g, "'")
)})</script>` )})</script>`
writer.write(encodeText(scripts)) writer.write(encodeText(scripts))
......
...@@ -15,11 +15,8 @@ createNextDescribe( ...@@ -15,11 +15,8 @@ createNextDescribe(
}) })
it('should allow to have a valid /not-found route', async () => { it('should allow to have a valid /not-found route', async () => {
const browser = await next.browser('/not-found') const html = await next.render('/not-found')
await check( expect(html).toContain("I'm still a valid page")
() => browser.elementByCss('h1').text(),
`I'm still a valid page`
)
}) })
if (isNextDev) { if (isNextDev) {
......
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