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 =
let initialServerDataLoaded = false
let initialServerDataFlushed = false
type IsBootStrap = 0
type ResponsePartial = string
function nextServerDataCallback(seg: IsBootStrap | ResponsePartial): number {
if (seg === 0) {
function nextServerDataCallback(
seg: [isBootStrap: 0] | [isNotBootstrap: 1, responsePartial: string]
): number {
if (seg[0] === 0) {
initialServerDataBuffer = []
} else {
if (!initialServerDataBuffer)
throw new Error('Unexpected server data: missing bootstrap script.')
if (initialServerDataWriter) {
initialServerDataWriter.enqueue(encoder.encode(seg))
initialServerDataWriter.enqueue(encoder.encode(seg[1]))
} else {
initialServerDataBuffer.push(seg)
initialServerDataBuffer.push(seg[1])
}
}
return 0
......
......@@ -10,10 +10,10 @@ declare global {
var __next_require__: (id: string) => any
var __next_chunk_load__: (id: string) => Promise
type isBootStrap = 0
type responsePartial = string
var __next_f: (isBootStrap | responsePartial)[]
var __next_f: (
| [isBootStrap: 0]
| [isNotBootstrap: 1, responsePartial: string]
)[]
var next: {
version: string
appDir?: boolean
......
......@@ -116,19 +116,19 @@ let initialServerDataWriter: ReadableStreamDefaultController | undefined =
let initialServerDataLoaded = false
let initialServerDataFlushed = false
type IsBootStrap = 0
type ResponsePartial = string
function nextServerDataCallback(seg: IsBootStrap | ResponsePartial): void {
if (seg === 0) {
function nextServerDataCallback(
seg: [isBootStrap: 0] | [isNotBootstrap: 1, responsePartial: string]
): void {
if (seg[0] === 0) {
initialServerDataBuffer = []
} else {
if (!initialServerDataBuffer)
throw new Error('Unexpected server data: missing bootstrap script.')
if (initialServerDataWriter) {
initialServerDataWriter.enqueue(encoder.encode(seg))
initialServerDataWriter.enqueue(encoder.encode(seg[1]))
} else {
initialServerDataBuffer.push(seg)
initialServerDataBuffer.push(seg[1])
}
}
}
......
......@@ -53,7 +53,7 @@ export function useFlightResponse(
writer.write(
encodeText(
`${startScriptTag}(self.__next_f=self.__next_f||[]).push(${htmlEscapeJsonString(
JSON.stringify(0)
JSON.stringify([0])
)})</script>`
)
)
......@@ -63,14 +63,8 @@ export function useFlightResponse(
writer.close()
} else {
const responsePartial = decodeText(value, textDecoder)
const scripts = `${startScriptTag}__next_f.push(${htmlEscapeJsonString(
// Since the inlined payload is always a JSON-ish encoded string with
// 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, "'")
const scripts = `${startScriptTag}self.__next_f.push(${htmlEscapeJsonString(
JSON.stringify([1, responsePartial])
)})</script>`
writer.write(encodeText(scripts))
......
......@@ -15,11 +15,8 @@ createNextDescribe(
})
it('should allow to have a valid /not-found route', async () => {
const browser = await next.browser('/not-found')
await check(
() => browser.elementByCss('h1').text(),
`I'm still a valid page`
)
const html = await next.render('/not-found')
expect(html).toContain("I'm still a valid page")
})
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