@samitouri / QOS-React-2 / commits / 5309f10285

Remove Flight Relay DOM/Native (#26828)

The bindings upstream in Relay has been removed so we don't need these builds anymore. The idea is to revisit an FB integration of Flight but it wouldn't use the Relay specific bindings. It's a bit unclear how it would look but likely more like the OSS version so not worth keeping these around. The `dom-relay` name also included the FB specific Fizz implementation of the streaming config so I renamed that to `dom-fb`. There's no Fizz implementation for Native yet so I just removed `native-relay`. We created a configurable fork for how to encode the output of Flight and the Relay implementation encoded it as JSON objects instead of strings/streams. The new implementation would likely be more stream-like and just encode it directly as string/binary chunks. So I removed those indirections so that this can just be declared inline in ReactFlightServer/Client.

Sebastian Markbåge committed May 17, 2023 at 20:33 UTC 5309f102854475030fb91ab732141411b49c1126
72 files changed +294 -2620
.eslintrc.js
-1
@@ -416,7 +416,6 @@ module.exports = {
416 {
417 files: [
418 'packages/react-native-renderer/**/*.js',
419 - 'packages/react-server-native-relay/**/*.js',
419 ],
420 globals: {
421 nativeFabricUIManager: 'readonly',
packages/react-client/flight.js
+1 -1
@@ -7,4 +7,4 @@
7 * @flow
8 */
9
10 -export * from './src/ReactFlightClientStream';
10 +export * from './src/ReactFlightClient';
packages/react-client/src/ReactFlightClient.js
+127 -16
@@ -13,9 +13,8 @@ import type {LazyComponent} from 'react/src/ReactLazy';
13 import type {
14 ClientReference,
15 ClientReferenceMetadata,
16 - UninitializedModel,
17 - Response,
16 SSRManifest,
17 + StringDecoder,
18 } from './ReactFlightClientConfig';
19
20 import type {HintModel} from 'react-server/src/ReactFlightServerConfig';
@@ -26,8 +25,11 @@ import {
25 resolveClientReference,
26 preloadModule,
27 requireModule,
29 - parseModel,
28 dispatchHint,
29 + readPartialStringChunk,
30 + readFinalStringChunk,
31 + supportsBinaryStreams,
32 + createStringDecoder,
33 } from './ReactFlightClientConfig';
34
35 import {
@@ -41,6 +43,8 @@ import {getOrCreateServerContext} from 'shared/ReactServerContextRegistry';
43
44 export type {CallServerCallback};
45
46 +type UninitializedModel = string;
47 +
48 export type JSONValue =
49 | number
50 | null
@@ -158,15 +162,15 @@ Chunk.prototype.then = function <T>(
162 }
163 };
164
161 -export type ResponseBase = {
165 +export type Response = {
166 _bundlerConfig: SSRManifest,
167 _callServer: CallServerCallback,
168 _chunks: Map<number, SomeChunk<any>>,
165 - ...
169 + _partialRow: string,
170 + _fromJSON: (key: string, value: JSONValue) => any,
171 + _stringDecoder: StringDecoder,
172 };
173
168 -export type {Response};
169 -
174 function readChunk<T>(chunk: SomeChunk<T>): T {
175 // If we have resolved content, we try to initialize it first which
176 // might put us back into one of the other states.
@@ -512,7 +516,7 @@ function createServerReferenceProxy<A: Iterable<any>, T>(
516 return proxy;
517 }
518
515 -export function parseModelString(
519 +function parseModelString(
520 response: Response,
521 parentObject: Object,
522 key: string,
@@ -632,7 +636,7 @@ export function parseModelString(
636 return value;
637 }
638
635 -export function parseModelTuple(
639 +function parseModelTuple(
640 response: Response,
641 value: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
642 ): any {
@@ -656,17 +660,25 @@ function missingCall() {
660 export function createResponse(
661 bundlerConfig: SSRManifest,
662 callServer: void | CallServerCallback,
659 -): ResponseBase {
663 +): Response {
664 const chunks: Map<number, SomeChunk<any>> = new Map();
661 - const response = {
665 + const response: Response = {
666 _bundlerConfig: bundlerConfig,
667 _callServer: callServer !== undefined ? callServer : missingCall,
668 _chunks: chunks,
669 + _partialRow: '',
670 + _stringDecoder: (null: any),
671 + _fromJSON: (null: any),
672 };
673 + if (supportsBinaryStreams) {
674 + response._stringDecoder = createStringDecoder();
675 + }
676 + // Don't inline this call because it causes closure to outline the call above.
677 + response._fromJSON = createFromJSONCallback(response);
678 return response;
679 }
680
669 -export function resolveModel(
681 +function resolveModel(
682 response: Response,
683 id: number,
684 model: UninitializedModel,
@@ -680,7 +692,7 @@ export function resolveModel(
692 }
693 }
694
683 -export function resolveModule(
695 +function resolveModule(
696 response: Response,
697 id: number,
698 model: UninitializedModel,
@@ -729,7 +741,7 @@ export function resolveModule(
741 }
742
743 type ErrorWithDigest = Error & {digest?: string};
732 -export function resolveErrorProd(
744 +function resolveErrorProd(
745 response: Response,
746 id: number,
747 digest: string,
@@ -758,7 +770,7 @@ export function resolveErrorProd(
770 }
771 }
772
761 -export function resolveErrorDev(
773 +function resolveErrorDev(
774 response: Response,
775 id: number,
776 digest: string,
@@ -789,7 +801,7 @@ export function resolveErrorDev(
801 }
802 }
803
792 -export function resolveHint(
804 +function resolveHint(
805 response: Response,
806 code: string,
807 model: UninitializedModel,
@@ -798,6 +810,105 @@ export function resolveHint(
810 dispatchHint(code, hintModel);
811 }
812
813 +function processFullRow(response: Response, row: string): void {
814 + if (row === '') {
815 + return;
816 + }
817 + const colon = row.indexOf(':', 0);
818 + const id = parseInt(row.slice(0, colon), 16);
819 + const tag = row[colon + 1];
820 + // When tags that are not text are added, check them here before
821 + // parsing the row as text.
822 + // switch (tag) {
823 + // }
824 + switch (tag) {
825 + case 'I': {
826 + resolveModule(response, id, row.slice(colon + 2));
827 + return;
828 + }
829 + case 'H': {
830 + const code = row[colon + 2];
831 + resolveHint(response, code, row.slice(colon + 3));
832 + return;
833 + }
834 + case 'E': {
835 + const errorInfo = JSON.parse(row.slice(colon + 2));
836 + if (__DEV__) {
837 + resolveErrorDev(
838 + response,
839 + id,
840 + errorInfo.digest,
841 + errorInfo.message,
842 + errorInfo.stack,
843 + );
844 + } else {
845 + resolveErrorProd(response, id, errorInfo.digest);
846 + }
847 + return;
848 + }
849 + default: {
850 + // We assume anything else is JSON.
851 + resolveModel(response, id, row.slice(colon + 1));
852 + return;
853 + }
854 + }
855 +}
856 +
857 +export function processStringChunk(
858 + response: Response,
859 + chunk: string,
860 + offset: number,
861 +): void {
862 + let linebreak = chunk.indexOf('\n', offset);
863 + while (linebreak > -1) {
864 + const fullrow = response._partialRow + chunk.slice(offset, linebreak);
865 + processFullRow(response, fullrow);
866 + response._partialRow = '';
867 + offset = linebreak + 1;
868 + linebreak = chunk.indexOf('\n', offset);
869 + }
870 + response._partialRow += chunk.slice(offset);
871 +}
872 +
873 +export function processBinaryChunk(
874 + response: Response,
875 + chunk: Uint8Array,
876 +): void {
877 + if (!supportsBinaryStreams) {
878 + throw new Error("This environment don't support binary chunks.");
879 + }
880 + const stringDecoder = response._stringDecoder;
881 + let linebreak = chunk.indexOf(10); // newline
882 + while (linebreak > -1) {
883 + const fullrow =
884 + response._partialRow +
885 + readFinalStringChunk(stringDecoder, chunk.subarray(0, linebreak));
886 + processFullRow(response, fullrow);
887 + response._partialRow = '';
888 + chunk = chunk.subarray(linebreak + 1);
889 + linebreak = chunk.indexOf(10); // newline
890 + }
891 + response._partialRow += readPartialStringChunk(stringDecoder, chunk);
892 +}
893 +
894 +function parseModel<T>(response: Response, json: UninitializedModel): T {
895 + return JSON.parse(json, response._fromJSON);
896 +}
897 +
898 +function createFromJSONCallback(response: Response) {
899 + // $FlowFixMe[missing-this-annot]
900 + return function (key: string, value: JSONValue) {
901 + if (typeof value === 'string') {
902 + // We can't use .bind here because we need the "this" value.
903 + return parseModelString(response, this, key, value);
904 + }
905 + if (typeof value === 'object' && value !== null) {
906 + return parseModelTuple(response, value);
907 + }
908 + return value;
909 + };
910 +}
911 +
912 export function close(response: Response): void {
913 // In case there are any remaining unresolved chunks, they won't
914 // be resolved now. So we need to issue an error to those.
packages/react-client/src/ReactFlightClientConfigNoStream.js deleted
-33
@@ -1,33 +0,0 @@
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 -export type StringDecoder = void;
11 -
12 -export const supportsBinaryStreams = false;
13 -
14 -export function createStringDecoder(): void {
15 - // eslint-disable-next-line react-internal/prod-error-codes
16 - throw new Error('Should never be called');
17 -}
18 -
19 -export function readPartialStringChunk(
20 - decoder: StringDecoder,
21 - buffer: Uint8Array,
22 -): string {
23 - // eslint-disable-next-line react-internal/prod-error-codes
24 - throw new Error('Should never be called');
25 -}
26 -
27 -export function readFinalStringChunk(
28 - decoder: StringDecoder,
29 - buffer: Uint8Array,
30 -): string {
31 - // eslint-disable-next-line react-internal/prod-error-codes
32 - throw new Error('Should never be called');
33 -}
packages/react-client/src/ReactFlightClientConfigStream.js deleted
-23
@@ -1,23 +0,0 @@
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 {ResponseBase} from './ReactFlightClient';
11 -import type {StringDecoder} from './ReactFlightClientConfig';
12 -
13 -export type Response = ResponseBase & {
14 - _partialRow: string,
15 - _fromJSON: (key: string, value: JSONValue) => any,
16 - _stringDecoder: StringDecoder,
17 -};
18 -
19 -export type UninitializedModel = string;
20 -
21 -export function parseModel<T>(response: Response, json: UninitializedModel): T {
22 - return JSON.parse(json, response._fromJSON);
23 -}
packages/react-client/src/ReactFlightClientStream.js deleted
-146
@@ -1,146 +0,0 @@
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 {CallServerCallback} from './ReactFlightClient';
11 -import type {Response} from './ReactFlightClientConfigStream';
12 -import type {SSRManifest} from './ReactFlightClientConfig';
13 -
14 -import {
15 - resolveModule,
16 - resolveModel,
17 - resolveErrorProd,
18 - resolveErrorDev,
19 - resolveHint,
20 - createResponse as createResponseBase,
21 - parseModelString,
22 - parseModelTuple,
23 -} from './ReactFlightClient';
24 -
25 -import {
26 - readPartialStringChunk,
27 - readFinalStringChunk,
28 - supportsBinaryStreams,
29 - createStringDecoder,
30 -} from './ReactFlightClientConfig';
31 -
32 -export type {Response};
33 -
34 -function processFullRow(response: Response, row: string): void {
35 - if (row === '') {
36 - return;
37 - }
38 - const colon = row.indexOf(':', 0);
39 - const id = parseInt(row.slice(0, colon), 16);
40 - const tag = row[colon + 1];
41 - // When tags that are not text are added, check them here before
42 - // parsing the row as text.
43 - // switch (tag) {
44 - // }
45 - switch (tag) {
46 - case 'I': {
47 - resolveModule(response, id, row.slice(colon + 2));
48 - return;
49 - }
50 - case 'H': {
51 - const code = row[colon + 2];
52 - resolveHint(response, code, row.slice(colon + 3));
53 - return;
54 - }
55 - case 'E': {
56 - const errorInfo = JSON.parse(row.slice(colon + 2));
57 - if (__DEV__) {
58 - resolveErrorDev(
59 - response,
60 - id,
61 - errorInfo.digest,
62 - errorInfo.message,
63 - errorInfo.stack,
64 - );
65 - } else {
66 - resolveErrorProd(response, id, errorInfo.digest);
67 - }
68 - return;
69 - }
70 - default: {
71 - // We assume anything else is JSON.
72 - resolveModel(response, id, row.slice(colon + 1));
73 - return;
74 - }
75 - }
76 -}
77 -
78 -export function processStringChunk(
79 - response: Response,
80 - chunk: string,
81 - offset: number,
82 -): void {
83 - let linebreak = chunk.indexOf('\n', offset);
84 - while (linebreak > -1) {
85 - const fullrow = response._partialRow + chunk.slice(offset, linebreak);
86 - processFullRow(response, fullrow);
87 - response._partialRow = '';
88 - offset = linebreak + 1;
89 - linebreak = chunk.indexOf('\n', offset);
90 - }
91 - response._partialRow += chunk.slice(offset);
92 -}
93 -
94 -export function processBinaryChunk(
95 - response: Response,
96 - chunk: Uint8Array,
97 -): void {
98 - if (!supportsBinaryStreams) {
99 - throw new Error("This environment don't support binary chunks.");
100 - }
101 - const stringDecoder = response._stringDecoder;
102 - let linebreak = chunk.indexOf(10); // newline
103 - while (linebreak > -1) {
104 - const fullrow =
105 - response._partialRow +
106 - readFinalStringChunk(stringDecoder, chunk.subarray(0, linebreak));
107 - processFullRow(response, fullrow);
108 - response._partialRow = '';
109 - chunk = chunk.subarray(linebreak + 1);
110 - linebreak = chunk.indexOf(10); // newline
111 - }
112 - response._partialRow += readPartialStringChunk(stringDecoder, chunk);
113 -}
114 -
115 -function createFromJSONCallback(response: Response) {
116 - // $FlowFixMe[missing-this-annot]
117 - return function (key: string, value: JSONValue) {
118 - if (typeof value === 'string') {
119 - // We can't use .bind here because we need the "this" value.
120 - return parseModelString(response, this, key, value);
121 - }
122 - if (typeof value === 'object' && value !== null) {
123 - return parseModelTuple(response, value);
124 - }
125 - return value;
126 - };
127 -}
128 -
129 -export function createResponse(
130 - bundlerConfig: SSRManifest,
131 - callServer: void | CallServerCallback,
132 -): Response {
133 - // NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.
134 - // It should be inlined to one object literal but minor changes can break it.
135 - const stringDecoder = supportsBinaryStreams ? createStringDecoder() : null;
136 - const response: any = createResponseBase(bundlerConfig, callServer);
137 - response._partialRow = '';
138 - if (supportsBinaryStreams) {
139 - response._stringDecoder = stringDecoder;
140 - }
141 - // Don't inline this call because it causes closure to outline the call above.
142 - response._fromJSON = createFromJSONCallback(response);
143 - return response;
144 -}
145 -
146 -export {reportGlobalError, getRoot, close} from './ReactFlightClient';
packages/react-client/src/forks/ReactFlightClientConfig.custom.js
-4
@@ -25,7 +25,6 @@
25
26 declare var $$$config: any;
27
28 -export type Response = any;
28 export opaque type SSRManifest = mixed;
29 export opaque type ServerManifest = mixed;
30 export opaque type ServerReferenceId = string;
@@ -39,9 +38,6 @@ export const dispatchHint = $$$config.dispatchHint;
38
39 export opaque type Source = mixed;
40
42 -export type UninitializedModel = string;
43 -export const parseModel = $$$config.parseModel;
44 -
41 export opaque type StringDecoder = mixed; // eslint-disable-line no-undef
42
43 export const supportsBinaryStreams = $$$config.supportsBinaryStreams;
packages/react-client/src/forks/ReactFlightClientConfig.dom-browser.js
-1
@@ -8,6 +8,5 @@
8 */
9
10 export * from 'react-client/src/ReactFlightClientConfigBrowser';
11 -export * from 'react-client/src/ReactFlightClientConfigStream';
11 export * from 'react-server-dom-webpack/src/ReactFlightClientConfigWebpackBundler';
12 export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
packages/react-client/src/forks/ReactFlightClientConfig.dom-bun.js
-1
@@ -8,7 +8,6 @@
8 */
9
10 export * from 'react-client/src/ReactFlightClientConfigBrowser';
11 -export * from 'react-client/src/ReactFlightClientConfigStream';
11 export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
12
13 export type Response = any;
packages/react-client/src/forks/ReactFlightClientConfig.dom-edge-webpack.js
-1
@@ -8,6 +8,5 @@
8 */
9
10 export * from 'react-client/src/ReactFlightClientConfigBrowser';
11 -export * from 'react-client/src/ReactFlightClientConfigStream';
11 export * from 'react-server-dom-webpack/src/ReactFlightClientConfigWebpackBundler';
12 export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
packages/react-client/src/forks/ReactFlightClientConfig.dom-legacy.js
-1
@@ -8,6 +8,5 @@
8 */
9
10 export * from 'react-client/src/ReactFlightClientConfigBrowser';
11 -export * from 'react-client/src/ReactFlightClientConfigStream';
11 export * from 'react-server-dom-webpack/src/ReactFlightClientConfigWebpackBundler';
12 export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
packages/react-client/src/forks/ReactFlightClientConfig.dom-node-webpack.js
-1
@@ -8,6 +8,5 @@
8 */
9
10 export * from 'react-client/src/ReactFlightClientConfigNode';
11 -export * from 'react-client/src/ReactFlightClientConfigStream';
11 export * from 'react-server-dom-webpack/src/ReactFlightClientConfigWebpackBundler';
12 export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
packages/react-client/src/forks/ReactFlightClientConfig.dom-node.js
-1
@@ -8,6 +8,5 @@
8 */
9
10 export * from 'react-client/src/ReactFlightClientConfigNode';
11 -export * from 'react-client/src/ReactFlightClientConfigStream';
11 export * from 'react-server-dom-webpack/src/ReactFlightClientConfigNodeBundler';
12 export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
packages/react-client/src/forks/ReactFlightClientConfig.dom-relay.js deleted
-12
@@ -1,12 +0,0 @@
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 -export * from 'react-server-dom-relay/src/ReactFlightClientConfigDOMRelay';
11 -export * from '../ReactFlightClientConfigNoStream';
12 -export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';
packages/react-client/src/forks/ReactFlightClientConfig.native-relay.js deleted
-11
@@ -1,11 +0,0 @@
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 -export * from 'react-server-native-relay/src/ReactFlightClientConfigNativeRelay';
11 -export * from '../ReactFlightClientConfigNoStream';
packages/react-native-renderer/package.json
+2 -2
@@ -8,9 +8,9 @@
8 "directory": "packages/react-native-renderer"
9 },
10 "dependencies": {
11 - "scheduler": "^0.11.0"
11 + "scheduler": "^0.23.0"
12 },
13 "peerDependencies": {
14 - "react": "^17.0.0"
14 + "react": "^18.0.0"
15 }
16 }
packages/react-native-renderer/src/server/ReactFizzConfigNative.js deleted
-359
@@ -1,359 +0,0 @@
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 - Destination,
14 - Chunk,
15 - PrecomputedChunk,
16 -} from 'react-server/src/ReactServerStreamConfig';
17 -
18 -import {
19 - writeChunk,
20 - writeChunkAndReturn,
21 - stringToChunk,
22 - stringToPrecomputedChunk,
23 -} from 'react-server/src/ReactServerStreamConfig';
24 -
25 -export const isPrimaryRenderer = true;
26 -
27 -// Every list of children or string is null terminated.
28 -const END_TAG = 0;
29 -// Tree node tags.
30 -const INSTANCE_TAG = 1;
31 -const PLACEHOLDER_TAG = 2;
32 -const SUSPENSE_PENDING_TAG = 3;
33 -const SUSPENSE_COMPLETE_TAG = 4;
34 -const SUSPENSE_CLIENT_RENDER_TAG = 5;
35 -// Command tags.
36 -const SEGMENT_TAG = 1;
37 -const SUSPENSE_UPDATE_TO_COMPLETE_TAG = 2;
38 -const SUSPENSE_UPDATE_TO_CLIENT_RENDER_TAG = 3;
39 -
40 -const END = new Uint8Array(1);
41 -END[0] = END_TAG;
42 -const PLACEHOLDER = new Uint8Array(1);
43 -PLACEHOLDER[0] = PLACEHOLDER_TAG;
44 -const INSTANCE = new Uint8Array(1);
45 -INSTANCE[0] = INSTANCE_TAG;
46 -const SUSPENSE_PENDING = new Uint8Array(1);
47 -SUSPENSE_PENDING[0] = SUSPENSE_PENDING_TAG;
48 -const SUSPENSE_COMPLETE = new Uint8Array(1);
49 -SUSPENSE_COMPLETE[0] = SUSPENSE_COMPLETE_TAG;
50 -const SUSPENSE_CLIENT_RENDER = new Uint8Array(1);
51 -SUSPENSE_CLIENT_RENDER[0] = SUSPENSE_CLIENT_RENDER_TAG;
52 -
53 -const SEGMENT = new Uint8Array(1);
54 -SEGMENT[0] = SEGMENT_TAG;
55 -const SUSPENSE_UPDATE_TO_COMPLETE = new Uint8Array(1);
56 -SUSPENSE_UPDATE_TO_COMPLETE[0] = SUSPENSE_UPDATE_TO_COMPLETE_TAG;
57 -const SUSPENSE_UPDATE_TO_CLIENT_RENDER = new Uint8Array(1);
58 -SUSPENSE_UPDATE_TO_CLIENT_RENDER[0] = SUSPENSE_UPDATE_TO_CLIENT_RENDER_TAG;
59 -
60 -export type Resources = void;
61 -export type BoundaryResources = void;
62 -
63 -// Per response,
64 -export type ResponseState = {
65 - nextSuspenseID: number,
66 -};
67 -
68 -// Allows us to keep track of what we've already written so we can refer back to it.
69 -export function createResponseState(): ResponseState {
70 - return {
71 - nextSuspenseID: 0,
72 - };
73 -}
74 -
75 -// isInAParentText
76 -export type FormatContext = boolean;
77 -
78 -export function createRootFormatContext(): FormatContext {
79 - return false;
80 -}
81 -
82 -export function getChildFormatContext(
83 - parentContext: FormatContext,
84 - type: string,
85 - props: Object,
86 -): FormatContext {
87 - const prevIsInAParentText = parentContext;
88 - const isInAParentText =
89 - type === 'AndroidTextInput' || // Android
90 - type === 'RCTMultilineTextInputView' || // iOS
91 - type === 'RCTSinglelineTextInputView' || // iOS
92 - type === 'RCTText' ||
93 - type === 'RCTVirtualText';
94 -
95 - if (prevIsInAParentText !== isInAParentText) {
96 - return isInAParentText;
97 - } else {
98 - return parentContext;
99 - }
100 -}
101 -
102 -// This object is used to lazily reuse the ID of the first generated node, or assign one.
103 -// This is very specific to DOM where we can't assign an ID to.
104 -export type SuspenseBoundaryID = number;
105 -
106 -export const UNINITIALIZED_SUSPENSE_BOUNDARY_ID = -1;
107 -
108 -export function assignSuspenseBoundaryID(
109 - responseState: ResponseState,
110 -): SuspenseBoundaryID {
111 - return responseState.nextSuspenseID++;
112 -}
113 -
114 -export function makeId(
115 - responseState: ResponseState,
116 - treeId: string,
117 - localId: number,
118 -): string {
119 - throw new Error('Not implemented');
120 -}
121 -
122 -const RAW_TEXT = stringToPrecomputedChunk('RCTRawText');
123 -
124 -export function pushTextInstance(
125 - target: Array<Chunk | PrecomputedChunk>,
126 - text: string,
127 - responseState: ResponseState,
128 - // This Renderer does not use this argument
129 - textEmbedded: boolean,
130 -): boolean {
131 - target.push(
132 - INSTANCE,
133 - RAW_TEXT, // Type
134 - END, // Null terminated type string
135 - // TODO: props { text: text }
136 - END, // End of children
137 - );
138 - return false;
139 -}
140 -
141 -export function pushStartInstance(
142 - target: Array<Chunk | PrecomputedChunk>,
143 - type: string,
144 - props: Object,
145 - resources: Resources,
146 - responseState: ResponseState,
147 - formatContext: FormatContext,
148 - textEmbedded: boolean,
149 -): ReactNodeList {
150 - target.push(
151 - INSTANCE,
152 - stringToChunk(type),
153 - END, // Null terminated type string
154 - // TODO: props
155 - );
156 - return props.children;
157 -}
158 -
159 -export function pushEndInstance(
160 - target: Array<Chunk | PrecomputedChunk>,
161 - type: string,
162 - props: Object,
163 - responseState: ResponseState,
164 - formatContext: FormatContext,
165 -): void {
166 - target.push(END);
167 -}
168 -
169 -// In this Renderer this is a noop
170 -export function pushSegmentFinale(
171 - target: Array<Chunk | PrecomputedChunk>,
172 - responseState: ResponseState,
173 - lastPushedText: boolean,
174 - textEmbedded: boolean,
175 -): void {}
176 -
177 -export function writeCompletedRoot(
178 - destination: Destination,
179 - responseState: ResponseState,
180 -): boolean {
181 - return true;
182 -}
183 -
184 -// IDs are formatted as little endian Uint16
185 -function formatID(id: number): Uint8Array {
186 - if (id > 0xffff) {
187 - throw new Error(
188 - 'More boundaries or placeholders than we expected to ever emit.',
189 - );
190 - }
191 - const buffer = new Uint8Array(2);
192 - buffer[0] = (id >>> 8) & 0xff;
193 - buffer[1] = id & 0xff;
194 - return buffer;
195 -}
196 -
197 -// Structural Nodes
198 -
199 -// A placeholder is a node inside a hidden partial tree that can be filled in later, but before
200 -// display. It's never visible to users.
201 -export function writePlaceholder(
202 - destination: Destination,
203 - responseState: ResponseState,
204 - id: number,
205 -): boolean {
206 - writeChunk(destination, PLACEHOLDER);
207 - return writeChunkAndReturn(destination, formatID(id));
208 -}
209 -
210 -// Suspense boundaries are encoded as comments.
211 -export function writeStartCompletedSuspenseBoundary(
212 - destination: Destination,
213 - responseState: ResponseState,
214 -): boolean {
215 - return writeChunkAndReturn(destination, SUSPENSE_COMPLETE);
216 -}
217 -
218 -export function pushStartCompletedSuspenseBoundary(
219 - target: Array<Chunk | PrecomputedChunk>,
220 -): void {
221 - target.push(SUSPENSE_COMPLETE);
222 -}
223 -
224 -export function writeStartPendingSuspenseBoundary(
225 - destination: Destination,
226 - responseState: ResponseState,
227 - id: SuspenseBoundaryID,
228 -): boolean {
229 - writeChunk(destination, SUSPENSE_PENDING);
230 - return writeChunkAndReturn(destination, formatID(id));
231 -}
232 -export function writeStartClientRenderedSuspenseBoundary(
233 - destination: Destination,
234 - responseState: ResponseState,
235 - // TODO: encode error for native
236 - errorDigest: ?string,
237 - errorMessage: ?string,
238 - errorComponentStack: ?string,
239 -): boolean {
240 - return writeChunkAndReturn(destination, SUSPENSE_CLIENT_RENDER);
241 -}
242 -export function writeEndCompletedSuspenseBoundary(
243 - destination: Destination,
244 - responseState: ResponseState,
245 -): boolean {
246 - return writeChunkAndReturn(destination, END);
247 -}
248 -export function pushEndCompletedSuspenseBoundary(
249 - target: Array<Chunk | PrecomputedChunk>,
250 -): void {
251 - target.push(END);
252 -}
253 -export function writeEndPendingSuspenseBoundary(
254 - destination: Destination,
255 - responseState: ResponseState,
256 -): boolean {
257 - return writeChunkAndReturn(destination, END);
258 -}
259 -export function writeEndClientRenderedSuspenseBoundary(
260 - destination: Destination,
261 - responseState: ResponseState,
262 -): boolean {
263 - return writeChunkAndReturn(destination, END);
264 -}
265 -
266 -export function writeStartSegment(
267 - destination: Destination,
268 - responseState: ResponseState,
269 - formatContext: FormatContext,
270 - id: number,
271 -): boolean {
272 - writeChunk(destination, SEGMENT);
273 - return writeChunkAndReturn(destination, formatID(id));
274 -}
275 -export function writeEndSegment(
276 - destination: Destination,
277 - formatContext: FormatContext,
278 -): boolean {
279 - return writeChunkAndReturn(destination, END);
280 -}
281 -
282 -// Instruction Set
283 -
284 -export function writeCompletedSegmentInstruction(
285 - destination: Destination,
286 - responseState: ResponseState,
287 - contentSegmentID: number,
288 -): boolean {
289 - // We don't need to emit this. Instead the client will keep track of pending placeholders.
290 - // TODO: Returning true here is not correct. Avoid having to call this function at all.
291 - return true;
292 -}
293 -
294 -export function writeCompletedBoundaryInstruction(
295 - destination: Destination,
296 - responseState: ResponseState,
297 - boundaryID: SuspenseBoundaryID,
298 - contentSegmentID: number,
299 - resources: BoundaryResources,
300 -): boolean {
301 - writeChunk(destination, SUSPENSE_UPDATE_TO_COMPLETE);
302 - writeChunk(destination, formatID(boundaryID));
303 - return writeChunkAndReturn(destination, formatID(contentSegmentID));
304 -}
305 -
306 -export function writeClientRenderBoundaryInstruction(
307 - destination: Destination,
308 - responseState: ResponseState,
309 - boundaryID: SuspenseBoundaryID,
310 - // TODO: encode error for native
311 - errorDigest: ?string,
312 - errorMessage: ?string,
313 - errorComponentStack: ?string,
314 -): boolean {
315 - writeChunk(destination, SUSPENSE_UPDATE_TO_CLIENT_RENDER);
316 - return writeChunkAndReturn(destination, formatID(boundaryID));
317 -}
318 -
319 -export function writePreamble(
320 - destination: Destination,
321 - resources: Resources,
322 - responseState: ResponseState,
323 - willFlushAllSegments: boolean,
324 -) {}
325 -
326 -export function writeHoistables(
327 - destination: Destination,
328 - resources: Resources,
329 - responseState: ResponseState,
330 -) {}
331 -
332 -export function writePostamble(
333 - destination: Destination,
334 - responseState: ResponseState,
335 -) {}
336 -
337 -export function hoistResources(
338 - resources: Resources,
339 - boundaryResources: BoundaryResources,
340 -) {}
341 -
342 -export function prepareHostDispatcher() {}
343 -export function createResources() {}
344 -export function createBoundaryResources() {}
345 -export function setCurrentlyRenderingBoundaryResourcesTarget(
346 - resources: Resources,
347 - boundaryResources: ?BoundaryResources,
348 -) {}
349 -
350 -export function writeResourcesForBoundary(
351 - destination: Destination,
352 - boundaryResources: BoundaryResources,
353 - responseState: ResponseState,
354 -): boolean {
355 - return true;
356 -}
357 -
358 -export type TransitionStatus = mixed;
359 -export const NotPendingTransition: TransitionStatus = null;
packages/react-native-renderer/src/server/ReactFlightServerConfigNative.js deleted
-19
@@ -1,19 +0,0 @@
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 -export const isPrimaryRenderer = true;
11 -
12 -export type Hints = null;
13 -export type HintModel = '';
14 -
15 -export function createHints(): null {
16 - return null;
17 -}
18 -
19 -export function prepareHostDispatcher() {}
packages/react-reconciler/src/forks/ReactFiberConfig.dom-fb.js renamed
packages/react-reconciler/src/forks/ReactFiberConfig.native-relay.js deleted
-10
@@ -1,10 +0,0 @@
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 -export * from 'react-native-renderer/src/ReactFiberConfigFabric';
packages/react-server-dom-fb/package.json renamed
+5 -4
@@ -1,16 +1,17 @@
1 {
2 - "name": "react-server-native-relay",
2 + "name": "react-server-dom-fb",
3 "version": "0.1.0",
4 "private": true,
5 "repository": {
6 "type" : "git",
7 "url" : "https://github.com/facebook/react.git",
8 - "directory": "packages/react-server-native-relay"
8 + "directory": "packages/react-server-dom-fb"
9 },
10 "dependencies": {
11 - "scheduler": "^0.11.0"
11 + "scheduler": "^0.23.0"
12 },
13 "peerDependencies": {
14 - "react": "^17.0.0"
14 + "react": "^18.0.0",
15 + "react-dom": "^18.0.0"
16 }
17 }
packages/react-server-dom-fb/src/ReactDOMServerFB.js renamed
packages/react-server-dom-fb/src/ReactServerStreamConfigFB.js renamed
packages/react-server-dom-fb/src/__tests__/ReactDOMServerFB-test.internal.js renamed
packages/react-server-dom-relay/index.js deleted
-10
@@ -1,10 +0,0 @@
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 -export * from './src/ReactFlightDOMRelayClient';
packages/react-server-dom-relay/package.json deleted
-17
@@ -1,17 +0,0 @@
1 -{
2 - "name": "react-server-dom-relay",
3 - "version": "0.1.0",
4 - "private": true,
5 - "repository": {
6 - "type" : "git",
7 - "url" : "https://github.com/facebook/react.git",
8 - "directory": "packages/react-server-dom-relay"
9 - },
10 - "dependencies": {
11 - "scheduler": "^0.11.0"
12 - },
13 - "peerDependencies": {
14 - "react": "^17.0.0",
15 - "react-dom": "^17.0.0"
16 - }
17 -}
packages/react-server-dom-relay/server.js deleted
-10
@@ -1,10 +0,0 @@
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 -export * from './src/ReactFlightDOMRelayServer';
packages/react-server-dom-relay/src/ReactFlightClientConfigDOMRelay.js deleted
-97
@@ -1,97 +0,0 @@
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 {JSONValue, ResponseBase} from 'react-client/src/ReactFlightClient';
11 -
12 -import type {JSResourceReference} from 'JSResourceReference';
13 -
14 -import type {ClientReferenceMetadata} from 'ReactFlightDOMRelayClientIntegration';
15 -
16 -export type ClientReference<T> = JSResourceReference<T>;
17 -
18 -import {
19 - parseModelString,
20 - parseModelTuple,
21 -} from 'react-client/src/ReactFlightClient';
22 -
23 -export {
24 - preloadModule,
25 - requireModule,
26 -} from 'ReactFlightDOMRelayClientIntegration';
27 -
28 -import {resolveClientReference as resolveClientReferenceImpl} from 'ReactFlightDOMRelayClientIntegration';
29 -
30 -import isArray from 'shared/isArray';
31 -
32 -export type {ClientReferenceMetadata} from 'ReactFlightDOMRelayClientIntegration';
33 -
34 -export type SSRManifest = null;
35 -export type ServerManifest = null;
36 -export type ServerReferenceId = string;
37 -
38 -export type UninitializedModel = JSONValue;
39 -
40 -export type Response = ResponseBase;
41 -
42 -export function resolveClientReference<T>(
43 - bundlerConfig: SSRManifest,
44 - metadata: ClientReferenceMetadata,
45 -): ClientReference<T> {
46 - return resolveClientReferenceImpl(metadata);
47 -}
48 -
49 -export function resolveServerReference<T>(
50 - bundlerConfig: ServerManifest,
51 - id: ServerReferenceId,
52 -): ClientReference<T> {
53 - throw new Error('Not implemented.');
54 -}
55 -
56 -function parseModelRecursively(
57 - response: Response,
58 - parentObj: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
59 - key: string,
60 - value: JSONValue,
61 -): $FlowFixMe {
62 - if (typeof value === 'string') {
63 - return parseModelString(response, parentObj, key, value);
64 - }
65 - if (typeof value === 'object' && value !== null) {
66 - if (isArray(value)) {
67 - const parsedValue: Array<$FlowFixMe> = [];
68 - for (let i = 0; i < value.length; i++) {
69 - (parsedValue: any)[i] = parseModelRecursively(
70 - response,
71 - value,
72 - '' + i,
73 - value[i],
74 - );
75 - }
76 - return parseModelTuple(response, parsedValue);
77 - } else {
78 - const parsedValue = {};
79 - for (const innerKey in value) {
80 - (parsedValue: any)[innerKey] = parseModelRecursively(
81 - response,
82 - value,
83 - innerKey,
84 - value[innerKey],
85 - );
86 - }
87 - return parsedValue;
88 - }
89 - }
90 - return value;
91 -}
92 -
93 -const dummy = {};
94 -
95 -export function parseModel<T>(response: Response, json: UninitializedModel): T {
96 - return (parseModelRecursively(response, dummy, '', json): any);
97 -}
packages/react-server-dom-relay/src/ReactFlightDOMRelayClient.js deleted
-61
@@ -1,61 +0,0 @@
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 {RowEncoding} from './ReactFlightDOMRelayProtocol';
11 -
12 -import type {Response} from 'react-client/src/ReactFlightClient';
13 -
14 -import {
15 - createResponse,
16 - resolveModel,
17 - resolveModule,
18 - resolveErrorDev,
19 - resolveErrorProd,
20 - resolveHint,
21 - close,
22 - getRoot,
23 -} from 'react-client/src/ReactFlightClient';
24 -
25 -export {createResponse, close, getRoot};
26 -
27 -export function resolveRow(response: Response, chunk: RowEncoding): void {
28 - if (chunk[0] === 'O') {
29 - // $FlowFixMe[incompatible-call] unable to refine on array indices
30 - resolveModel(response, chunk[1], chunk[2]);
31 - } else if (chunk[0] === 'I') {
32 - // $FlowFixMe[incompatible-call] unable to refine on array indices
33 - resolveModule(response, chunk[1], chunk[2]);
34 - } else if (chunk[0] === 'H') {
35 - // $FlowFixMe[incompatible-call] unable to refine on array indices
36 - resolveHint(response, chunk[1], chunk[2]);
37 - } else {
38 - if (__DEV__) {
39 - resolveErrorDev(
40 - response,
41 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
42 - chunk[1],
43 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
44 - // $FlowFixMe[prop-missing]
45 - // $FlowFixMe[incompatible-use]
46 - chunk[2].digest,
47 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
48 - // $FlowFixMe[incompatible-use]
49 - chunk[2].message || '',
50 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
51 - // $FlowFixMe[incompatible-use]
52 - chunk[2].stack || '',
53 - );
54 - } else {
55 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
56 - // $FlowFixMe[prop-missing]
57 - // $FlowFixMe[incompatible-use]
58 - resolveErrorProd(response, chunk[1], chunk[2].digest);
59 - }
60 - }
61 -}
packages/react-server-dom-relay/src/ReactFlightDOMRelayProtocol.js deleted
-36
@@ -1,36 +0,0 @@
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 {HintModel} from 'react-server/src/ReactFlightServerConfig';
11 -import type {ClientReferenceMetadata} from 'ReactFlightDOMRelayServerIntegration';
12 -
13 -export type JSONValue =
14 - | string
15 - | number
16 - | boolean
17 - | null
18 - | {+[key: string]: JSONValue}
19 - | $ReadOnlyArray<JSONValue>;
20 -
21 -export type RowEncoding =
22 - | ['O', number, JSONValue]
23 - | ['I', number, ClientReferenceMetadata]
24 - | ['H', string, HintModel]
25 - | ['P', number, string]
26 - | ['S', number, string]
27 - | [
28 - 'E',
29 - number,
30 - {
31 - digest: string,
32 - message?: string,
33 - stack?: string,
34 - ...
35 - },
36 - ];
packages/react-server-dom-relay/src/ReactFlightDOMRelayServer.js deleted
-44
@@ -1,44 +0,0 @@
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 {ReactClientValue} from 'react-server/src/ReactFlightServer';
11 -import type {
12 - ClientManifest,
13 - Destination,
14 -} from './ReactFlightServerConfigDOMRelay';
15 -
16 -import {
17 - createRequest,
18 - startWork,
19 - startFlowing,
20 -} from 'react-server/src/ReactFlightServer';
21 -
22 -type Options = {
23 - onError?: (error: mixed) => void,
24 - identifierPrefix?: string,
25 -};
26 -
27 -function render(
28 - model: ReactClientValue,
29 - destination: Destination,
30 - config: ClientManifest,
31 - options?: Options,
32 -): void {
33 - const request = createRequest(
34 - model,
35 - config,
36 - options ? options.onError : undefined,
37 - undefined, // not currently set up to supply context overrides
38 - options ? options.identifierPrefix : undefined,
39 - );
40 - startWork(request);
41 - startFlowing(request, destination);
42 -}
43 -
44 -export {render};
packages/react-server-dom-relay/src/ReactFlightServerConfigDOMRelay.js deleted
-236
@@ -1,236 +0,0 @@
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 {HintModel} from 'react-server/src/ReactFlightServerConfig';
11 -import type {RowEncoding, JSONValue} from './ReactFlightDOMRelayProtocol';
12 -
13 -import type {
14 - Request,
15 - ReactClientValue,
16 -} from 'react-server/src/ReactFlightServer';
17 -
18 -import type {JSResourceReference} from 'JSResourceReference';
19 -import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
20 -
21 -import hasOwnProperty from 'shared/hasOwnProperty';
22 -import isArray from 'shared/isArray';
23 -
24 -export type ClientReference<T> = JSResourceReference<T>;
25 -export type ServerReference<T> = T;
26 -export type ServerReferenceId = {};
27 -
28 -import type {
29 - Destination,
30 - BundlerConfig as ClientManifest,
31 - ClientReferenceMetadata,
32 -} from 'ReactFlightDOMRelayServerIntegration';
33 -
34 -import {resolveModelToJSON} from 'react-server/src/ReactFlightServer';
35 -
36 -import {
37 - emitRow,
38 - resolveClientReferenceMetadata as resolveClientReferenceMetadataImpl,
39 - close,
40 -} from 'ReactFlightDOMRelayServerIntegration';
41 -
42 -export type {
43 - Destination,
44 - BundlerConfig as ClientManifest,
45 - ClientReferenceMetadata,
46 -} from 'ReactFlightDOMRelayServerIntegration';
47 -
48 -export function isClientReference(reference: Object): boolean {
49 - return reference instanceof JSResourceReferenceImpl;
50 -}
51 -
52 -export function isServerReference(reference: Object): boolean {
53 - return false;
54 -}
55 -
56 -export type ClientReferenceKey = ClientReference<any>;
57 -
58 -export function getClientReferenceKey(
59 - reference: ClientReference<any>,
60 -): ClientReferenceKey {
61 - // We use the reference object itself as the key because we assume the
62 - // object will be cached by the bundler runtime.
63 - return reference;
64 -}
65 -
66 -export function resolveClientReferenceMetadata<T>(
67 - config: ClientManifest,
68 - resource: ClientReference<T>,
69 -): ClientReferenceMetadata {
70 - return resolveClientReferenceMetadataImpl(config, resource);
71 -}
72 -
73 -export function getServerReferenceId<T>(
74 - config: ClientManifest,
75 - resource: ServerReference<T>,
76 -): ServerReferenceId {
77 - throw new Error('Not implemented.');
78 -}
79 -
80 -export function getServerReferenceBoundArguments<T>(
81 - config: ClientManifest,
82 - resource: ServerReference<T>,
83 -): Array<ReactClientValue> {
84 - throw new Error('Not implemented.');
85 -}
86 -
87 -export type Chunk = RowEncoding;
88 -
89 -export function processErrorChunkProd(
90 - request: Request,
91 - id: number,
92 - digest: string,
93 -): Chunk {
94 - if (__DEV__) {
95 - // These errors should never make it into a build so we don't need to encode them in codes.json
96 - // eslint-disable-next-line react-internal/prod-error-codes
97 - throw new Error(
98 - 'processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.',
99 - );
100 - }
101 -
102 - return [
103 - 'E',
104 - id,
105 - {
106 - digest,
107 - },
108 - ];
109 -}
110 -
111 -export function processErrorChunkDev(
112 - request: Request,
113 - id: number,
114 - digest: string,
115 - message: string,
116 - stack: string,
117 -): Chunk {
118 - if (!__DEV__) {
119 - // These errors should never make it into a build so we don't need to encode them in codes.json
120 - // eslint-disable-next-line react-internal/prod-error-codes
121 - throw new Error(
122 - 'processErrorChunkDev should never be called while in production mode. Use processErrorChunkProd instead. This is a bug in React.',
123 - );
124 - }
125 -
126 - return [
127 - 'E',
128 - id,
129 - {
130 - digest,
131 - message,
132 - stack,
133 - },
134 - ];
135 -}
136 -
137 -function convertModelToJSON(
138 - request: Request,
139 - parent: {+[key: string]: ReactClientValue} | $ReadOnlyArray<ReactClientValue>,
140 - key: string,
141 - model: ReactClientValue,
142 -): JSONValue {
143 - const json = resolveModelToJSON(request, parent, key, model);
144 - if (typeof json === 'object' && json !== null) {
145 - if (isArray(json)) {
146 - const jsonArray: Array<JSONValue> = [];
147 - for (let i = 0; i < json.length; i++) {
148 - jsonArray[i] = convertModelToJSON(request, json, '' + i, json[i]);
149 - }
150 - return jsonArray;
151 - } else {
152 - const jsonObj: {[key: string]: JSONValue} = {};
153 - for (const nextKey in json) {
154 - if (hasOwnProperty.call(json, nextKey)) {
155 - jsonObj[nextKey] = convertModelToJSON(
156 - request,
157 - json,
158 - nextKey,
159 - json[nextKey],
160 - );
161 - }
162 - }
163 - return jsonObj;
164 - }
165 - }
166 - return json;
167 -}
168 -
169 -export function processModelChunk(
170 - request: Request,
171 - id: number,
172 - model: ReactClientValue,
173 -): Chunk {
174 - const json = convertModelToJSON(request, {}, '', model);
175 - return ['O', id, json];
176 -}
177 -
178 -export function processReferenceChunk(
179 - request: Request,
180 - id: number,
181 - reference: string,
182 -): Chunk {
183 - return ['O', id, reference];
184 -}
185 -
186 -export function processImportChunk(
187 - request: Request,
188 - id: number,
189 - clientReferenceMetadata: ClientReferenceMetadata,
190 -): Chunk {
191 - // The clientReferenceMetadata is already a JSON serializable value.
192 - return ['I', id, clientReferenceMetadata];
193 -}
194 -
195 -export function processHintChunk(
196 - request: Request,
197 - id: number,
198 - code: string,
199 - model: HintModel,
200 -): Chunk {
201 - // The hint is already a JSON serializable value.
202 - return ['H', code, model];
203 -}
204 -
205 -export function scheduleWork(callback: () => void) {
206 - callback();
207 -}
208 -
209 -export function flushBuffered(destination: Destination) {}
210 -
211 -export const supportsRequestStorage = false;
212 -export const requestStorage: AsyncLocalStorage<Request> = (null: any);
213 -
214 -export function beginWriting(destination: Destination) {}
215 -
216 -export function writeChunk(destination: Destination, chunk: Chunk): void {
217 - // $FlowFixMe[incompatible-call] `Chunk` doesn't flow into `JSONValue` because of the `E` row type.
218 - emitRow(destination, chunk);
219 -}
220 -
221 -export function writeChunkAndReturn(
222 - destination: Destination,
223 - chunk: Chunk,
224 -): boolean {
225 - // $FlowFixMe[incompatible-call] `Chunk` doesn't flow into `JSONValue` because of the `E` row type.
226 - emitRow(destination, chunk);
227 - return true;
228 -}
229 -
230 -export function completeWriting(destination: Destination) {}
231 -
232 -export {close};
233 -
234 -export function closeWithError(destination: Destination, error: mixed): void {
235 - close(destination);
236 -}
packages/react-server-dom-relay/src/__mocks__/JSResourceReferenceImpl.js deleted
-19
@@ -1,19 +0,0 @@
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 -
8 -'use strict';
9 -
10 -class JSResourceReferenceImpl {
11 - constructor(moduleId) {
12 - this._moduleId = moduleId;
13 - }
14 - getModuleId() {
15 - return this._moduleId;
16 - }
17 -}
18 -
19 -module.exports = JSResourceReferenceImpl;
packages/react-server-dom-relay/src/__mocks__/ReactFlightDOMRelayClientIntegration.js deleted
-22
@@ -1,22 +0,0 @@
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 -
8 -'use strict';
9 -
10 -import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
11 -
12 -const ReactFlightDOMRelayClientIntegration = {
13 - resolveClientReference(metadata) {
14 - return new JSResourceReferenceImpl(metadata);
15 - },
16 - preloadModule(clientReference) {},
17 - requireModule(clientReference) {
18 - return clientReference._moduleId;
19 - },
20 -};
21 -
22 -module.exports = ReactFlightDOMRelayClientIntegration;
packages/react-server-dom-relay/src/__mocks__/ReactFlightDOMRelayServerIntegration.js deleted
-20
@@ -1,20 +0,0 @@
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 -
8 -'use strict';
9 -
10 -const ReactFlightDOMRelayServerIntegration = {
11 - emitRow(destination, json) {
12 - destination.push(json);
13 - },
14 - close(destination) {},
15 - resolveClientReferenceMetadata(config, resource) {
16 - return resource._moduleId;
17 - },
18 -};
19 -
20 -module.exports = ReactFlightDOMRelayServerIntegration;
packages/react-server-dom-relay/src/__tests__/ReactFlightDOMRelay-test.internal.js deleted
-240
@@ -1,240 +0,0 @@
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 -
8 -'use strict';
9 -
10 -let act;
11 -let React;
12 -let ReactDOMClient;
13 -let JSResourceReferenceImpl;
14 -let ReactDOMFlightRelayServer;
15 -let ReactDOMFlightRelayClient;
16 -let SuspenseList;
17 -
18 -describe('ReactFlightDOMRelay', () => {
19 - beforeEach(() => {
20 - jest.resetModules();
21 -
22 - act = require('internal-test-utils').act;
23 - React = require('react');
24 - ReactDOMClient = require('react-dom/client');
25 - ReactDOMFlightRelayServer = require('react-server-dom-relay/server');
26 - ReactDOMFlightRelayClient = require('react-server-dom-relay');
27 - JSResourceReferenceImpl = require('JSResourceReferenceImpl');
28 - if (gate(flags => flags.enableSuspenseList)) {
29 - SuspenseList = React.SuspenseList;
30 - }
31 - });
32 -
33 - function readThrough(data) {
34 - const response = ReactDOMFlightRelayClient.createResponse();
35 - for (let i = 0; i < data.length; i++) {
36 - const chunk = data[i];
37 - ReactDOMFlightRelayClient.resolveRow(response, chunk);
38 - }
39 - ReactDOMFlightRelayClient.close(response);
40 - const promise = ReactDOMFlightRelayClient.getRoot(response);
41 - let model;
42 - let error;
43 - promise.then(
44 - m => (model = m),
45 - e => (error = e),
46 - );
47 - if (error) {
48 - throw error;
49 - }
50 - return model;
51 - }
52 -
53 - it('can render a Server Component', () => {
54 - function Bar({text}) {
55 - return text.toUpperCase();
56 - }
57 - function Foo() {
58 - return {
59 - bar: (
60 - <div>
61 - <Bar text="a" />, <Bar text="b" />
62 - </div>
63 - ),
64 - };
65 - }
66 - const transport = [];
67 - ReactDOMFlightRelayServer.render(
68 - {
69 - foo: <Foo />,
70 - },
71 - transport,
72 - );
73 -
74 - const model = readThrough(transport);
75 - expect(model).toEqual({
76 - foo: {
77 - bar: (
78 - <div>
79 - {'A'}
80 - {', '}
81 - {'B'}
82 - </div>
83 - ),
84 - },
85 - });
86 - });
87 -
88 - it('can render a Client Component using a module reference and render there', async () => {
89 - function UserClient(props) {
90 - return (
91 - <span>
92 - {props.greeting}, {props.name}
93 - </span>
94 - );
95 - }
96 - const User = new JSResourceReferenceImpl(UserClient);
97 -
98 - function Greeting({firstName, lastName}) {
99 - return <User greeting="Hello" name={firstName + ' ' + lastName} />;
100 - }
101 -
102 - const model = {
103 - greeting: <Greeting firstName="Seb" lastName="Smith" />,
104 - };
105 -
106 - const transport = [];
107 - ReactDOMFlightRelayServer.render(model, transport);
108 -
109 - const modelClient = readThrough(transport);
110 -
111 - const container = document.createElement('div');
112 - const root = ReactDOMClient.createRoot(container);
113 - await act(() => {
114 - root.render(modelClient.greeting);
115 - });
116 -
117 - expect(container.innerHTML).toEqual('<span>Hello, Seb Smith</span>');
118 - });
119 -
120 - // @gate enableSuspenseList
121 - it('can reasonably handle different element types', () => {
122 - const {forwardRef, memo, Fragment, StrictMode, Profiler, Suspense} = React;
123 -
124 - const Inner = memo(
125 - forwardRef((props, ref) => {
126 - return <div ref={ref}>{'Hello ' + props.name}</div>;
127 - }),
128 - );
129 -
130 - function Foo() {
131 - return {
132 - bar: (
133 - <div>
134 - <Fragment>Fragment child</Fragment>
135 - <Profiler>Profiler child</Profiler>
136 - <StrictMode>StrictMode child</StrictMode>
137 - <Suspense fallback="Loading...">Suspense child</Suspense>
138 - <SuspenseList fallback="Loading...">
139 - {'SuspenseList row 1'}
140 - {'SuspenseList row 2'}
141 - </SuspenseList>
142 - <Inner name="world" />
143 - </div>
144 - ),
145 - };
146 - }
147 - const transport = [];
148 - ReactDOMFlightRelayServer.render(
149 - {
150 - foo: <Foo />,
151 - },
152 - transport,
153 - );
154 -
155 - const model = readThrough(transport);
156 - expect(model).toEqual({
157 - foo: {
158 - bar: (
159 - <div>
160 - Fragment child
161 - <Profiler>Profiler child</Profiler>
162 - <StrictMode>StrictMode child</StrictMode>
163 - <Suspense fallback="Loading...">Suspense child</Suspense>
164 - <SuspenseList fallback="Loading...">
165 - {'SuspenseList row 1'}
166 - {'SuspenseList row 2'}
167 - </SuspenseList>
168 - <div>Hello world</div>
169 - </div>
170 - ),
171 - },
172 - });
173 - });
174 -
175 - it('can handle a subset of Hooks', () => {
176 - const {useMemo, useCallback} = React;
177 - function Inner({x}) {
178 - const foo = useMemo(() => x + x, [x]);
179 - const bar = useCallback(() => 10 + foo, [foo]);
180 - return bar();
181 - }
182 -
183 - function Foo() {
184 - return {
185 - bar: <Inner x={2} />,
186 - };
187 - }
188 - const transport = [];
189 - ReactDOMFlightRelayServer.render(
190 - {
191 - foo: <Foo />,
192 - },
193 - transport,
194 - );
195 -
196 - const model = readThrough(transport);
197 - expect(model).toEqual({
198 - foo: {
199 - bar: 14,
200 - },
201 - });
202 - });
203 -
204 - it('can handle a subset of Hooks, with element as root', () => {
205 - const {useMemo, useCallback} = React;
206 - function Inner({x}) {
207 - const foo = useMemo(() => x + x, [x]);
208 - const bar = useCallback(() => 10 + foo, [foo]);
209 - return bar();
210 - }
211 -
212 - function Foo() {
213 - return <Inner x={2} />;
214 - }
215 - const transport = [];
216 - ReactDOMFlightRelayServer.render(<Foo />, transport);
217 -
218 - const model = readThrough(transport);
219 - expect(model).toEqual(14);
220 - });
221 -
222 - it('should warn in DEV if a class instance polyfill is passed to a host component', () => {
223 - function Bar() {}
224 -
225 - function Foo() {}
226 - Foo.prototype = Object.create(Bar.prototype);
227 - // This is enumerable which some polyfills do.
228 - Foo.prototype.constructor = Foo;
229 - Foo.prototype.method = function () {};
230 -
231 - expect(() => {
232 - const transport = [];
233 - ReactDOMFlightRelayServer.render(<input value={new Foo()} />, transport);
234 - readThrough(transport);
235 - }).toErrorDev(
236 - 'Only plain objects can be passed to Client Components from Server Components. ',
237 - {withoutStack: true},
238 - );
239 - });
240 -});
packages/react-server-dom-webpack/src/ReactFlightDOMClientBrowser.js
+2 -2
@@ -9,7 +9,7 @@
9
10 import type {Thenable} from 'shared/ReactTypes.js';
11
12 -import type {Response as FlightResponse} from 'react-client/src/ReactFlightClientStream';
12 +import type {Response as FlightResponse} from 'react-client/src/ReactFlightClient';
13
14 import type {ReactServerValue} from 'react-client/src/ReactFlightReplyClient';
15
@@ -20,7 +20,7 @@ import {
20 processStringChunk,
21 processBinaryChunk,
22 close,
23 -} from 'react-client/src/ReactFlightClientStream';
23 +} from 'react-client/src/ReactFlightClient';
24
25 import {
26 processReply,
packages/react-server-dom-webpack/src/ReactFlightDOMClientEdge.js
+2 -2
@@ -9,7 +9,7 @@
9
10 import type {Thenable} from 'shared/ReactTypes.js';
11
12 -import type {Response as FlightResponse} from 'react-client/src/ReactFlightClientStream';
12 +import type {Response as FlightResponse} from 'react-client/src/ReactFlightClient';
13
14 import type {SSRManifest} from './ReactFlightClientConfigWebpackBundler';
15
@@ -19,7 +19,7 @@ import {
19 reportGlobalError,
20 processBinaryChunk,
21 close,
22 -} from 'react-client/src/ReactFlightClientStream';
22 +} from 'react-client/src/ReactFlightClient';
23
24 function noServerCall() {
25 throw new Error(
packages/react-server-dom-webpack/src/ReactFlightDOMClientNode.js
+3 -3
@@ -9,7 +9,7 @@
9
10 import type {Thenable} from 'shared/ReactTypes.js';
11
12 -import type {Response} from 'react-client/src/ReactFlightClientStream';
12 +import type {Response} from 'react-client/src/ReactFlightClient';
13
14 import type {SSRManifest} from 'react-client/src/ReactFlightClientConfig';
15
@@ -21,8 +21,8 @@ import {
21 reportGlobalError,
22 processBinaryChunk,
23 close,
24 -} from 'react-client/src/ReactFlightClientStream';
25 -import {processStringChunk} from '../../react-client/src/ReactFlightClientStream';
24 +} from 'react-client/src/ReactFlightClient';
25 +import {processStringChunk} from '../../react-client/src/ReactFlightClient';
26
27 function noServerCall() {
28 throw new Error(
packages/react-server-native-relay/server.js deleted
-10
@@ -1,10 +0,0 @@
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 -export * from './src/ReactFlightNativeRelayServer';
packages/react-server-native-relay/src/ReactFlightClientConfigNativeRelay.js deleted
-99
@@ -1,99 +0,0 @@
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 {JSONValue, ResponseBase} from 'react-client/src/ReactFlightClient';
11 -
12 -import type {JSResourceReference} from 'JSResourceReference';
13 -
14 -import type {ClientReferenceMetadata} from 'ReactFlightNativeRelayClientIntegration';
15 -
16 -export type ClientReference<T> = JSResourceReference<T>;
17 -
18 -import {
19 - parseModelString,
20 - parseModelTuple,
21 -} from 'react-client/src/ReactFlightClient';
22 -
23 -export {
24 - preloadModule,
25 - requireModule,
26 -} from 'ReactFlightNativeRelayClientIntegration';
27 -
28 -import {resolveClientReference as resolveClientReferenceImpl} from 'ReactFlightNativeRelayClientIntegration';
29 -
30 -import isArray from 'shared/isArray';
31 -
32 -export type {ClientReferenceMetadata} from 'ReactFlightNativeRelayClientIntegration';
33 -
34 -export type SSRManifest = null;
35 -export type ServerManifest = null;
36 -export type ServerReferenceId = string;
37 -
38 -export type UninitializedModel = JSONValue;
39 -
40 -export type Response = ResponseBase;
41 -
42 -export function resolveClientReference<T>(
43 - bundlerConfig: SSRManifest,
44 - metadata: ClientReferenceMetadata,
45 -): ClientReference<T> {
46 - return resolveClientReferenceImpl(metadata);
47 -}
48 -
49 -export function resolveServerReference<T>(
50 - bundlerConfig: ServerManifest,
51 - id: ServerReferenceId,
52 -): ClientReference<T> {
53 - throw new Error('Not implemented.');
54 -}
55 -
56 -function parseModelRecursively(
57 - response: Response,
58 - parentObj: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
59 - key: string,
60 - value: JSONValue,
61 -): $FlowFixMe {
62 - if (typeof value === 'string') {
63 - return parseModelString(response, parentObj, key, value);
64 - }
65 - if (typeof value === 'object' && value !== null) {
66 - if (isArray(value)) {
67 - const parsedValue: Array<$FlowFixMe> = [];
68 - for (let i = 0; i < value.length; i++) {
69 - (parsedValue: any)[i] = parseModelRecursively(
70 - response,
71 - value,
72 - '' + i,
73 - value[i],
74 - );
75 - }
76 - return parseModelTuple(response, parsedValue);
77 - } else {
78 - const parsedValue = {};
79 - for (const innerKey in value) {
80 - (parsedValue: any)[innerKey] = parseModelRecursively(
81 - response,
82 - value,
83 - innerKey,
84 - value[innerKey],
85 - );
86 - }
87 - return parsedValue;
88 - }
89 - }
90 - return value;
91 -}
92 -
93 -const dummy = {};
94 -
95 -export function parseModel<T>(response: Response, json: UninitializedModel): T {
96 - return (parseModelRecursively(response, dummy, '', json): any);
97 -}
98 -
99 -export function dispatchHint(code: string, model: mixed) {}
packages/react-server-native-relay/src/ReactFlightNativeRelayClient.js deleted
-56
@@ -1,56 +0,0 @@
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 {RowEncoding} from './ReactFlightNativeRelayProtocol';
11 -
12 -import type {Response} from 'react-client/src/ReactFlightClient';
13 -
14 -import {
15 - createResponse,
16 - resolveModel,
17 - resolveModule,
18 - resolveErrorDev,
19 - resolveErrorProd,
20 - close,
21 - getRoot,
22 -} from 'react-client/src/ReactFlightClient';
23 -
24 -export {createResponse, close, getRoot};
25 -
26 -export function resolveRow(response: Response, chunk: RowEncoding): void {
27 - if (chunk[0] === 'O') {
28 - // $FlowFixMe[incompatible-call] `Chunk` doesn't flow into `JSONValue` because of the `E` row type.
29 - resolveModel(response, chunk[1], chunk[2]);
30 - } else if (chunk[0] === 'I') {
31 - // $FlowFixMe[incompatible-call] `Chunk` doesn't flow into `JSONValue` because of the `E` row type.
32 - resolveModule(response, chunk[1], chunk[2]);
33 - } else {
34 - if (__DEV__) {
35 - resolveErrorDev(
36 - response,
37 - chunk[1],
38 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
39 - // $FlowFixMe[incompatible-use]
40 - // $FlowFixMe[prop-missing]
41 - chunk[2].digest,
42 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
43 - // $FlowFixMe[incompatible-use]
44 - chunk[2].message || '',
45 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
46 - // $FlowFixMe[incompatible-use]
47 - chunk[2].stack || '',
48 - );
49 - } else {
50 - // $FlowFixMe[incompatible-call]: Flow doesn't support disjoint unions on tuples.
51 - // $FlowFixMe[incompatible-use]
52 - // $FlowFixMe[prop-missing]
53 - resolveErrorProd(response, chunk[1], chunk[2].digest);
54 - }
55 - }
56 -}
packages/react-server-native-relay/src/ReactFlightNativeRelayProtocol.js deleted
-34
@@ -1,34 +0,0 @@
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 {ClientReferenceMetadata} from 'ReactFlightNativeRelayServerIntegration';
11 -
12 -export type JSONValue =
13 - | string
14 - | number
15 - | boolean
16 - | null
17 - | {+[key: string]: JSONValue}
18 - | Array<JSONValue>;
19 -
20 -export type RowEncoding =
21 - | ['O', number, JSONValue]
22 - | ['I', number, ClientReferenceMetadata]
23 - | ['P', number, string]
24 - | ['S', number, string]
25 - | [
26 - 'E',
27 - number,
28 - {
29 - digest: string,
30 - message?: string,
31 - stack?: string,
32 - ...
33 - },
34 - ];
packages/react-server-native-relay/src/ReactFlightNativeRelayServer.js deleted
-32
@@ -1,32 +0,0 @@
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 {ReactClientValue} from 'react-server/src/ReactFlightServer';
11 -import type {
12 - ClientManifest,
13 - Destination,
14 -} from './ReactFlightServerConfigNativeRelay';
15 -
16 -import {
17 - createRequest,
18 - startWork,
19 - startFlowing,
20 -} from 'react-server/src/ReactFlightServer';
21 -
22 -function render(
23 - model: ReactClientValue,
24 - destination: Destination,
25 - config: ClientManifest,
26 -): void {
27 - const request = createRequest(model, config);
28 - startWork(request);
29 - startFlowing(request, destination);
30 -}
31 -
32 -export {render};
packages/react-server-native-relay/src/ReactFlightServerConfigNativeRelay.js deleted
-232
@@ -1,232 +0,0 @@
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 {RowEncoding, JSONValue} from './ReactFlightNativeRelayProtocol';
11 -import type {
12 - Request,
13 - ReactClientValue,
14 -} from 'react-server/src/ReactFlightServer';
15 -import hasOwnProperty from 'shared/hasOwnProperty';
16 -import isArray from 'shared/isArray';
17 -import type {JSResourceReference} from 'JSResourceReference';
18 -import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
19 -
20 -export type ClientReference<T> = JSResourceReference<T>;
21 -export type ServerReference<T> = T;
22 -export type ServerReferenceId = {};
23 -
24 -import type {
25 - Destination,
26 - BundlerConfig as ClientManifest,
27 - ClientReferenceMetadata,
28 -} from 'ReactFlightNativeRelayServerIntegration';
29 -
30 -import {resolveModelToJSON} from 'react-server/src/ReactFlightServer';
31 -
32 -import {
33 - emitRow,
34 - close,
35 - resolveClientReferenceMetadata as resolveClientReferenceMetadataImpl,
36 -} from 'ReactFlightNativeRelayServerIntegration';
37 -
38 -export type {
39 - Destination,
40 - BundlerConfig as ClientManifest,
41 - ClientReferenceMetadata,
42 -} from 'ReactFlightNativeRelayServerIntegration';
43 -
44 -export function isClientReference(reference: Object): boolean {
45 - return reference instanceof JSResourceReferenceImpl;
46 -}
47 -
48 -export function isServerReference(reference: Object): boolean {
49 - return false;
50 -}
51 -
52 -export type ClientReferenceKey = ClientReference<any>;
53 -
54 -export function getClientReferenceKey(
55 - reference: ClientReference<any>,
56 -): ClientReferenceKey {
57 - // We use the reference object itself as the key because we assume the
58 - // object will be cached by the bundler runtime.
59 - return reference;
60 -}
61 -
62 -export function resolveClientReferenceMetadata<T>(
63 - config: ClientManifest,
64 - resource: ClientReference<T>,
65 -): ClientReferenceMetadata {
66 - return resolveClientReferenceMetadataImpl(config, resource);
67 -}
68 -
69 -export function getServerReferenceId<T>(
70 - config: ClientManifest,
71 - resource: ServerReference<T>,
72 -): ServerReferenceId {
73 - throw new Error('Not implemented.');
74 -}
75 -
76 -export function getServerReferenceBoundArguments<T>(
77 - config: ClientManifest,
78 - resource: ServerReference<T>,
79 -): Array<ReactClientValue> {
80 - throw new Error('Not implemented.');
81 -}
82 -
83 -export type Chunk = RowEncoding;
84 -
85 -export function processErrorChunkProd(
86 - request: Request,
87 - id: number,
88 - digest: string,
89 -): Chunk {
90 - if (__DEV__) {
91 - // These errors should never make it into a build so we don't need to encode them in codes.json
92 - // eslint-disable-next-line react-internal/prod-error-codes
93 - throw new Error(
94 - 'processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.',
95 - );
96 - }
97 -
98 - return [
99 - 'E',
100 - id,
101 - {
102 - digest,
103 - },
104 - ];
105 -}
106 -export function processErrorChunkDev(
107 - request: Request,
108 - id: number,
109 - digest: string,
110 - message: string,
111 - stack: string,
112 -): Chunk {
113 - if (!__DEV__) {
114 - // These errors should never make it into a build so we don't need to encode them in codes.json
115 - // eslint-disable-next-line react-internal/prod-error-codes
116 - throw new Error(
117 - 'processErrorChunkDev should never be called while in production mode. Use processErrorChunkProd instead. This is a bug in React.',
118 - );
119 - }
120 -
121 - return [
122 - 'E',
123 - id,
124 - {
125 - digest,
126 - message,
127 - stack,
128 - },
129 - ];
130 -}
131 -
132 -function convertModelToJSON(
133 - request: Request,
134 - parent: {+[key: string]: ReactClientValue} | $ReadOnlyArray<ReactClientValue>,
135 - key: string,
136 - model: ReactClientValue,
137 -): JSONValue {
138 - const json = resolveModelToJSON(request, parent, key, model);
139 - if (typeof json === 'object' && json !== null) {
140 - if (isArray(json)) {
141 - const jsonArray: Array<JSONValue> = [];
142 - for (let i = 0; i < json.length; i++) {
143 - jsonArray[i] = convertModelToJSON(request, json, '' + i, json[i]);
144 - }
145 - return jsonArray;
146 - } else {
147 - const jsonObj: {[key: string]: JSONValue} = {};
148 - for (const nextKey in json) {
149 - if (hasOwnProperty.call(json, nextKey)) {
150 - jsonObj[nextKey] = convertModelToJSON(
151 - request,
152 - json,
153 - nextKey,
154 - json[nextKey],
155 - );
156 - }
157 - }
158 - return jsonObj;
159 - }
160 - }
161 - return json;
162 -}
163 -
164 -export function processModelChunk(
165 - request: Request,
166 - id: number,
167 - model: ReactClientValue,
168 -): Chunk {
169 - const json = convertModelToJSON(request, {}, '', model);
170 - return ['O', id, json];
171 -}
172 -
173 -export function processReferenceChunk(
174 - request: Request,
175 - id: number,
176 - reference: string,
177 -): Chunk {
178 - return ['O', id, reference];
179 -}
180 -
181 -export function processImportChunk(
182 - request: Request,
183 - id: number,
184 - clientReferenceMetadata: ClientReferenceMetadata,
185 -): Chunk {
186 - // The clientReferenceMetadata is already a JSON serializable value.
187 - return ['I', id, clientReferenceMetadata];
188 -}
189 -
190 -export function processHintChunk(
191 - request: Request,
192 - id: number,
193 - code: string,
194 - model: JSONValue,
195 -): Chunk {
196 - throw new Error(
197 - 'React Internal Error: processHintChunk is not implemented for Native-Relay. The fact that this method was called means there is a bug in React.',
198 - );
199 -}
200 -
201 -export function scheduleWork(callback: () => void) {
202 - callback();
203 -}
204 -
205 -export function flushBuffered(destination: Destination) {}
206 -
207 -export const supportsRequestStorage = false;
208 -export const requestStorage: AsyncLocalStorage<Request> = (null: any);
209 -
210 -export function beginWriting(destination: Destination) {}
211 -
212 -export function writeChunk(destination: Destination, chunk: Chunk): void {
213 - // $FlowFixMe[incompatible-call] `Chunk` doesn't flow into `JSONValue` because of the `E` row type.
214 - emitRow(destination, chunk);
215 -}
216 -
217 -export function writeChunkAndReturn(
218 - destination: Destination,
219 - chunk: Chunk,
220 -): boolean {
221 - // $FlowFixMe[incompatible-call] `Chunk` doesn't flow into `JSONValue` because of the `E` row type.
222 - emitRow(destination, chunk);
223 - return true;
224 -}
225 -
226 -export function completeWriting(destination: Destination) {}
227 -
228 -export {close};
229 -
230 -export function closeWithError(destination: Destination, error: mixed): void {
231 - close(destination);
232 -}
packages/react-server-native-relay/src/__mocks__/ReactFlightNativeRelayClientIntegration.js deleted
-22
@@ -1,22 +0,0 @@
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 -
8 -'use strict';
9 -
10 -import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
11 -
12 -const ReactFlightNativeRelayClientIntegration = {
13 - resolveClientReference(metadata) {
14 - return new JSResourceReferenceImpl(metadata);
15 - },
16 - preloadModule(clientReference) {},
17 - requireModule(clientReference) {
18 - return clientReference._moduleId;
19 - },
20 -};
21 -
22 -module.exports = ReactFlightNativeRelayClientIntegration;
packages/react-server-native-relay/src/__mocks__/ReactFlightNativeRelayServerIntegration.js deleted
-20
@@ -1,20 +0,0 @@
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 -
8 -'use strict';
9 -
10 -const ReactFlightNativeRelayServerIntegration = {
11 - emitRow(destination, json) {
12 - destination.push(json);
13 - },
14 - close(destination) {},
15 - resolveClientReferenceMetadata(config, resource) {
16 - return resource._moduleId;
17 - },
18 -};
19 -
20 -module.exports = ReactFlightNativeRelayServerIntegration;
packages/react-server-native-relay/src/__tests__/ReactFlightNativeRelay-test.internal.js deleted
-140
@@ -1,140 +0,0 @@
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 -
8 -'use strict';
9 -
10 -let React;
11 -let ReactFabric;
12 -let createReactNativeComponentClass;
13 -let View;
14 -let Text;
15 -let JSResourceReferenceImpl;
16 -let ReactNativeFlightRelayServer;
17 -let ReactNativeFlightRelayClient;
18 -
19 -describe('ReactFlightNativeRelay', () => {
20 - beforeEach(() => {
21 - jest.resetModules();
22 -
23 - require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
24 -
25 - React = require('react');
26 - // TODO: Switch this out to react-native
27 - ReactFabric = require('react-native-renderer/fabric');
28 - createReactNativeComponentClass =
29 - require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
30 - .ReactNativeViewConfigRegistry.register;
31 - View = createReactNativeComponentClass('RCTView', () => ({
32 - validAttributes: {},
33 - uiViewClassName: 'RCTView',
34 - }));
35 - Text = createReactNativeComponentClass('RCTText', () => ({
36 - validAttributes: {},
37 - uiViewClassName: 'RCTText',
38 - }));
39 -
40 - ReactNativeFlightRelayServer = require('react-server-native-relay/server');
41 - ReactNativeFlightRelayClient = require('react-server-native-relay');
42 - JSResourceReferenceImpl = require('JSResourceReferenceImpl');
43 - });
44 -
45 - function readThrough(data) {
46 - const response = ReactNativeFlightRelayClient.createResponse();
47 - for (let i = 0; i < data.length; i++) {
48 - const chunk = data[i];
49 - ReactNativeFlightRelayClient.resolveRow(response, chunk);
50 - }
51 - ReactNativeFlightRelayClient.close(response);
52 - const promise = ReactNativeFlightRelayClient.getRoot(response);
53 - let model;
54 - let error;
55 - promise.then(
56 - m => (model = m),
57 - e => (error = e),
58 - );
59 - if (error) {
60 - throw error;
61 - }
62 - return model;
63 - }
64 -
65 - it('can render a Server Component', () => {
66 - function Bar({text}) {
67 - return <Text>{text.toUpperCase()}</Text>;
68 - }
69 - function Foo() {
70 - return {
71 - bar: (
72 - <View>
73 - <Bar text="a" /> <Bar text="b" />
74 - </View>
75 - ),
76 - };
77 - }
78 - const transport = [];
79 - ReactNativeFlightRelayServer.render(
80 - {
81 - foo: <Foo />,
82 - },
83 - transport,
84 - );
85 -
86 - const model = readThrough(transport);
87 - expect(model).toMatchSnapshot();
88 - });
89 -
90 - it('can render a Client Component using a module reference and render there', () => {
91 - function UserClient(props) {
92 - return (
93 - <Text>
94 - {props.greeting}, {props.name}
95 - </Text>
96 - );
97 - }
98 - const User = new JSResourceReferenceImpl(UserClient);
99 -
100 - function Greeting({firstName, lastName}) {
101 - return <User greeting="Hello" name={firstName + ' ' + lastName} />;
102 - }
103 -
104 - const model = {
105 - greeting: <Greeting firstName="Seb" lastName="Smith" />,
106 - };
107 -
108 - const transport = [];
109 - ReactNativeFlightRelayServer.render(model, transport);
110 -
111 - const modelClient = readThrough(transport);
112 -
113 - ReactFabric.render(modelClient.greeting, 1);
114 - expect(
115 - nativeFabricUIManager.__dumpHierarchyForJestTestsOnly(),
116 - ).toMatchSnapshot();
117 - });
118 -
119 - it('should warn in DEV if a class instance polyfill is passed to a host component', () => {
120 - function Bar() {}
121 -
122 - function Foo() {}
123 - Foo.prototype = Object.create(Bar.prototype);
124 - // This is enumerable which some polyfills do.
125 - Foo.prototype.constructor = Foo;
126 - Foo.prototype.method = function () {};
127 -
128 - expect(() => {
129 - const transport = [];
130 - ReactNativeFlightRelayServer.render(
131 - <input value={new Foo()} />,
132 - transport,
133 - );
134 - readThrough(transport);
135 - }).toErrorDev(
136 - 'Only plain objects can be passed to Client Components from Server Components. ',
137 - {withoutStack: true},
138 - );
139 - });
140 -});
packages/react-server-native-relay/src/__tests__/__snapshots__/ReactFlightNativeRelay-test.internal.js.snap deleted
-25
@@ -1,25 +0,0 @@
1 -// Jest Snapshot v1, https://goo.gl/fbAQLP
2 -
3 -exports[`ReactFlightNativeRelay can render a Client Component using a module reference and render there 1`] = `
4 -"1
5 - RCTText null
6 - RCTRawText {"text":"Hello"}
7 - RCTRawText {"text":", "}
8 - RCTRawText {"text":"Seb Smith"}"
9 -`;
10 -
11 -exports[`ReactFlightNativeRelay can render a Server Component 1`] = `
12 -{
13 - "foo": {
14 - "bar": <RCTView>
15 - <RCTText>
16 - A
17 - </RCTText>
18 -
19 - <RCTText>
20 - B
21 - </RCTText>
22 - </RCTView>,
23 - },
24 -}
25 -`;
packages/react-server/src/ReactFlightServer.js
+111 -16
@@ -7,9 +7,22 @@
7 * @flow
8 */
9
10 +import type {Chunk, Destination} from './ReactServerStreamConfig';
11 +
12 +import {
13 + scheduleWork,
14 + flushBuffered,
15 + beginWriting,
16 + writeChunkAndReturn,
17 + stringToChunk,
18 + completeWriting,
19 + close,
20 + closeWithError,
21 +} from './ReactServerStreamConfig';
22 +
23 +export type {Destination, Chunk} from './ReactServerStreamConfig';
24 +
25 import type {
11 - Destination,
12 - Chunk,
26 ClientManifest,
27 ClientReferenceMetadata,
28 ClientReference,
@@ -34,19 +47,6 @@ import type {
47 import type {LazyComponent} from 'react/src/ReactLazy';
48
49 import {
37 - scheduleWork,
38 - beginWriting,
39 - writeChunkAndReturn,
40 - completeWriting,
41 - flushBuffered,
42 - close,
43 - closeWithError,
44 - processModelChunk,
45 - processImportChunk,
46 - processErrorChunkProd,
47 - processErrorChunkDev,
48 - processReferenceChunk,
49 - processHintChunk,
50 resolveClientReferenceMetadata,
51 getServerReferenceId,
52 getServerReferenceBoundArguments,
@@ -99,6 +99,16 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
99 import isArray from 'shared/isArray';
100 import {SuspenseException, getSuspendedThenable} from './ReactFlightThenable';
101
102 +type JSONValue =
103 + | string
104 + | boolean
105 + | number
106 + | null
107 + | {+[key: string]: JSONValue}
108 + | $ReadOnlyArray<JSONValue>;
109 +
110 +const stringify = JSON.stringify;
111 +
112 type ReactJSONValue =
113 | string
114 | boolean
@@ -723,7 +733,7 @@ function escapeStringValue(value: string): string {
733 let insideContextProps = null;
734 let isInsideContextValue = false;
735
726 -export function resolveModelToJSON(
736 +function resolveModelToJSON(
737 request: Request,
738 parent:
739 | {+[key: string | number]: ReactClientValue}
@@ -1450,3 +1460,88 @@ function importServerContexts(
1460 }
1461 return rootContextSnapshot;
1462 }
1463 +
1464 +function serializeRowHeader(tag: string, id: number) {
1465 + return id.toString(16) + ':' + tag;
1466 +}
1467 +
1468 +function processErrorChunkProd(
1469 + request: Request,
1470 + id: number,
1471 + digest: string,
1472 +): Chunk {
1473 + if (__DEV__) {
1474 + // These errors should never make it into a build so we don't need to encode them in codes.json
1475 + // eslint-disable-next-line react-internal/prod-error-codes
1476 + throw new Error(
1477 + 'processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.',
1478 + );
1479 + }
1480 +
1481 + const errorInfo: any = {digest};
1482 + const row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
1483 + return stringToChunk(row);
1484 +}
1485 +
1486 +function processErrorChunkDev(
1487 + request: Request,
1488 + id: number,
1489 + digest: string,
1490 + message: string,
1491 + stack: string,
1492 +): Chunk {
1493 + if (!__DEV__) {
1494 + // These errors should never make it into a build so we don't need to encode them in codes.json
1495 + // eslint-disable-next-line react-internal/prod-error-codes
1496 + throw new Error(
1497 + 'processErrorChunkDev should never be called while in production mode. Use processErrorChunkProd instead. This is a bug in React.',
1498 + );
1499 + }
1500 +
1501 + const errorInfo: any = {digest, message, stack};
1502 + const row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
1503 + return stringToChunk(row);
1504 +}
1505 +
1506 +function processModelChunk(
1507 + request: Request,
1508 + id: number,
1509 + model: ReactClientValue,
1510 +): Chunk {
1511 + // $FlowFixMe[incompatible-type] stringify can return null
1512 + const json: string = stringify(model, request.toJSON);
1513 + const row = id.toString(16) + ':' + json + '\n';
1514 + return stringToChunk(row);
1515 +}
1516 +
1517 +function processReferenceChunk(
1518 + request: Request,
1519 + id: number,
1520 + reference: string,
1521 +): Chunk {
1522 + const json = stringify(reference);
1523 + const row = id.toString(16) + ':' + json + '\n';
1524 + return stringToChunk(row);
1525 +}
1526 +
1527 +function processImportChunk(
1528 + request: Request,
1529 + id: number,
1530 + clientReferenceMetadata: ReactClientValue,
1531 +): Chunk {
1532 + // $FlowFixMe[incompatible-type] stringify can return null
1533 + const json: string = stringify(clientReferenceMetadata);
1534 + const row = serializeRowHeader('I', id) + json + '\n';
1535 + return stringToChunk(row);
1536 +}
1537 +
1538 +function processHintChunk(
1539 + request: Request,
1540 + id: number,
1541 + code: string,
1542 + model: JSONValue,
1543 +): Chunk {
1544 + const json: string = stringify(model);
1545 + const row = serializeRowHeader('H' + code, id) + json + '\n';
1546 + return stringToChunk(row);
1547 +}
packages/react-server/src/ReactFlightServerConfigStream.js deleted
-174
@@ -1,174 +0,0 @@
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 -// This file is an intermediate layer to translate between Flight
11 -// calls to stream output over a binary stream.
12 -
13 -/*
14 -FLIGHT PROTOCOL GRAMMAR
15 -
16 -Response
17 -- RowSequence
18 -
19 -RowSequence
20 -- Row RowSequence
21 -- Row
22 -
23 -Row
24 -- "J" RowID JSONData
25 -- "M" RowID JSONModuleData
26 -- "H" RowID HTMLData
27 -- "B" RowID BlobData
28 -- "U" RowID URLData
29 -- "E" RowID ErrorData
30 -
31 -RowID
32 -- HexDigits ":"
33 -
34 -HexDigits
35 -- HexDigit HexDigits
36 -- HexDigit
37 -
38 -HexDigit
39 -- 0-F
40 -
41 -URLData
42 -- (UTF8 encoded URL) "\n"
43 -
44 -ErrorData
45 -- (UTF8 encoded JSON: {message: "...", stack: "..."}) "\n"
46 -
47 -JSONData
48 -- (UTF8 encoded JSON) "\n"
49 - - String values that begin with $ are escaped with a "$" prefix.
50 - - References to other rows are encoding as JSONReference strings.
51 -
52 -JSONReference
53 -- "$" HexDigits
54 -
55 -HTMLData
56 -- ByteSize (UTF8 encoded HTML)
57 -
58 -BlobData
59 -- ByteSize (Binary Data)
60 -
61 -ByteSize
62 -- (unsigned 32-bit integer)
63 -*/
64 -
65 -// TODO: Implement HTMLData, BlobData and URLData.
66 -
67 -import type {
68 - Request,
69 - ReactClientValue,
70 -} from 'react-server/src/ReactFlightServer';
71 -
72 -import {stringToChunk} from './ReactServerStreamConfig';
73 -
74 -import type {Chunk} from './ReactServerStreamConfig';
75 -
76 -export type {Destination, Chunk} from './ReactServerStreamConfig';
77 -
78 -const stringify = JSON.stringify;
79 -
80 -function serializeRowHeader(tag: string, id: number) {
81 - return id.toString(16) + ':' + tag;
82 -}
83 -
84 -export function processErrorChunkProd(
85 - request: Request,
86 - id: number,
87 - digest: string,
88 -): Chunk {
89 - if (__DEV__) {
90 - // These errors should never make it into a build so we don't need to encode them in codes.json
91 - // eslint-disable-next-line react-internal/prod-error-codes
92 - throw new Error(
93 - 'processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.',
94 - );
95 - }
96 -
97 - const errorInfo: any = {digest};
98 - const row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
99 - return stringToChunk(row);
100 -}
101 -
102 -export function processErrorChunkDev(
103 - request: Request,
104 - id: number,
105 - digest: string,
106 - message: string,
107 - stack: string,
108 -): Chunk {
109 - if (!__DEV__) {
110 - // These errors should never make it into a build so we don't need to encode them in codes.json
111 - // eslint-disable-next-line react-internal/prod-error-codes
112 - throw new Error(
113 - 'processErrorChunkDev should never be called while in production mode. Use processErrorChunkProd instead. This is a bug in React.',
114 - );
115 - }
116 -
117 - const errorInfo: any = {digest, message, stack};
118 - const row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
119 - return stringToChunk(row);
120 -}
121 -
122 -export function processModelChunk(
123 - request: Request,
124 - id: number,
125 - model: ReactClientValue,
126 -): Chunk {
127 - // $FlowFixMe[incompatible-type] stringify can return null
128 - const json: string = stringify(model, request.toJSON);
129 - const row = id.toString(16) + ':' + json + '\n';
130 - return stringToChunk(row);
131 -}
132 -
133 -export function processReferenceChunk(
134 - request: Request,
135 - id: number,
136 - reference: string,
137 -): Chunk {
138 - const json = stringify(reference);
139 - const row = id.toString(16) + ':' + json + '\n';
140 - return stringToChunk(row);
141 -}
142 -
143 -export function processImportChunk(
144 - request: Request,
145 - id: number,
146 - clientReferenceMetadata: ReactClientValue,
147 -): Chunk {
148 - // $FlowFixMe[incompatible-type] stringify can return null
149 - const json: string = stringify(clientReferenceMetadata);
150 - const row = serializeRowHeader('I', id) + json + '\n';
151 - return stringToChunk(row);
152 -}
153 -
154 -export function processHintChunk(
155 - request: Request,
156 - id: number,
157 - code: string,
158 - model: JSONValue,
159 -): Chunk {
160 - const json: string = stringify(model);
161 - const row = serializeRowHeader('H' + code, id) + json + '\n';
162 - return stringToChunk(row);
163 -}
164 -
165 -export {
166 - scheduleWork,
167 - flushBuffered,
168 - beginWriting,
169 - writeChunk,
170 - writeChunkAndReturn,
171 - completeWriting,
172 - close,
173 - closeWithError,
174 -} from './ReactServerStreamConfig';
packages/react-server/src/forks/ReactFizzConfig.dom-fb.js renamed
packages/react-server/src/forks/ReactFizzConfig.native-relay.js deleted
-14
@@ -1,14 +0,0 @@
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 -import type {Request} from 'react-server/src/ReactFizzServer';
10 -
11 -export * from 'react-native-renderer/src/server/ReactFizzConfigNative';
12 -
13 -export const supportsRequestStorage = false;
14 -export const requestStorage: AsyncLocalStorage<Request> = (null: any);
packages/react-server/src/forks/ReactFlightServerConfig.custom.js
+4 -4
@@ -6,13 +6,13 @@
6 *
7 * @flow
8 */
9 +
10 import type {Request} from 'react-server/src/ReactFlightServer';
11
11 -export * from '../ReactFlightServerConfigStream';
12 export * from '../ReactFlightServerConfigBundlerCustom';
13
14 -export type Hints = null;
15 -export type HintModel = '';
14 +export type Hints = any;
15 +export type HintModel = any;
16
17 export const isPrimaryRenderer = false;
18
@@ -21,6 +21,6 @@ export const prepareHostDispatcher = () => {};
21 export const supportsRequestStorage = false;
22 export const requestStorage: AsyncLocalStorage<Request> = (null: any);
23
24 -export function createHints(): null {
24 +export function createHints(): any {
25 return null;
26 }
packages/react-server/src/forks/ReactFlightServerConfig.dom-browser.js
-1
@@ -9,7 +9,6 @@
9
10 import type {Request} from 'react-server/src/ReactFlightServer';
11
12 -export * from '../ReactFlightServerConfigStream';
12 export * from 'react-server-dom-webpack/src/ReactFlightServerConfigWebpackBundler';
13 export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
14
packages/react-server/src/forks/ReactFlightServerConfig.dom-bun.js
-1
@@ -9,7 +9,6 @@
9
10 import type {Request} from 'react-server/src/ReactFlightServer';
11
12 -export * from '../ReactFlightServerConfigStream';
12 export * from '../ReactFlightServerConfigBundlerCustom';
13 export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
14
packages/react-server/src/forks/ReactFlightServerConfig.dom-edge-webpack.js
-1
@@ -8,7 +8,6 @@
8 */
9 import type {Request} from 'react-server/src/ReactFlightServer';
10
11 -export * from '../ReactFlightServerConfigStream';
11 export * from 'react-server-dom-webpack/src/ReactFlightServerConfigWebpackBundler';
12 export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
13
packages/react-server/src/forks/ReactFlightServerConfig.dom-legacy.js
-1
@@ -9,7 +9,6 @@
9
10 import type {Request} from 'react-server/src/ReactFlightServer';
11
12 -export * from '../ReactFlightServerConfigStream';
12 export * from 'react-server-dom-webpack/src/ReactFlightServerConfigWebpackBundler';
13 export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
14
packages/react-server/src/forks/ReactFlightServerConfig.dom-node-webpack.js
-1
@@ -10,7 +10,6 @@ import {AsyncLocalStorage} from 'async_hooks';
10
11 import type {Request} from 'react-server/src/ReactFlightServer';
12
13 -export * from '../ReactFlightServerConfigStream';
13 export * from 'react-server-dom-webpack/src/ReactFlightServerConfigWebpackBundler';
14 export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
15
packages/react-server/src/forks/ReactFlightServerConfig.dom-node.js
-1
@@ -11,7 +11,6 @@ import {AsyncLocalStorage} from 'async_hooks';
11
12 import type {Request} from 'react-server/src/ReactFlightServer';
13
14 -export * from '../ReactFlightServerConfigStream';
14 export * from 'react-server-dom-webpack/src/ReactFlightServerConfigWebpackBundler';
15 export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
16
packages/react-server/src/forks/ReactFlightServerConfig.dom-relay.js deleted
-11
@@ -1,11 +0,0 @@
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 -export * from 'react-server-dom-relay/src/ReactFlightServerConfigDOMRelay';
11 -export * from 'react-dom-bindings/src/server/ReactFlightServerConfigDOM';
packages/react-server/src/forks/ReactFlightServerConfig.native-relay.js deleted
-11
@@ -1,11 +0,0 @@
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 -export * from 'react-server-native-relay/src/ReactFlightServerConfigNativeRelay';
11 -export * from 'react-native-renderer/src/server/ReactFlightServerConfigNative';
packages/react-server/src/forks/ReactServerStreamConfig.dom-fb.js renamed
+1 -1
@@ -7,4 +7,4 @@
7 * @flow
8 */
9
10 -export * from './src/ReactFlightNativeRelayClient';
10 +export * from '../../../react-server-dom-fb/src/ReactServerStreamConfigFB';
packages/react-server/src/forks/ReactServerStreamConfig.dom-relay.js deleted
-10
@@ -1,10 +0,0 @@
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 -export * from 'react-server-dom-relay/src/ReactServerStreamConfigFB';
packages/react-server/src/forks/ReactServerStreamConfig.native-relay.js deleted
-10
@@ -1,10 +0,0 @@
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 -export * from '../ReactServerStreamConfigNode';
scripts/flow/config/flowconfig
-1
@@ -23,7 +23,6 @@
23 ./scripts/flow/environment.js
24 ./scripts/flow/react-devtools.js
25 ./scripts/flow/react-native-host-hooks.js
26 -./scripts/flow/react-relay-hooks.js
26 ./scripts/flow/xplat.js
27
28 [lints]
scripts/flow/createFlowConfigs.js
+18 -4
@@ -16,11 +16,21 @@ const configTemplate = fs
16 .readFileSync(__dirname + '/config/flowconfig')
17 .toString();
18
19 -function writeConfig(renderer, rendererInfo, isServerSupported) {
19 +function writeConfig(
20 + renderer,
21 + rendererInfo,
22 + isServerSupported,
23 + isFlightSupported,
24 +) {
25 const folder = __dirname + '/' + renderer;
26 mkdirp.sync(folder);
27
28 + isFlightSupported =
29 + isFlightSupported === true ||
30 + (isServerSupported && isFlightSupported !== false);
31 +
32 const serverRenderer = isServerSupported ? renderer : 'custom';
33 + const flightRenderer = isFlightSupported ? renderer : 'custom';
34
35 const ignoredPaths = [];
36
@@ -35,7 +45,10 @@ function writeConfig(renderer, rendererInfo, isServerSupported) {
45 ignoredPaths.push(`.*/packages/${otherPath}`);
46 });
47
38 - if (otherRenderer.shortName !== serverRenderer) {
48 + if (
49 + otherRenderer.shortName !== serverRenderer &&
50 + otherRenderer.shortName !== flightRenderer
51 + ) {
52 ignoredPaths.push(
53 `.*/packages/.*/forks/.*\\.${otherRenderer.shortName}.js`,
54 );
@@ -54,8 +67,8 @@ function writeConfig(renderer, rendererInfo, isServerSupported) {
67 module.name_mapper='ReactFiberConfig$$' -> 'forks/ReactFiberConfig.${renderer}'
68 module.name_mapper='ReactServerStreamConfig$$' -> 'forks/ReactServerStreamConfig.${serverRenderer}'
69 module.name_mapper='ReactFizzConfig$$' -> 'forks/ReactFizzConfig.${serverRenderer}'
57 -module.name_mapper='ReactFlightServerConfig$$' -> 'forks/ReactFlightServerConfig.${serverRenderer}'
58 -module.name_mapper='ReactFlightClientConfig$$' -> 'forks/ReactFlightClientConfig.${serverRenderer}'
70 +module.name_mapper='ReactFlightServerConfig$$' -> 'forks/ReactFlightServerConfig.${flightRenderer}'
71 +module.name_mapper='ReactFlightClientConfig$$' -> 'forks/ReactFlightClientConfig.${flightRenderer}'
72 module.name_mapper='react-devtools-feature-flags' -> 'react-devtools-shared/src/config/DevToolsFeatureFlags.default'
73 `.trim(),
74 )
@@ -96,6 +109,7 @@ inlinedHostConfigs.forEach(rendererInfo => {
109 rendererInfo.shortName,
110 rendererInfo,
111 rendererInfo.isServerSupported,
112 + rendererInfo.isFlightSupported,
113 );
114 }
115 });
scripts/flow/react-relay-hooks.js deleted
-102
@@ -1,102 +0,0 @@
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 -type JSONValue =
11 - | string
12 - | boolean
13 - | number
14 - | null
15 - | {+[key: string]: JSONValue}
16 - | $ReadOnlyArray<JSONValue>;
17 -
18 -declare module 'JSResourceReference' {
19 - declare export interface JSResourceReference<T> {
20 - getModuleId(): string;
21 - getModuleIdAsRef(): $Flow$ModuleRef<T>;
22 - getModuleIfRequired(): ?T;
23 - load(): Promise<T>;
24 - preload(): void;
25 - }
26 -}
27 -
28 -declare module 'JSResourceReferenceImpl' {
29 - declare export default class JSResourceReferenceImpl<T> {
30 - getModuleId(): string;
31 - getModuleIdAsRef(): $Flow$ModuleRef<T>;
32 - getModuleIfRequired(): ?T;
33 - load(): Promise<T>;
34 - preload(): void;
35 - }
36 -}
37 -
38 -declare module 'ReactFlightDOMRelayServerIntegration' {
39 - import type {JSResourceReference} from 'JSResourceReference';
40 -
41 - declare export opaque type Destination;
42 - declare export opaque type BundlerConfig;
43 - declare export function emitRow(
44 - destination: Destination,
45 - json: JSONValue,
46 - ): void;
47 - declare export function close(destination: Destination): void;
48 -
49 - declare export type ClientReferenceMetadata = JSONValue;
50 - declare export function resolveClientReferenceMetadata<T>(
51 - config: BundlerConfig,
52 - resourceReference: JSResourceReference<T>,
53 - ): ClientReferenceMetadata;
54 -}
55 -
56 -declare module 'ReactFlightDOMRelayClientIntegration' {
57 - import type {JSResourceReference} from 'JSResourceReference';
58 -
59 - declare export opaque type ClientReferenceMetadata;
60 - declare export function resolveClientReference<T>(
61 - moduleData: ClientReferenceMetadata,
62 - ): JSResourceReference<T>;
63 - declare export function preloadModule<T>(
64 - moduleReference: JSResourceReference<T>,
65 - ): null | Promise<void>;
66 - declare export function requireModule<T>(
67 - moduleReference: JSResourceReference<T>,
68 - ): T;
69 -}
70 -
71 -declare module 'ReactFlightNativeRelayServerIntegration' {
72 - import type {JSResourceReference} from 'JSResourceReference';
73 -
74 - declare export opaque type Destination;
75 - declare export opaque type BundlerConfig;
76 - declare export function emitRow(
77 - destination: Destination,
78 - json: JSONValue,
79 - ): void;
80 - declare export function close(destination: Destination): void;
81 -
82 - declare export type ClientReferenceMetadata = JSONValue;
83 - declare export function resolveClientReferenceMetadata<T>(
84 - config: BundlerConfig,
85 - resourceReference: JSResourceReference<T>,
86 - ): ClientReferenceMetadata;
87 -}
88 -
89 -declare module 'ReactFlightNativeRelayClientIntegration' {
90 - import type {JSResourceReference} from 'JSResourceReference';
91 -
92 - declare export opaque type ClientReferenceMetadata;
93 - declare export function resolveClientReference<T>(
94 - moduleData: ClientReferenceMetadata,
95 - ): JSResourceReference<T>;
96 - declare export function preloadModule<T>(
97 - moduleReference: JSResourceReference<T>,
98 - ): null | Promise<void>;
99 - declare export function requireModule<T>(
100 - moduleReference: JSResourceReference<T>,
101 - ): T;
102 -}
scripts/rollup/bundles.js
+1 -65
@@ -253,7 +253,7 @@ const bundles = [
253 {
254 bundleTypes: __EXPERIMENTAL__ ? [FB_WWW_DEV, FB_WWW_PROD] : [],
255 moduleType: RENDERER,
256 - entry: 'react-server-dom-relay/src/ReactDOMServerFB.js',
256 + entry: 'react-server-dom-fb/src/ReactDOMServerFB.js',
257 global: 'ReactDOMServerStreaming',
258 minifyWithProdErrorCodes: false,
259 wrapWithModuleBoundaries: false,
@@ -450,70 +450,6 @@ const bundles = [
450 externals: ['url', 'module'],
451 },
452
453 - /******* React Server DOM Relay Writer *******/
454 - {
455 - bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],
456 - moduleType: RENDERER,
457 - entry: 'react-server-dom-relay/server',
458 - global: 'ReactFlightDOMRelayServer',
459 - minifyWithProdErrorCodes: false,
460 - wrapWithModuleBoundaries: false,
461 - externals: [
462 - 'react',
463 - 'ReactFlightDOMRelayServerIntegration',
464 - 'JSResourceReferenceImpl',
465 - ],
466 - },
467 -
468 - /******* React Server DOM Relay Reader *******/
469 - {
470 - bundleTypes: [FB_WWW_DEV, FB_WWW_PROD],
471 - moduleType: RENDERER,
472 - entry: 'react-server-dom-relay',
473 - global: 'ReactFlightDOMRelayClient',
474 - minifyWithProdErrorCodes: true,
475 - wrapWithModuleBoundaries: false,
476 - externals: [
477 - 'react',
478 - 'ReactFlightDOMRelayClientIntegration',
479 - 'JSResourceReferenceImpl',
480 - ],
481 - },
482 -
483 - /******* React Server Native Relay Writer *******/
484 - {
485 - bundleTypes: [RN_FB_DEV, RN_FB_PROD],
486 - moduleType: RENDERER,
487 - entry: 'react-server-native-relay/server',
488 - global: 'ReactFlightNativeRelayServer',
489 - minifyWithProdErrorCodes: false,
490 - wrapWithModuleBoundaries: false,
491 - externals: [
492 - 'react',
493 - 'ReactFlightNativeRelayServerIntegration',
494 - 'JSResourceReferenceImpl',
495 - 'ReactNativeInternalFeatureFlags',
496 - 'util',
497 - 'async_hooks',
498 - ],
499 - },
500 -
501 - /******* React Server Native Relay Reader *******/
502 - {
503 - bundleTypes: [RN_FB_DEV, RN_FB_PROD],
504 - moduleType: RENDERER,
505 - entry: 'react-server-native-relay',
506 - global: 'ReactFlightNativeRelayClient',
507 - minifyWithProdErrorCodes: true,
508 - wrapWithModuleBoundaries: false,
509 - externals: [
510 - 'react',
511 - 'ReactFlightNativeRelayClientIntegration',
512 - 'JSResourceReferenceImpl',
513 - 'ReactNativeInternalFeatureFlags',
514 - ],
515 - },
516 -
453 /******* React Suspense Test Utils *******/
454 {
455 bundleTypes: [NODE_ES2015],
scripts/rollup/packaging.js
-2
@@ -93,8 +93,6 @@ function getBundleOutputPath(bundle, bundleType, filename, packageName) {
93 /\.js$/,
94 '.fb.js'
95 )}`;
96 - case 'react-server-native-relay':
97 - return `build/facebook-relay/flight/${filename}`;
96 default:
97 throw new Error('Unknown RN package.');
98 }
scripts/shared/inlinedHostConfigs.js
+17 -45
@@ -34,7 +34,6 @@ module.exports = [
34 'react-server-dom-webpack/server',
35 'react-server-dom-webpack/server.node.unbundled',
36 'react-server-dom-webpack/src/ReactFlightDOMServerNode.js', // react-server-dom-webpack/server.node
37 - 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
37 'react-devtools',
38 'react-devtools-core',
39 'react-devtools-shell',
@@ -85,7 +84,6 @@ module.exports = [
84 'react-server-dom-webpack/server.browser',
85 'react-server-dom-webpack/src/ReactFlightDOMClientBrowser.js', // react-server-dom-webpack/client.browser
86 'react-server-dom-webpack/src/ReactFlightDOMServerBrowser.js', // react-server-dom-webpack/server.browser
88 - 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
87 'react-devtools',
88 'react-devtools-core',
89 'react-devtools-shell',
@@ -117,7 +115,6 @@ module.exports = [
115 'react-server-dom-webpack/server.edge',
116 'react-server-dom-webpack/src/ReactFlightDOMClientEdge.js', // react-server-dom-webpack/client.edge
117 'react-server-dom-webpack/src/ReactFlightDOMServerEdge.js', // react-server-dom-webpack/server.edge
120 - 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
118 'react-devtools',
119 'react-devtools-core',
120 'react-devtools-shell',
@@ -148,7 +145,6 @@ module.exports = [
145 'react-server-dom-webpack/server',
146 'react-server-dom-webpack/server.node',
147 'react-server-dom-webpack/src/ReactFlightDOMServerNode.js', // react-server-dom-webpack/server.node
151 - 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
148 'react-devtools',
149 'react-devtools-core',
150 'react-devtools-shell',
@@ -174,18 +170,23 @@ module.exports = [
170 'react-dom/src/server/ReactDOMLegacyServerNode.js', // react-dom/server.node
171 'react-dom/src/server/ReactDOMLegacyServerNode.classic.fb.js',
172 'react-dom/src/server/ReactDOMLegacyServerNodeStream.js', // file indirection to support partial forking of some methods in *Node
177 - 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
173 'shared/ReactDOMSharedInternals',
174 ],
175 isFlowTyped: true,
176 isServerSupported: true,
177 },
178 {
184 - shortName: 'art',
185 - entryPoints: ['react-art'],
186 - paths: ['react-art'],
187 - isFlowTyped: false, // TODO: type it.
188 - isServerSupported: false,
179 + shortName: 'dom-fb',
180 + entryPoints: ['react-server-dom-fb/src/ReactDOMServerFB.js'],
181 + paths: [
182 + 'react-dom',
183 + 'react-dom-bindings',
184 + 'react-server-dom-fb',
185 + 'shared/ReactDOMSharedInternals',
186 + ],
187 + isFlowTyped: true,
188 + isServerSupported: true,
189 + isFlightSupported: false,
190 },
191 {
192 shortName: 'native',
@@ -209,36 +210,11 @@ module.exports = [
210 isServerSupported: false,
211 },
212 {
212 - shortName: 'dom-relay',
213 - entryPoints: [
214 - 'react-server-dom-relay',
215 - 'react-server-dom-relay/server',
216 - 'react-server-dom-relay/src/ReactDOMServerFB.js',
217 - ],
218 - paths: [
219 - 'react-dom',
220 - 'react-dom-bindings',
221 - 'react-server-dom-relay',
222 - 'shared/ReactDOMSharedInternals',
223 - ],
224 - isFlowTyped: true,
225 - isServerSupported: true,
226 - },
227 - {
228 - shortName: 'native-relay',
229 - entryPoints: [
230 - 'react-server-native-relay',
231 - 'react-server-native-relay/server',
232 - ],
233 - paths: [
234 - 'react-native-renderer',
235 - 'react-server-native-relay',
236 - // this is included here so that it's not included in the main native check
237 - // remove this when it's added to the main native renderer.
238 - 'react-native-renderer/src/server',
239 - ],
240 - isFlowTyped: true,
241 - isServerSupported: true,
213 + shortName: 'art',
214 + entryPoints: ['react-art'],
215 + paths: ['react-art'],
216 + isFlowTyped: false, // TODO: type it.
217 + isServerSupported: false,
218 },
219 {
220 shortName: 'custom',
@@ -248,11 +224,7 @@ module.exports = [
224 'react-server',
225 'react-server/flight',
226 ],
251 - paths: [
252 - 'react-client/flight',
253 - 'react-server/flight',
254 - 'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
255 - ],
227 + paths: ['react-client/flight', 'react-server/flight'],
228 isFlowTyped: true,
229 isServerSupported: true,
230 },
yarn.lock
-8
@@ -14143,14 +14143,6 @@ saxes@^6.0.0:
14143 loose-envify "^1.1.0"
14144 object-assign "^4.1.1"
14145
14146 -scheduler@^0.11.0:
14147 - version "0.11.3"
14148 - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.11.3.tgz#b5769b90cf8b1464f3f3cfcafe8e3cd7555a2d6b"
14149 - integrity sha512-i9X9VRRVZDd3xZw10NY5Z2cVMbdYg6gqFecfj79USv1CFN+YrJ3gIPRKf1qlY+Sxly4djoKdfx1T+m9dnRB8kQ==
14150 - dependencies:
14151 - loose-envify "^1.1.0"
14152 - object-assign "^4.1.1"
14153 -
14146 scheduler@^0.13.0:
14147 version "0.13.6"
14148 resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889"