Skip to content

Commit 6ef466c

Browse files
authored
make preamble and postamble types explicit and fix typo (#25102)
1 parent 796d318 commit 6ef466c

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ function pushLink(
10841084
pushAttribute(target, responseState, 'data-rprec', propValue);
10851085
} else if (__DEV__) {
10861086
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.`,
10881088
);
10891089
}
10901090
break;
@@ -1238,27 +1238,27 @@ function pushStartTitle(
12381238

12391239
function pushStartHead(
12401240
target: Array<Chunk | PrecomputedChunk>,
1241-
preamble: ?Array<Chunk | PrecomputedChunk>,
1241+
preamble: Array<Chunk | PrecomputedChunk>,
12421242
props: Object,
12431243
tag: string,
12441244
responseState: ResponseState,
12451245
): ReactNodeList {
12461246
// 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;
12481248

12491249
return pushStartGenericElement(target, props, tag, responseState);
12501250
}
12511251

12521252
function pushStartHtml(
12531253
target: Array<Chunk | PrecomputedChunk>,
1254-
preamble: ?Array<Chunk | PrecomputedChunk>,
1254+
preamble: Array<Chunk | PrecomputedChunk>,
12551255
props: Object,
12561256
tag: string,
12571257
formatContext: FormatContext,
12581258
responseState: ResponseState,
12591259
): ReactNodeList {
12601260
// 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;
12621262

12631263
if (formatContext.insertionMode === ROOT_HTML_MODE) {
12641264
// 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>');
14851485

14861486
export function pushStartInstance(
14871487
target: Array<Chunk | PrecomputedChunk>,
1488-
preamble: ?Array<Chunk | PrecomputedChunk>,
1488+
preamble: Array<Chunk | PrecomputedChunk>,
14891489
type: string,
14901490
props: Object,
14911491
responseState: ResponseState,
@@ -1607,7 +1607,7 @@ const endTag2 = stringToPrecomputedChunk('>');
16071607

16081608
export function pushEndInstance(
16091609
target: Array<Chunk | PrecomputedChunk>,
1610-
postamble: ?Array<Chunk | PrecomputedChunk>,
1610+
postamble: Array<Chunk | PrecomputedChunk>,
16111611
type: string,
16121612
props: Object,
16131613
): void {
@@ -1636,8 +1636,7 @@ export function pushEndInstance(
16361636
// Postamble end tags
16371637
case 'body':
16381638
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;
16411640
// Intentional fallthrough
16421641
default: {
16431642
target.push(endTag1, stringToChunk(type), endTag2);

packages/react-native-renderer/src/server/ReactNativeServerFormatConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function pushTextInstance(
137137

138138
export function pushStartInstance(
139139
target: Array<Chunk | PrecomputedChunk>,
140-
preamble: ?Array<Chunk | PrecomputedChunk>,
140+
preamble: Array<Chunk | PrecomputedChunk>,
141141
type: string,
142142
props: Object,
143143
responseState: ResponseState,
@@ -154,7 +154,7 @@ export function pushStartInstance(
154154

155155
export function pushEndInstance(
156156
target: Array<Chunk | PrecomputedChunk>,
157-
postamble: ?Array<Chunk | PrecomputedChunk>,
157+
postamble: Array<Chunk | PrecomputedChunk>,
158158
type: string,
159159
props: Object,
160160
): void {

packages/react-server/src/ReactFizzServer.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ export opaque type Request = {
201201
clientRenderedBoundaries: Array<SuspenseBoundary>, // Errored or client rendered but not yet flushed.
202202
completedBoundaries: Array<SuspenseBoundary>, // Completed but not yet fully flushed boundaries to show.
203203
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
206206
// onError is called when an error happens anywhere in the tree. It might recover.
207207
// The return string is used in production primarily to avoid leaking internals, secondarily to save bytes.
208208
// Returning null/undefined will cause a defualt error message in production
@@ -275,8 +275,8 @@ export function createRequest(
275275
clientRenderedBoundaries: [],
276276
completedBoundaries: [],
277277
partialBoundaries: [],
278-
preamble: enableFloat ? [] : null,
279-
postamble: enableFloat ? [] : null,
278+
preamble: [],
279+
postamble: [],
280280
onError: onError === undefined ? defaultErrorHandler : onError,
281281
onAllReady: onAllReady === undefined ? noop : onAllReady,
282282
onShellReady: onShellReady === undefined ? noop : onShellReady,
@@ -2074,9 +2074,7 @@ function flushCompletedQueues(
20742074
if (completedRootSegment !== null) {
20752075
if (request.pendingRootTasks === 0) {
20762076
if (enableFloat) {
2077-
const preamble: Array<
2078-
Chunk | PrecomputedChunk,
2079-
> = (request.preamble: any);
2077+
const preamble = request.preamble;
20802078
for (i = 0; i < preamble.length; i++) {
20812079
// we expect the preamble to be tiny and will ignore backpressure
20822080
writeChunk(destination, preamble[i]);
@@ -2167,9 +2165,7 @@ function flushCompletedQueues(
21672165
// either they have pending task or they're complete.
21682166
) {
21692167
if (enableFloat) {
2170-
const postamble: Array<
2171-
Chunk | PrecomputedChunk,
2172-
> = (request.postamble: any);
2168+
const postamble = request.postamble;
21732169
for (let i = 0; i < postamble.length; i++) {
21742170
writeChunk(destination, postamble[i]);
21752171
}

scripts/error-codes/codes.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,5 +422,5 @@
422422
"434": "`dangerouslySetInnerHTML` does not make sense on <title>.",
423423
"435": "Unexpected Suspense handler tag (%s). This is a bug in React.",
424424
"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."
426426
}

0 commit comments

Comments
 (0)