@samitouri / QOS-React-2 / commits / 6ef466c681

make preamble and postamble types explicit and fix typo (#25102)

Josh Story committed Aug 16, 2022 at 04:17 UTC 6ef466c681c987493432608be56f2e01f94268d7
4 files changed +17 -22
packages/react-dom/src/server/ReactDOMServerFormatConfig.js
+8 -9
@@ -1084,7 +1084,7 @@ function pushLink(
1084 pushAttribute(target, responseState, 'data-rprec', propValue);
1085 } else if (__DEV__) {
1086 throw new Error(
1087 - `the "precedence" prop for links to stylehseets expects to receive a string but received something of type "${typeof propValue}" instead.`,
1087 + `the "precedence" prop for links to stylesheets expects to receive a string but received something of type "${typeof propValue}" instead.`,
1088 );
1089 }
1090 break;
@@ -1238,27 +1238,27 @@ function pushStartTitle(
1238
1239 function pushStartHead(
1240 target: Array<Chunk | PrecomputedChunk>,
1241 - preamble: ?Array<Chunk | PrecomputedChunk>,
1241 + preamble: Array<Chunk | PrecomputedChunk>,
1242 props: Object,
1243 tag: string,
1244 responseState: ResponseState,
1245 ): ReactNodeList {
1246 // Preamble type is nullable for feature off cases but is guaranteed when feature is on
1247 - target = enableFloat ? (preamble: any) : target;
1247 + target = enableFloat ? preamble : target;
1248
1249 return pushStartGenericElement(target, props, tag, responseState);
1250 }
1251
1252 function pushStartHtml(
1253 target: Array<Chunk | PrecomputedChunk>,
1254 - preamble: ?Array<Chunk | PrecomputedChunk>,
1254 + preamble: Array<Chunk | PrecomputedChunk>,
1255 props: Object,
1256 tag: string,
1257 formatContext: FormatContext,
1258 responseState: ResponseState,
1259 ): ReactNodeList {
1260 // Preamble type is nullable for feature off cases but is guaranteed when feature is on
1261 - target = enableFloat ? (preamble: any) : target;
1261 + target = enableFloat ? preamble : target;
1262
1263 if (formatContext.insertionMode === ROOT_HTML_MODE) {
1264 // If we're rendering the html tag and we're at the root (i.e. not in foreignObject)
@@ -1485,7 +1485,7 @@ const DOCTYPE: PrecomputedChunk = stringToPrecomputedChunk('<!DOCTYPE html>');
1485
1486 export function pushStartInstance(
1487 target: Array<Chunk | PrecomputedChunk>,
1488 - preamble: ?Array<Chunk | PrecomputedChunk>,
1488 + preamble: Array<Chunk | PrecomputedChunk>,
1489 type: string,
1490 props: Object,
1491 responseState: ResponseState,
@@ -1607,7 +1607,7 @@ const endTag2 = stringToPrecomputedChunk('>');
1607
1608 export function pushEndInstance(
1609 target: Array<Chunk | PrecomputedChunk>,
1610 - postamble: ?Array<Chunk | PrecomputedChunk>,
1610 + postamble: Array<Chunk | PrecomputedChunk>,
1611 type: string,
1612 props: Object,
1613 ): void {
@@ -1636,8 +1636,7 @@ export function pushEndInstance(
1636 // Postamble end tags
1637 case 'body':
1638 case 'html':
1639 - // Preamble type is nullable for feature off cases but is guaranteed when feature is on
1640 - target = enableFloat ? (postamble: any) : target;
1639 + target = enableFloat ? postamble : target;
1640 // Intentional fallthrough
1641 default: {
1642 target.push(endTag1, stringToChunk(type), endTag2);
packages/react-native-renderer/src/server/ReactNativeServerFormatConfig.js
+2 -2
@@ -137,7 +137,7 @@ export function pushTextInstance(
137
138 export function pushStartInstance(
139 target: Array<Chunk | PrecomputedChunk>,
140 - preamble: ?Array<Chunk | PrecomputedChunk>,
140 + preamble: Array<Chunk | PrecomputedChunk>,
141 type: string,
142 props: Object,
143 responseState: ResponseState,
@@ -154,7 +154,7 @@ export function pushStartInstance(
154
155 export function pushEndInstance(
156 target: Array<Chunk | PrecomputedChunk>,
157 - postamble: ?Array<Chunk | PrecomputedChunk>,
157 + postamble: Array<Chunk | PrecomputedChunk>,
158 type: string,
159 props: Object,
160 ): void {
packages/react-server/src/ReactFizzServer.js
+6 -10
@@ -201,8 +201,8 @@ export opaque type Request = {
201 clientRenderedBoundaries: Array<SuspenseBoundary>, // Errored or client rendered but not yet flushed.
202 completedBoundaries: Array<SuspenseBoundary>, // Completed but not yet fully flushed boundaries to show.
203 partialBoundaries: Array<SuspenseBoundary>, // Partially completed boundaries that can flush its segments early.
204 - +preamble: ?Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted before any segment chunks.
205 - +postamble: ?Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted after segments, waiting for all pending root tasks to finish
204 + +preamble: Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted before any segment chunks.
205 + +postamble: Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted after segments, waiting for all pending root tasks to finish
206 // onError is called when an error happens anywhere in the tree. It might recover.
207 // The return string is used in production primarily to avoid leaking internals, secondarily to save bytes.
208 // Returning null/undefined will cause a defualt error message in production
@@ -275,8 +275,8 @@ export function createRequest(
275 clientRenderedBoundaries: [],
276 completedBoundaries: [],
277 partialBoundaries: [],
278 - preamble: enableFloat ? [] : null,
279 - postamble: enableFloat ? [] : null,
278 + preamble: [],
279 + postamble: [],
280 onError: onError === undefined ? defaultErrorHandler : onError,
281 onAllReady: onAllReady === undefined ? noop : onAllReady,
282 onShellReady: onShellReady === undefined ? noop : onShellReady,
@@ -2074,9 +2074,7 @@ function flushCompletedQueues(
2074 if (completedRootSegment !== null) {
2075 if (request.pendingRootTasks === 0) {
2076 if (enableFloat) {
2077 - const preamble: Array<
2078 - Chunk | PrecomputedChunk,
2079 - > = (request.preamble: any);
2077 + const preamble = request.preamble;
2078 for (i = 0; i < preamble.length; i++) {
2079 // we expect the preamble to be tiny and will ignore backpressure
2080 writeChunk(destination, preamble[i]);
@@ -2167,9 +2165,7 @@ function flushCompletedQueues(
2165 // either they have pending task or they're complete.
2166 ) {
2167 if (enableFloat) {
2170 - const postamble: Array<
2171 - Chunk | PrecomputedChunk,
2172 - > = (request.postamble: any);
2168 + const postamble = request.postamble;
2169 for (let i = 0; i < postamble.length; i++) {
2170 writeChunk(destination, postamble[i]);
2171 }
scripts/error-codes/codes.json
+1 -1
@@ -422,5 +422,5 @@
422 "434": "`dangerouslySetInnerHTML` does not make sense on <title>.",
423 "435": "Unexpected Suspense handler tag (%s). This is a bug in React.",
424 "436": "Stylesheet resources need a unique representation in the DOM while hydrating and more than one matching DOM Node was found. To fix, ensure you are only rendering one stylesheet link with an href attribute of \"%s\".",
425 - "437": "the \"precedence\" prop for links to stylehseets expects to receive a string but received something of type \"%s\" instead."
425 + "437": "the \"precedence\" prop for links to stylesheets expects to receive a string but received something of type \"%s\" instead."
426 }