main
js 114 lines 3.46 KB
Raw
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 {Request} from 'react-server/src/ReactFlightServer';
11 import type {ReactComponentInfo} from 'shared/ReactTypes';
12 import type {ReactClientValue} from 'react-server/src/ReactFlightServer';
13
14 export type HintCode = string;
15 export type HintModel<T: HintCode> = null; // eslint-disable-line no-unused-vars
16 export type Hints = null;
17
18 export function createHints(): Hints {
19 return null;
20 }
21
22 export type FormatContext = null;
23
24 export function createRootFormatContext(): FormatContext {
25 return null;
26 }
27
28 export function getChildFormatContext(
29 parentContext: FormatContext,
30 type: string,
31 props: Object,
32 ): FormatContext {
33 return parentContext;
34 }
35
36 export const supportsRequestStorage = false;
37 export const requestStorage: AsyncLocalStorage<Request | void> = null as any;
38
39 export const supportsComponentStorage = false;
40 export const componentStorage: AsyncLocalStorage<ReactComponentInfo | void> =
41 null as any;
42
43 export * from '../ReactFlightServerConfigDebugNoop';
44
45 export * from '../ReactFlightStackConfigV8';
46 export * from '../ReactServerConsoleConfigPlain';
47
48 export type ClientManifest = null;
49 export opaque type ClientReference<T> = null; // eslint-disable-line no-unused-vars
50 export opaque type ServerReference<T> = null; // eslint-disable-line no-unused-vars
51 export opaque type ClientReferenceMetadata: any = null;
52 export opaque type ServerReferenceId: string = string;
53 export opaque type ClientReferenceKey: any = string;
54
55 const CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
56 const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
57
58 export function isClientReference(reference: Object): boolean {
59 return reference.$$typeof === CLIENT_REFERENCE_TAG;
60 }
61
62 export function isServerReference(reference: Object): boolean {
63 return reference.$$typeof === SERVER_REFERENCE_TAG;
64 }
65
66 export function getClientReferenceKey(
67 reference: ClientReference<any>,
68 ): ClientReferenceKey {
69 throw new Error(
70 'Attempted to render a Client Component from renderToHTML. ' +
71 'This is not supported since it will never hydrate. ' +
72 'Only render Server Components with renderToHTML.',
73 );
74 }
75
76 export function resolveClientReferenceMetadata<T>(
77 config: ClientManifest,
78 clientReference: ClientReference<T>,
79 ): ClientReferenceMetadata {
80 throw new Error(
81 'Attempted to render a Client Component from renderToHTML. ' +
82 'This is not supported since it will never hydrate. ' +
83 'Only render Server Components with renderToHTML.',
84 );
85 }
86
87 export function getServerReferenceId<T>(
88 config: ClientManifest,
89 serverReference: ServerReference<T>,
90 ): ServerReferenceId {
91 throw new Error(
92 'Attempted to render a Server Action from renderToHTML. ' +
93 'This is not supported since it varies by version of the app. ' +
94 'Use a fixed URL for any forms instead.',
95 );
96 }
97
98 export function getServerReferenceBoundArguments<T>(
99 config: ClientManifest,
100 serverReference: ServerReference<T>,
101 ): null | Array<ReactClientValue> {
102 throw new Error(
103 'Attempted to render a Server Action from renderToHTML. ' +
104 'This is not supported since it varies by version of the app. ' +
105 'Use a fixed URL for any forms instead.',
106 );
107 }
108
109 export function getServerReferenceLocation<T>(
110 config: ClientManifest,
111 serverReference: ServerReference<T>,
112 ): void {
113 return undefined;
114 }