Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9d0a1820
Commit
9d0a1820
authored
Feb 09, 2026
by
Jimmy Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: dedupe inlined flight bootstrap encoding
parent
108af215
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
37 deletions
+20
-37
use-flight-response.tsx
packages/next/src/server/app-render/use-flight-response.tsx
+20
-37
No files found.
packages/next/src/server/app-render/use-flight-response.tsx
View file @
9d0a1820
...
@@ -238,17 +238,7 @@ function writeInitialInstructions(
...
@@ -238,17 +238,7 @@ function writeInitialInstructions(
scriptStart
:
string
,
scriptStart
:
string
,
formState
:
unknown
|
null
formState
:
unknown
|
null
)
{
)
{
let
scriptContents
=
`(self.__next_f=self.__next_f||[]).push(
${
htmlEscapeJsonString
(
controller
.
enqueue
(
encodeInitialFlightData
(
scriptStart
,
formState
))
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_BOOTSTRAP
])
)}
)`
if
(
formState
!=
null
)
{
scriptContents
+=
`;self.__next_f.push(
${
htmlEscapeJsonString
(
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_FORM_STATE
,
formState
])
)}
)`
}
controller
.
enqueue
(
encoder
.
encode
(
`
${
scriptStart
}${
scriptContents
}
</script>`
))
}
}
function
writeFlightDataInstruction
(
function
writeFlightDataInstruction
(
...
@@ -302,6 +292,23 @@ function encodeFlightDataChunk(
...
@@ -302,6 +292,23 @@ function encodeFlightDataChunk(
)
)
}
}
function
encodeInitialFlightData
(
scriptStart
:
string
,
formState
:
unknown
|
null
):
Uint8Array
{
let
scriptContents
=
`(self.__next_f=self.__next_f||[]).push(
${
htmlEscapeJsonString
(
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_BOOTSTRAP
])
)}
)`
if
(
formState
!=
null
)
{
scriptContents
+=
`;self.__next_f.push(
${
htmlEscapeJsonString
(
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_FORM_STATE
,
formState
])
)}
)`
}
return
encoder
.
encode
(
`
${
scriptStart
}${
scriptContents
}
</script>`
)
}
/**
/**
* Creates a Node.js Readable that provides inline script tag chunks for writing
* Creates a Node.js Readable that provides inline script tag chunks for writing
* hydration data to the client outside the React render itself.
* hydration data to the client outside the React render itself.
...
@@ -336,19 +343,7 @@ export function createInlinedDataNodeStream(
...
@@ -336,19 +343,7 @@ export function createInlinedDataNodeStream(
try
{
try
{
if
(
!
bootstrapWritten
)
{
if
(
!
bootstrapWritten
)
{
bootstrapWritten
=
true
bootstrapWritten
=
true
let
scriptContents
=
`(self.__next_f=self.__next_f||[]).push(
${
htmlEscapeJsonString
(
this
.
push
(
encodeInitialFlightData
(
startScriptTag
,
formState
))
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_BOOTSTRAP
])
)}
)`
if
(
formState
!=
null
)
{
scriptContents
+=
`;self.__next_f.push(
${
htmlEscapeJsonString
(
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_FORM_STATE
,
formState
])
)}
)`
}
this
.
push
(
encoder
.
encode
(
`
${
startScriptTag
}${
scriptContents
}
</script>`
)
)
}
}
try
{
try
{
...
@@ -366,19 +361,7 @@ export function createInlinedDataNodeStream(
...
@@ -366,19 +361,7 @@ export function createInlinedDataNodeStream(
flush
(
callback
:
(
error
?:
Error
)
=>
void
)
{
flush
(
callback
:
(
error
?:
Error
)
=>
void
)
{
// If no data was ever received, still write the bootstrap
// If no data was ever received, still write the bootstrap
if
(
!
bootstrapWritten
)
{
if
(
!
bootstrapWritten
)
{
let
scriptContents
=
`(self.__next_f=self.__next_f||[]).push(
${
htmlEscapeJsonString
(
this
.
push
(
encodeInitialFlightData
(
startScriptTag
,
formState
))
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_BOOTSTRAP
])
)}
)`
if
(
formState
!=
null
)
{
scriptContents
+=
`;self.__next_f.push(
${
htmlEscapeJsonString
(
JSON
.
stringify
([
INLINE_FLIGHT_PAYLOAD_FORM_STATE
,
formState
])
)}
)`
}
this
.
push
(
encoder
.
encode
(
`
${
startScriptTag
}${
scriptContents
}
</script>`
)
)
}
}
callback
()
callback
()
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment