Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add renderToMarkup for Client Components #30121

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,20 @@
* @flow
*/

import type {Thenable} from 'shared/ReactTypes';
export * from 'react-client/src/ReactFlightClientStreamConfigWeb';
export * from 'react-client/src/ReactClientConsoleConfigBrowser';

export * from 'react-html/src/ReactHTMLLegacyClientStreamConfig.js';
export * from 'react-client/src/ReactClientConsoleConfigPlain';

export type ModuleLoading = null;
export type SSRModuleMap = null;
export opaque type ServerManifest = null;
export type Response = any;
export opaque type ModuleLoading = mixed;
export opaque type SSRModuleMap = mixed;
export opaque type ServerManifest = mixed;
export opaque type ServerReferenceId = string;
export opaque type ClientReferenceMetadata = null;
export opaque type ClientReference<T> = null; // eslint-disable-line no-unused-vars

export function prepareDestinationForModule(
moduleLoading: ModuleLoading,
nonce: ?string,
metadata: ClientReferenceMetadata,
) {
throw new Error(
'renderToMarkup should not have emitted Client References. This is a bug in React.',
);
}

export function resolveClientReference<T>(
bundlerConfig: SSRModuleMap,
metadata: ClientReferenceMetadata,
): ClientReference<T> {
throw new Error(
'renderToMarkup should not have emitted Client References. This is a bug in React.',
);
}

export function resolveServerReference<T>(
config: ServerManifest,
id: ServerReferenceId,
): ClientReference<T> {
throw new Error(
'renderToMarkup should not have emitted Server References. This is a bug in React.',
);
}

export function preloadModule<T>(
metadata: ClientReference<T>,
): null | Thenable<T> {
return null;
}

export function requireModule<T>(metadata: ClientReference<T>): T {
throw new Error(
'renderToMarkup should not have emitted Client References. This is a bug in React.',
);
}

export opaque type ClientReferenceMetadata = mixed;
export opaque type ClientReference<T> = mixed; // eslint-disable-line no-unused-vars
export const resolveClientReference: any = null;
export const resolveServerReference: any = null;
export const preloadModule: any = null;
export const requireModule: any = null;
export const dispatchHint: any = null;
export const prepareDestinationForModule: any = null;
export const usedWithSSR = true;

type HintCode = string;
type HintModel<T: HintCode> = null; // eslint-disable-line no-unused-vars

export function dispatchHint<Code: HintCode>(
code: Code,
model: HintModel<Code>,
): void {
// Should never happen.
}

export function preinitModuleForSSR(
href: string,
nonce: ?string,
crossOrigin: ?string,
) {
// Should never happen.
}

export function preinitScriptForSSR(
href: string,
nonce: ?string,
crossOrigin: ?string,
) {
// Should never happen.
}
88 changes: 88 additions & 0 deletions packages/react-client/src/forks/ReactFlightClientConfig.markup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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
*/

import type {Thenable} from 'shared/ReactTypes';

export * from 'react-html/src/ReactHTMLLegacyClientStreamConfig.js';
export * from 'react-client/src/ReactClientConsoleConfigPlain';

export type ModuleLoading = null;
export type SSRModuleMap = null;
export opaque type ServerManifest = null;
export opaque type ServerReferenceId = string;
export opaque type ClientReferenceMetadata = null;
export opaque type ClientReference<T> = null; // eslint-disable-line no-unused-vars

export function prepareDestinationForModule(
moduleLoading: ModuleLoading,
nonce: ?string,
metadata: ClientReferenceMetadata,
) {
throw new Error(
'renderToMarkup should not have emitted Client References. This is a bug in React.',
);
}

export function resolveClientReference<T>(
bundlerConfig: SSRModuleMap,
metadata: ClientReferenceMetadata,
): ClientReference<T> {
throw new Error(
'renderToMarkup should not have emitted Client References. This is a bug in React.',
);
}

export function resolveServerReference<T>(
config: ServerManifest,
id: ServerReferenceId,
): ClientReference<T> {
throw new Error(
'renderToMarkup should not have emitted Server References. This is a bug in React.',
);
}

export function preloadModule<T>(
metadata: ClientReference<T>,
): null | Thenable<T> {
return null;
}

export function requireModule<T>(metadata: ClientReference<T>): T {
throw new Error(
'renderToMarkup should not have emitted Client References. This is a bug in React.',
);
}

export const usedWithSSR = true;

type HintCode = string;
type HintModel<T: HintCode> = null; // eslint-disable-line no-unused-vars

export function dispatchHint<Code: HintCode>(
code: Code,
model: HintModel<Code>,
): void {
// Should never happen.
}

export function preinitModuleForSSR(
href: string,
nonce: ?string,
crossOrigin: ?string,
) {
// Should never happen.
}

export function preinitScriptForSSR(
href: string,
nonce: ?string,
crossOrigin: ?string,
) {
// Should never happen.
}
2 changes: 2 additions & 0 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export type HeadersDescriptor = {
// E.g. this can be used to distinguish legacy renderers from this modern one.
export const isPrimaryRenderer = true;

export const supportsClientAPIs = true;

export type StreamingFormat = 0 | 1;
const ScriptStreamingFormat: StreamingFormat = 0;
const DataStreamingFormat: StreamingFormat = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export {
resetResumableState,
completeResumableState,
emitEarlyPreloads,
supportsClientAPIs,
} from './ReactFizzConfigDOM';

import escapeTextForBrowser from './escapeTextForBrowser';
Expand Down
13 changes: 9 additions & 4 deletions packages/react-html/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';
/**
* 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
*/

throw new Error(
'react-html is not supported outside a React Server Components environment.',
);
export * from './src/ReactHTMLClient';
8 changes: 5 additions & 3 deletions packages/react-html/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

throw new Error(
'react-html is not supported outside a React Server Components environment.'
);
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-html.production.js');
} else {
module.exports = require('./cjs/react-html.development.js');
}
Loading