mirror of
https://github.com/facebook/react.git
synced 2026-02-23 20:23:02 +00:00
This renames Module References to Client References, since they are in the server->client direction. I also changed the Proxies exposed from the `node-register` loader to provide better error messages. Ideally, some of this should be replicated in the ESM loader too but neither are the source of truth. We'll replicate this in the static form in the Next.js loaders. cc @huozhi @shuding - All references are now functions so that when you call them on the server, we can yield a better error message. - References that are themselves already referring to an export name are now proxies that error when you dot into them. - `use(...)` can now be used on a client reference to unwrap it server side and then pass a reference to the awaited value.
103 lines
2.9 KiB
JavaScript
103 lines
2.9 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
type JSONValue =
|
|
| string
|
|
| boolean
|
|
| number
|
|
| null
|
|
| {+[key: string]: JSONValue}
|
|
| $ReadOnlyArray<JSONValue>;
|
|
|
|
declare module 'JSResourceReference' {
|
|
declare export interface JSResourceReference<T> {
|
|
getModuleId(): string;
|
|
getModuleIdAsRef(): $Flow$ModuleRef<T>;
|
|
getModuleIfRequired(): ?T;
|
|
load(): Promise<T>;
|
|
preload(): void;
|
|
}
|
|
}
|
|
|
|
declare module 'JSResourceReferenceImpl' {
|
|
declare export default class JSResourceReferenceImpl<T> {
|
|
getModuleId(): string;
|
|
getModuleIdAsRef(): $Flow$ModuleRef<T>;
|
|
getModuleIfRequired(): ?T;
|
|
load(): Promise<T>;
|
|
preload(): void;
|
|
}
|
|
}
|
|
|
|
declare module 'ReactFlightDOMRelayServerIntegration' {
|
|
import type {JSResourceReference} from 'JSResourceReference';
|
|
|
|
declare export opaque type Destination;
|
|
declare export opaque type BundlerConfig;
|
|
declare export function emitRow(
|
|
destination: Destination,
|
|
json: JSONValue,
|
|
): void;
|
|
declare export function close(destination: Destination): void;
|
|
|
|
declare export type ModuleMetaData = JSONValue;
|
|
declare export function resolveModuleMetaData<T>(
|
|
config: BundlerConfig,
|
|
resourceReference: JSResourceReference<T>,
|
|
): ModuleMetaData;
|
|
}
|
|
|
|
declare module 'ReactFlightDOMRelayClientIntegration' {
|
|
import type {JSResourceReference} from 'JSResourceReference';
|
|
|
|
declare export opaque type ModuleMetaData;
|
|
declare export function resolveClientReference<T>(
|
|
moduleData: ModuleMetaData,
|
|
): JSResourceReference<T>;
|
|
declare export function preloadModule<T>(
|
|
moduleReference: JSResourceReference<T>,
|
|
): null | Promise<void>;
|
|
declare export function requireModule<T>(
|
|
moduleReference: JSResourceReference<T>,
|
|
): T;
|
|
}
|
|
|
|
declare module 'ReactFlightNativeRelayServerIntegration' {
|
|
import type {JSResourceReference} from 'JSResourceReference';
|
|
|
|
declare export opaque type Destination;
|
|
declare export opaque type BundlerConfig;
|
|
declare export function emitRow(
|
|
destination: Destination,
|
|
json: JSONValue,
|
|
): void;
|
|
declare export function close(destination: Destination): void;
|
|
|
|
declare export type ModuleMetaData = JSONValue;
|
|
declare export function resolveModuleMetaData<T>(
|
|
config: BundlerConfig,
|
|
resourceReference: JSResourceReference<T>,
|
|
): ModuleMetaData;
|
|
}
|
|
|
|
declare module 'ReactFlightNativeRelayClientIntegration' {
|
|
import type {JSResourceReference} from 'JSResourceReference';
|
|
|
|
declare export opaque type ModuleMetaData;
|
|
declare export function resolveClientReference<T>(
|
|
moduleData: ModuleMetaData,
|
|
): JSResourceReference<T>;
|
|
declare export function preloadModule<T>(
|
|
moduleReference: JSResourceReference<T>,
|
|
): null | Promise<void>;
|
|
declare export function requireModule<T>(
|
|
moduleReference: JSResourceReference<T>,
|
|
): T;
|
|
}
|