MCPcopy
hub / github.com/vercel/next.js / nextServerDataRegisterWriter

Function nextServerDataRegisterWriter

packages/next/src/client/app-index.tsx:125–154  ·  view source on GitHub ↗
(ctr: ReadableStreamDefaultController)

Source from the content-addressed store, hash-verified

123// `initialServerDataFlushed` to make sure the writer will be closed and
124// `initialServerDataBuffer` will be cleared in the right time.
125function nextServerDataRegisterWriter(ctr: ReadableStreamDefaultController) {
126 if (initialServerDataBuffer) {
127 initialServerDataBuffer.forEach((val) => {
128 ctr.enqueue(typeof val === 'string' ? encoder.encode(val) : val)
129 })
130 if (initialServerDataLoaded && !initialServerDataFlushed) {
131 // Instant Navigation Testing API: don't close or error the inline
132 // Flight stream. The static shell has no inline Flight data, so the
133 // stream is empty. Closing it would cause React to log an error about
134 // missing data. Leaving it open lets React treat any holes as
135 // "still suspended." Hydration uses the separately fetched RSC payload
136 // (self.__next_instant_test), not this stream.
137 if (isStreamErrorOrUnfinished(ctr)) {
138 if (!instantTestStaticFetch) {
139 ctr.error(
140 new Error(
141 'The connection to the page was unexpectedly closed, possibly due to the stop button being clicked, loss of Wi-Fi, or an unstable internet connection.'
142 )
143 )
144 }
145 } else {
146 ctr.close()
147 }
148 initialServerDataFlushed = true
149 initialServerDataBuffer = undefined
150 }
151 }
152
153 initialServerDataWriter = ctr
154}
155
156// When `DOMContentLoaded`, we can close all pending writers to finish hydration.
157const DOMContentLoaded = function () {

Callers

nothing calls this directly

Calls 6

encodeMethod · 0.65
errorMethod · 0.65
closeMethod · 0.65
forEachMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected