Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make preamble and postamble types explicit and fix typo #25102

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions packages/react-dom/src/server/ReactDOMServerFormatConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ function pushLink(
pushAttribute(target, responseState, 'data-rprec', propValue);
} else if (__DEV__) {
throw new Error(
`the "precedence" prop for links to stylehseets expects to receive a string but received something of type "${typeof propValue}" instead.`,
`the "precedence" prop for links to stylesheets expects to receive a string but received something of type "${typeof propValue}" instead.`,
);
}
break;
Expand Down Expand Up @@ -1238,27 +1238,27 @@ function pushStartTitle(

function pushStartHead(
target: Array<Chunk | PrecomputedChunk>,
preamble: ?Array<Chunk | PrecomputedChunk>,
preamble: Array<Chunk | PrecomputedChunk>,
props: Object,
tag: string,
responseState: ResponseState,
): ReactNodeList {
// Preamble type is nullable for feature off cases but is guaranteed when feature is on
target = enableFloat ? (preamble: any) : target;
target = enableFloat ? preamble : target;

return pushStartGenericElement(target, props, tag, responseState);
}

function pushStartHtml(
target: Array<Chunk | PrecomputedChunk>,
preamble: ?Array<Chunk | PrecomputedChunk>,
preamble: Array<Chunk | PrecomputedChunk>,
props: Object,
tag: string,
formatContext: FormatContext,
responseState: ResponseState,
): ReactNodeList {
// Preamble type is nullable for feature off cases but is guaranteed when feature is on
target = enableFloat ? (preamble: any) : target;
target = enableFloat ? preamble : target;

if (formatContext.insertionMode === ROOT_HTML_MODE) {
// If we're rendering the html tag and we're at the root (i.e. not in foreignObject)
Expand Down Expand Up @@ -1485,7 +1485,7 @@ const DOCTYPE: PrecomputedChunk = stringToPrecomputedChunk('<!DOCTYPE html>');

export function pushStartInstance(
target: Array<Chunk | PrecomputedChunk>,
preamble: ?Array<Chunk | PrecomputedChunk>,
preamble: Array<Chunk | PrecomputedChunk>,
type: string,
props: Object,
responseState: ResponseState,
Expand Down Expand Up @@ -1607,7 +1607,7 @@ const endTag2 = stringToPrecomputedChunk('>');

export function pushEndInstance(
target: Array<Chunk | PrecomputedChunk>,
postamble: ?Array<Chunk | PrecomputedChunk>,
postamble: Array<Chunk | PrecomputedChunk>,
type: string,
props: Object,
): void {
Expand Down Expand Up @@ -1636,8 +1636,7 @@ export function pushEndInstance(
// Postamble end tags
case 'body':
case 'html':
// Preamble type is nullable for feature off cases but is guaranteed when feature is on
target = enableFloat ? (postamble: any) : target;
target = enableFloat ? postamble : target;
// Intentional fallthrough
default: {
target.push(endTag1, stringToChunk(type), endTag2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function pushTextInstance(

export function pushStartInstance(
target: Array<Chunk | PrecomputedChunk>,
preamble: ?Array<Chunk | PrecomputedChunk>,
preamble: Array<Chunk | PrecomputedChunk>,
type: string,
props: Object,
responseState: ResponseState,
Expand All @@ -154,7 +154,7 @@ export function pushStartInstance(

export function pushEndInstance(
target: Array<Chunk | PrecomputedChunk>,
postamble: ?Array<Chunk | PrecomputedChunk>,
postamble: Array<Chunk | PrecomputedChunk>,
type: string,
props: Object,
): void {
Expand Down
16 changes: 6 additions & 10 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export opaque type Request = {
clientRenderedBoundaries: Array<SuspenseBoundary>, // Errored or client rendered but not yet flushed.
completedBoundaries: Array<SuspenseBoundary>, // Completed but not yet fully flushed boundaries to show.
partialBoundaries: Array<SuspenseBoundary>, // Partially completed boundaries that can flush its segments early.
+preamble: ?Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted before any segment chunks.
+postamble: ?Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted after segments, waiting for all pending root tasks to finish
+preamble: Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted before any segment chunks.
+postamble: Array<Chunk | PrecomputedChunk>, // Chunks that need to be emitted after segments, waiting for all pending root tasks to finish
// onError is called when an error happens anywhere in the tree. It might recover.
// The return string is used in production primarily to avoid leaking internals, secondarily to save bytes.
// Returning null/undefined will cause a defualt error message in production
Expand Down Expand Up @@ -275,8 +275,8 @@ export function createRequest(
clientRenderedBoundaries: [],
completedBoundaries: [],
partialBoundaries: [],
preamble: enableFloat ? [] : null,
postamble: enableFloat ? [] : null,
preamble: [],
postamble: [],
onError: onError === undefined ? defaultErrorHandler : onError,
onAllReady: onAllReady === undefined ? noop : onAllReady,
onShellReady: onShellReady === undefined ? noop : onShellReady,
Expand Down Expand Up @@ -2074,9 +2074,7 @@ function flushCompletedQueues(
if (completedRootSegment !== null) {
if (request.pendingRootTasks === 0) {
if (enableFloat) {
const preamble: Array<
Chunk | PrecomputedChunk,
> = (request.preamble: any);
const preamble = request.preamble;
for (i = 0; i < preamble.length; i++) {
// we expect the preamble to be tiny and will ignore backpressure
writeChunk(destination, preamble[i]);
Expand Down Expand Up @@ -2167,9 +2165,7 @@ function flushCompletedQueues(
// either they have pending task or they're complete.
) {
if (enableFloat) {
const postamble: Array<
Chunk | PrecomputedChunk,
> = (request.postamble: any);
const postamble = request.postamble;
for (let i = 0; i < postamble.length; i++) {
writeChunk(destination, postamble[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,5 +422,5 @@
"434": "`dangerouslySetInnerHTML` does not make sense on <title>.",
"435": "Unexpected Suspense handler tag (%s). This is a bug in React.",
"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\".",
"437": "the \"precedence\" prop for links to stylehseets expects to receive a string but received something of type \"%s\" instead."
"437": "the \"precedence\" prop for links to stylesheets expects to receive a string but received something of type \"%s\" instead."
}