| 123 | // `initialServerDataFlushed` to make sure the writer will be closed and |
| 124 | // `initialServerDataBuffer` will be cleared in the right time. |
| 125 | function 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. |
| 157 | const DOMContentLoaded = function () { |