1
+/**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ */
9
+
10
+import type {ReactNodeList} from 'shared/ReactTypes';
11
+
12
+import type {
13
+ RenderState,
14
+ ResumableState,
15
+ HoistableState,
16
+ FormatContext,
17
+} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
18
+
19
+import {pushStartInstance as pushStartInstanceImpl} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
20
+
21
+import type {
22
+ Destination,
23
+ Chunk,
24
+ PrecomputedChunk,
25
+} from 'react-server/src/ReactServerStreamConfig';
26
+
27
+import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
28
+
29
+import {NotPending} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
30
+
31
+import hasOwnProperty from 'shared/hasOwnProperty';
32
+
33
+// Allow embedding inside another Fizz render.
34
+export const isPrimaryRenderer = false;
35
+
36
+// Disable Client Hooks
37
+export const supportsClientAPIs = false;
38
+
39
+import {
40
+ stringToChunk,
41
+ stringToPrecomputedChunk,
42
+} from 'react-server/src/ReactServerStreamConfig';
43
+
44
+// this chunk is empty on purpose because we do not want to emit the DOCTYPE
45
+// when markup is rendering HTML
46
+export const doctypeChunk: PrecomputedChunk = stringToPrecomputedChunk('');
47
+
48
+export type {
49
+ RenderState,
50
+ ResumableState,
51
+ HoistableState,
52
+ FormatContext,
53
+} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
54
+
55
+export {
56
+ getChildFormatContext,
57
+ makeId,
58
+ pushEndInstance,
59
+ pushStartCompletedSuspenseBoundary,
60
+ pushEndCompletedSuspenseBoundary,
61
+ pushFormStateMarkerIsMatching,
62
+ pushFormStateMarkerIsNotMatching,
63
+ writeStartSegment,
64
+ writeEndSegment,
65
+ writeCompletedSegmentInstruction,
66
+ writeCompletedBoundaryInstruction,
67
+ writeClientRenderBoundaryInstruction,
68
+ writeStartPendingSuspenseBoundary,
69
+ writeEndPendingSuspenseBoundary,
70
+ writeHoistablesForBoundary,
71
+ writePlaceholder,
72
+ writeCompletedRoot,
73
+ createRootFormatContext,
74
+ createRenderState,
75
+ createResumableState,
76
+ createHoistableState,
77
+ writePreamble,
78
+ writeHoistables,
79
+ writePostamble,
80
+ hoistHoistables,
81
+ resetResumableState,
82
+ completeResumableState,
83
+ emitEarlyPreloads,
84
+} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';
85
+
86
+import escapeTextForBrowser from 'react-dom-bindings/src/server/escapeTextForBrowser';
87
+
88
+export function pushStartInstance(
89
+ target: Array<Chunk | PrecomputedChunk>,
90
+ type: string,
91
+ props: Object,
92
+ resumableState: ResumableState,
93
+ renderState: RenderState,
94
+ hoistableState: null | HoistableState,
95
+ formatContext: FormatContext,
96
+ textEmbedded: boolean,
97
+ isFallback: boolean,
98
+): ReactNodeList {
99
+ for (const propKey in props) {
100
+ if (hasOwnProperty.call(props, propKey)) {
101
+ const propValue = props[propKey];
102
+ if (propKey === 'ref' && propValue != null) {
103
+ throw new Error(
104
+ 'Cannot pass ref in renderToMarkup because they will never be hydrated.',
105
+ );
106
+ }
107
+ if (typeof propValue === 'function') {
108
+ throw new Error(
109
+ 'Cannot pass event handlers (' +
110
+ propKey +
111
+ ') in renderToMarkup because ' +
112
+ 'the HTML will never be hydrated so they can never get called.',
113
+ );
114
+ }
115
+ }
116
+ }
117
+
118
+ return pushStartInstanceImpl(
119
+ target,
120
+ type,
121
+ props,
122
+ resumableState,
123
+ renderState,
124
+ hoistableState,
125
+ formatContext,
126
+ textEmbedded,
127
+ isFallback,
128
+ );
129
+}
130
+
131
+export function pushTextInstance(
132
+ target: Array<Chunk | PrecomputedChunk>,
133
+ text: string,
134
+ renderState: RenderState,
135
+ textEmbedded: boolean,
136
+): boolean {
137
+ // Markup doesn't need any termination.
138
+ target.push(stringToChunk(escapeTextForBrowser(text)));
139
+ return false;
140
+}
141
+
142
+export function pushSegmentFinale(
143
+ target: Array<Chunk | PrecomputedChunk>,
144
+ renderState: RenderState,
145
+ lastPushedText: boolean,
146
+ textEmbedded: boolean,
147
+): void {
148
+ // Markup doesn't need any termination.
149
+ return;
150
+}
151
+
152
+export function writeStartCompletedSuspenseBoundary(
153
+ destination: Destination,
154
+ renderState: RenderState,
155
+): boolean {
156
+ // Markup doesn't have any instructions.
157
+ return true;
158
+}
159
+export function writeStartClientRenderedSuspenseBoundary(
160
+ destination: Destination,
161
+ renderState: RenderState,
162
+ // flushing these error arguments are not currently supported in this legacy streaming format.
163
+ errorDigest: ?string,
164
+ errorMessage: ?string,
165
+ errorStack: ?string,
166
+ errorComponentStack: ?string,
167
+): boolean {
168
+ // Markup doesn't have any instructions.
169
+ return true;
170
+}
171
+
172
+export function writeEndCompletedSuspenseBoundary(
173
+ destination: Destination,
174
+ renderState: RenderState,
175
+): boolean {
176
+ // Markup doesn't have any instructions.
177
+ return true;
178
+}
179
+export function writeEndClientRenderedSuspenseBoundary(
180
+ destination: Destination,
181
+ renderState: RenderState,
182
+): boolean {
183
+ // Markup doesn't have any instructions.
184
+ return true;
185
+}
186
+
187
+export type TransitionStatus = FormStatus;
188
+export const NotPendingTransition: TransitionStatus = NotPending;