Skip to content

Commit

Permalink
Rename SSRManifest to ServerConsumerManifest (#31299)
Browse files Browse the repository at this point in the history
This config is more generally applicable to all server-side Flight
Clients and not just SSR.
  • Loading branch information
sebmarkbage authored Oct 20, 2024
1 parent 1839e14 commit 39a7730
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 100 deletions.
12 changes: 9 additions & 3 deletions fixtures/flight/server/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function renderApp(req, res, next) {
buildPath = path.join(__dirname, '../build/');
}
// Read the module map from the virtual file system.
const ssrManifest = JSON.parse(
const serverConsumerManifest = JSON.parse(
await virtualFs.readFile(
path.join(buildPath, 'react-ssr-manifest.json'),
'utf8'
Expand Down Expand Up @@ -160,14 +160,20 @@ async function renderApp(req, res, next) {
rscResponse.pipe(rscResponse1);
rscResponse.pipe(rscResponse2);

const {formState} = await createFromNodeStream(rscResponse1, ssrManifest);
const {formState} = await createFromNodeStream(
rscResponse1,
serverConsumerManifest
);
rscResponse1.end();

let cachedResult;
let Root = () => {
if (!cachedResult) {
// Read this stream inside the render.
cachedResult = createFromNodeStream(rscResponse2, ssrManifest);
cachedResult = createFromNodeStream(
rscResponse2,
serverConsumerManifest
);
}
return React.use(cachedResult).root;
};
Expand Down
8 changes: 4 additions & 4 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {LazyComponent} from 'react/src/ReactLazy';
import type {
ClientReference,
ClientReferenceMetadata,
SSRModuleMap,
ServerConsumerModuleMap,
StringDecoder,
ModuleLoading,
} from './ReactFlightClientConfig';
Expand Down Expand Up @@ -269,7 +269,7 @@ export type FindSourceMapURLCallback = (
) => null | string;

export type Response = {
_bundlerConfig: SSRModuleMap,
_bundlerConfig: ServerConsumerModuleMap,
_moduleLoading: ModuleLoading,
_callServer: CallServerCallback,
_encodeFormAction: void | EncodeFormActionCallback,
Expand Down Expand Up @@ -1420,7 +1420,7 @@ function missingCall() {

function ResponseInstance(
this: $FlowFixMe,
bundlerConfig: SSRModuleMap,
bundlerConfig: ServerConsumerModuleMap,
moduleLoading: ModuleLoading,
callServer: void | CallServerCallback,
encodeFormAction: void | EncodeFormActionCallback,
Expand Down Expand Up @@ -1485,7 +1485,7 @@ function ResponseInstance(
}

export function createResponse(
bundlerConfig: SSRModuleMap,
bundlerConfig: ServerConsumerModuleMap,
moduleLoading: ModuleLoading,
callServer: void | CallServerCallback,
encodeFormAction: void | EncodeFormActionCallback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
declare const $$$config: any;

export opaque type ModuleLoading = mixed;
export opaque type SSRModuleMap = mixed;
export opaque type ServerConsumerModuleMap = mixed;
export opaque type ServerManifest = mixed;
export opaque type ServerReferenceId = string;
export opaque type ClientReferenceMetadata = mixed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export * from 'react-client/src/ReactClientConsoleConfigPlain';
export * from 'react-dom-bindings/src/shared/ReactFlightClientConfigDOM';

export opaque type ModuleLoading = mixed;
export opaque type SSRModuleMap = mixed;
export opaque type ServerConsumerModuleMap = mixed;
export opaque type ServerManifest = mixed;
export opaque type ServerReferenceId = string;
export opaque type ClientReferenceMetadata = mixed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export * from 'react-client/src/ReactClientConsoleConfigBrowser';

export type Response = any;
export opaque type ModuleLoading = mixed;
export opaque type SSRModuleMap = mixed;
export opaque type ServerConsumerModuleMap = mixed;
export opaque type ServerManifest = mixed;
export opaque type ServerReferenceId = string;
export opaque type ClientReferenceMetadata = mixed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export * from 'react-markup/src/ReactMarkupLegacyClientStreamConfig.js';
export * from 'react-client/src/ReactClientConsoleConfigPlain';

export type ModuleLoading = null;
export type SSRModuleMap = null;
export type ServerConsumerModuleMap = null;
export opaque type ServerManifest = null;
export opaque type ServerReferenceId = string;
export opaque type ClientReferenceMetadata = null;
Expand All @@ -33,7 +33,7 @@ export function prepareDestinationForModule(
}

export function resolveClientReference<T>(
bundlerConfig: SSRModuleMap,
bundlerConfig: ServerConsumerModuleMap,
metadata: ClientReferenceMetadata,
): ClientReference<T> {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
} from 'shared/ReactTypes';
import type {ModuleLoading} from 'react-client/src/ReactFlightClientConfig';

export type SSRModuleMap = string; // Module root path
export type ServerConsumerModuleMap = string; // Module root path

export type ServerManifest = string; // Module root path

Expand Down Expand Up @@ -48,7 +48,7 @@ export function prepareDestinationForModule(
}

export function resolveClientReference<T>(
bundlerConfig: SSRModuleMap,
bundlerConfig: ServerConsumerModuleMap,
metadata: ClientReferenceMetadata,
): ClientReference<T> {
const baseURL = bundlerConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('ReactFlightTurbopackDOMEdge', () => {
turbopackMap,
);
const response = ReactServerDOMClient.createFromReadableStream(stream, {
ssrManifest: {
serverManifest: {
moduleMap: translationMap,
moduleLoading: null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '../shared/ReactFlightImportMetadata';
import {prepareDestinationWithChunks} from 'react-client/src/ReactFlightClientConfig';

export type SSRModuleMap = {
export type ServerConsumerModuleMap = {
[clientId: string]: {
[clientExportName: string]: ClientReference<any>,
},
Expand Down Expand Up @@ -58,7 +58,7 @@ export function prepareDestinationForModule(
}

export function resolveClientReference<T>(
bundlerConfig: SSRModuleMap,
bundlerConfig: ServerConsumerModuleMap,
metadata: ClientReferenceMetadata,
): ClientReference<T> {
const moduleExports = bundlerConfig[metadata[ID]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {prepareDestinationWithChunks} from 'react-client/src/ReactFlightClientCo

import {loadChunk} from 'react-client/src/ReactFlightClientConfig';

export type SSRModuleMap = null | {
export type ServerConsumerModuleMap = null | {
[clientId: string]: {
[clientExportName: string]: ClientReferenceManifestEntry,
},
Expand Down Expand Up @@ -63,7 +63,7 @@ export function prepareDestinationForModule(
}

export function resolveClientReference<T>(
bundlerConfig: SSRModuleMap,
bundlerConfig: ServerConsumerModuleMap,
metadata: ClientReferenceMetadata,
): ClientReference<T> {
if (bundlerConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import type {
import type {ReactServerValue} from 'react-client/src/ReactFlightReplyClient';

import type {
SSRModuleMap,
ServerConsumerModuleMap,
ModuleLoading,
} from 'react-client/src/ReactFlightClientConfig';

type SSRManifest = {
moduleMap: SSRModuleMap,
type ServerConsumerManifest = {
moduleMap: ServerConsumerModuleMap,
moduleLoading: ModuleLoading,
};

Expand Down Expand Up @@ -66,7 +66,7 @@ type EncodeFormActionCallback = <A>(
) => ReactCustomFormAction;

export type Options = {
ssrManifest: SSRManifest,
serverManifest: ServerConsumerManifest,
nonce?: string,
encodeFormAction?: EncodeFormActionCallback,
temporaryReferences?: TemporaryReferenceSet,
Expand All @@ -77,8 +77,8 @@ export type Options = {

function createResponseFromOptions(options: Options) {
return createResponse(
options.ssrManifest.moduleMap,
options.ssrManifest.moduleLoading,
options.serverManifest.moduleMap,
options.serverManifest.moduleLoading,
noServerCall,
options.encodeFormAction,
typeof options.nonce === 'string' ? options.nonce : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import type {
} from 'react-client/src/ReactFlightClient';

import type {
SSRModuleMap,
ServerConsumerModuleMap,
ModuleLoading,
} from 'react-client/src/ReactFlightClientConfig';

type SSRManifest = {
moduleMap: SSRModuleMap,
type ServerConsumerManifest = {
moduleMap: ServerConsumerModuleMap,
moduleLoading: ModuleLoading,
};

Expand Down Expand Up @@ -66,12 +66,12 @@ export type Options = {

function createFromNodeStream<T>(
stream: Readable,
ssrManifest: SSRManifest,
serverConsumerManifest: ServerConsumerManifest,
options?: Options,
): Thenable<T> {
const response: Response = createResponse(
ssrManifest.moduleMap,
ssrManifest.moduleLoading,
serverConsumerManifest.moduleMap,
serverConsumerManifest.moduleLoading,
noServerCall,
options ? options.encodeFormAction : undefined,
options && typeof options.nonce === 'string' ? options.nonce : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Options = {
clientReferences?: ClientReferencePath | $ReadOnlyArray<ClientReferencePath>,
chunkName?: string,
clientManifestFilename?: string,
ssrManifestFilename?: string,
serverConsumerManifestFilename?: string,
};

const PLUGIN_NAME = 'React Server Plugin';
Expand All @@ -67,7 +67,7 @@ export default class ReactFlightWebpackPlugin {
clientReferences: $ReadOnlyArray<ClientReferencePath>;
chunkName: string;
clientManifestFilename: string;
ssrManifestFilename: string;
serverConsumerManifestFilename: string;

constructor(options: Options) {
if (!options || typeof options.isServer !== 'boolean') {
Expand Down Expand Up @@ -105,8 +105,8 @@ export default class ReactFlightWebpackPlugin {
}
this.clientManifestFilename =
options.clientManifestFilename || 'react-client-manifest.json';
this.ssrManifestFilename =
options.ssrManifestFilename || 'react-ssr-manifest.json';
this.serverConsumerManifestFilename =
options.serverConsumerManifestFilename || 'react-ssr-manifest.json';
}

apply(compiler: any) {
Expand Down Expand Up @@ -239,18 +239,18 @@ export default class ReactFlightWebpackPlugin {
const clientManifest: {
[string]: ImportManifestEntry,
} = {};
type SSRModuleMap = {
type ServerConsumerModuleMap = {
[string]: {
[string]: {specifier: string, name: string},
},
};
const moduleMap: SSRModuleMap = {};
const moduleMap: ServerConsumerModuleMap = {};
const ssrBundleConfig: {
moduleLoading: {
prefix: string,
crossOrigin: string | null,
},
moduleMap: SSRModuleMap,
moduleMap: ServerConsumerModuleMap,
} = {
moduleLoading: {
prefix: compilation.outputOptions.publicPath || '',
Expand Down Expand Up @@ -374,7 +374,7 @@ export default class ReactFlightWebpackPlugin {
);
const ssrOutput = JSON.stringify(ssrBundleConfig, null, 2);
compilation.emitAsset(
_this.ssrManifestFilename,
_this.serverConsumerManifestFilename,
new sources.RawSource(ssrOutput, false),
);
},
Expand Down
Loading

0 comments on commit 39a7730

Please sign in to comment.