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

Clean up inconsistent naming in Flight implementation #26356

Closed
Closed
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
10 changes: 5 additions & 5 deletions fixtures/flight-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ <h1>Flight Example</h1>
return 'Title';
}

let model = {
let value = {
title: <Title />,
content: <HTML />,
};

let stream = ReactServerDOMServer.renderToReadableStream(model);
let stream = ReactServerDOMServer.renderToReadableStream(value);
let response = new Response(stream, {
headers: {'Content-Type': 'text/html'},
});
Expand All @@ -83,12 +83,12 @@ <h1>Flight Example</h1>
}

function Shell({ data }) {
let model = React.use(data);
let value = React.use(data);
return <div>
<Suspense fallback="...">
<h1>{model.title}</h1>
<h1>{value.title}</h1>
</Suspense>
{model.content}
{value.content}
</div>;
}

Expand Down
6 changes: 3 additions & 3 deletions fixtures/flight/server/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ app.all('/', async function (req, res, next) {
virtualFs = fs;
buildPath = path.join(__dirname, '../build/');
}
// Read the module map from the virtual file system.
const moduleMap = JSON.parse(
// Read the SSR manifest from the virtual file system.
const ssrManifest = JSON.parse(
await virtualFs.readFile(
path.join(buildPath, 'react-ssr-manifest.json'),
'utf8'
Expand All @@ -140,7 +140,7 @@ app.all('/', async function (req, res, next) {
// For HTML, we're a "client" emulator that runs the client code,
// so we start by consuming the RSC payload. This needs a module
// map that reverse engineers the client-side path to the SSR path.
const root = await createFromNodeStream(rscResponse, moduleMap);
const root = await createFromNodeStream(rscResponse, ssrManifest);
// Render it into HTML by resolving the client components
res.set('Content-type', 'text/html');
const {pipe} = renderToPipeableStream(root, {
Expand Down
12 changes: 6 additions & 6 deletions fixtures/flight/server/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ app.get('/', async function (req, res) {
// const m = require('../src/App.js');
const m = await import('../src/App.js');

let moduleMap;
let clientManifest;
let mainCSSChunks;
if (process.env.NODE_ENV === 'development') {
// Read the module map from the HMR server in development.
moduleMap = await (
// Read the client manifest from the HMR server in development.
clientManifest = await (
await fetch('http://localhost:3000/react-client-manifest.json')
).json();
mainCSSChunks = (
Expand All @@ -65,8 +65,8 @@ app.get('/', async function (req, res) {
).json()
).main.css;
} else {
// Read the module map from the static build in production.
moduleMap = JSON.parse(
// Read the client manifest from the static build in production.
clientManifest = JSON.parse(
await readFile(
path.resolve(__dirname, `../build/react-client-manifest.json`),
'utf8'
Expand All @@ -91,7 +91,7 @@ app.get('/', async function (req, res) {
),
React.createElement(App),
];
const {pipe} = renderToPipeableStream(root, moduleMap);
const {pipe} = renderToPipeableStream(root, clientManifest);
pipe(res);
});

Expand Down
108 changes: 54 additions & 54 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {LazyComponent} from 'react/src/ReactLazy';
import type {
ClientReference,
ClientReferenceMetadata,
UninitializedModel,
UninitializedValue,
Response,
SSRManifest,
} from './ReactFlightClientHostConfig';
Expand All @@ -22,7 +22,7 @@ import {
resolveClientReference,
preloadModule,
requireModule,
parseModel,
parseJSONValue,
} from './ReactFlightClientHostConfig';

import {knownServerReferences} from './ReactFlightServerReferenceRegistry';
Expand All @@ -43,7 +43,7 @@ export type JSONValue =

const PENDING = 'pending';
const BLOCKED = 'blocked';
const RESOLVED_MODEL = 'resolved_model';
const RESOLVED_JSON_VALUE = 'resolved_json_value';
const RESOLVED_MODULE = 'resolved_module';
const INITIALIZED = 'fulfilled';
const ERRORED = 'rejected';
Expand All @@ -62,9 +62,9 @@ type BlockedChunk<T> = {
_response: Response,
then(resolve: (T) => mixed, reject: (mixed) => mixed): void,
};
type ResolvedModelChunk<T> = {
status: 'resolved_model',
value: UninitializedModel,
type ResolvedJSONValueChunk<T> = {
status: 'resolved_json_value',
value: UninitializedValue,
reason: null,
_response: Response,
then(resolve: (T) => mixed, reject: (mixed) => mixed): void,
Expand Down Expand Up @@ -93,7 +93,7 @@ type ErroredChunk<T> = {
type SomeChunk<T> =
| PendingChunk<T>
| BlockedChunk<T>
| ResolvedModelChunk<T>
| ResolvedJSONValueChunk<T>
| ResolvedModuleChunk<T>
| InitializedChunk<T>
| ErroredChunk<T>;
Expand All @@ -117,8 +117,8 @@ Chunk.prototype.then = function <T>(
// If we have resolved content, we try to initialize it first which
// might put us back into one of the other states.
switch (chunk.status) {
case RESOLVED_MODEL:
initializeModelChunk(chunk);
case RESOLVED_JSON_VALUE:
initializeJSONValueChunk(chunk);
break;
case RESOLVED_MODULE:
initializeModuleChunk(chunk);
Expand Down Expand Up @@ -151,7 +151,7 @@ Chunk.prototype.then = function <T>(
};

export type ResponseBase = {
_bundlerConfig: SSRManifest,
_ssrManifest: SSRManifest,
_callServer: CallServerCallback,
_chunks: Map<number, SomeChunk<any>>,
...
Expand All @@ -163,8 +163,8 @@ function readChunk<T>(chunk: SomeChunk<T>): T {
// If we have resolved content, we try to initialize it first which
// might put us back into one of the other states.
switch (chunk.status) {
case RESOLVED_MODEL:
initializeModelChunk(chunk);
case RESOLVED_JSON_VALUE:
initializeJSONValueChunk(chunk);
break;
case RESOLVED_MODULE:
initializeModuleChunk(chunk);
Expand Down Expand Up @@ -249,12 +249,12 @@ function triggerErrorOnChunk<T>(chunk: SomeChunk<T>, error: mixed): void {
}
}

function createResolvedModelChunk<T>(
function createResolvedJSONValueChunk<T>(
response: Response,
value: UninitializedModel,
): ResolvedModelChunk<T> {
value: UninitializedValue,
): ResolvedJSONValueChunk<T> {
// $FlowFixMe Flow doesn't support functions as constructors
return new Chunk(RESOLVED_MODEL, value, null, response);
return new Chunk(RESOLVED_JSON_VALUE, value, null, response);
}

function createResolvedModuleChunk<T>(
Expand All @@ -265,24 +265,24 @@ function createResolvedModuleChunk<T>(
return new Chunk(RESOLVED_MODULE, value, null, response);
}

function resolveModelChunk<T>(
function resolveJSONValueChunk<T>(
chunk: SomeChunk<T>,
value: UninitializedModel,
value: UninitializedValue,
): void {
if (chunk.status !== PENDING) {
// We already resolved. We didn't expect to see this.
return;
}
const resolveListeners = chunk.value;
const rejectListeners = chunk.reason;
const resolvedChunk: ResolvedModelChunk<T> = (chunk: any);
resolvedChunk.status = RESOLVED_MODEL;
const resolvedChunk: ResolvedJSONValueChunk<T> = (chunk: any);
resolvedChunk.status = RESOLVED_JSON_VALUE;
resolvedChunk.value = value;
if (resolveListeners !== null) {
// This is unfortunate that we're reading this eagerly if
// we already have listeners attached since they might no
// longer be rendered or might not be the highest pri.
initializeModelChunk(resolvedChunk);
initializeJSONValueChunk(resolvedChunk);
// The status might have changed after initialization.
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
}
Expand All @@ -307,20 +307,20 @@ function resolveModuleChunk<T>(
}
}

let initializingChunk: ResolvedModelChunk<any> = (null: any);
let initializingChunkBlockedModel: null | {deps: number, value: any} = null;
function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
let initializingChunk: ResolvedJSONValueChunk<any> = (null: any);
let initializingChunkBlockedValue: null | {deps: number, value: any} = null;
function initializeJSONValueChunk<T>(chunk: ResolvedJSONValueChunk<T>): void {
const prevChunk = initializingChunk;
const prevBlocked = initializingChunkBlockedModel;
const prevBlocked = initializingChunkBlockedValue;
initializingChunk = chunk;
initializingChunkBlockedModel = null;
initializingChunkBlockedValue = null;
try {
const value: T = parseModel(chunk._response, chunk.value);
const value: T = parseJSONValue(chunk._response, chunk.value);
if (
initializingChunkBlockedModel !== null &&
initializingChunkBlockedModel.deps > 0
initializingChunkBlockedValue !== null &&
initializingChunkBlockedValue.deps > 0
) {
initializingChunkBlockedModel.value = value;
initializingChunkBlockedValue.value = value;
// We discovered new dependencies on modules that are not yet resolved.
// We have to go the BLOCKED state until they're resolved.
const blockedChunk: BlockedChunk<T> = (chunk: any);
Expand All @@ -338,7 +338,7 @@ function initializeModelChunk<T>(chunk: ResolvedModelChunk<T>): void {
erroredChunk.reason = error;
} finally {
initializingChunk = prevChunk;
initializingChunkBlockedModel = prevBlocked;
initializingChunkBlockedValue = prevBlocked;
}
}

Expand Down Expand Up @@ -436,17 +436,17 @@ function getChunk(response: Response, id: number): SomeChunk<any> {
return chunk;
}

function createModelResolver<T>(
function createValueResolver<T>(
chunk: SomeChunk<T>,
parentObject: Object,
key: string,
): (value: any) => void {
let blocked;
if (initializingChunkBlockedModel) {
blocked = initializingChunkBlockedModel;
if (initializingChunkBlockedValue) {
blocked = initializingChunkBlockedValue;
blocked.deps++;
} else {
blocked = initializingChunkBlockedModel = {
blocked = initializingChunkBlockedValue = {
deps: 1,
value: null,
};
Expand All @@ -469,7 +469,7 @@ function createModelResolver<T>(
};
}

function createModelReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
function createValueReject<T>(chunk: SomeChunk<T>): (error: mixed) => void {
return (error: mixed) => triggerErrorOnChunk(chunk, error);
}

Expand Down Expand Up @@ -501,7 +501,7 @@ function createServerReferenceProxy<A: Iterable<any>, T>(
return proxy;
}

export function parseModelString(
export function parseJSONValueString(
response: Response,
parentObject: Object,
key: string,
Expand Down Expand Up @@ -544,8 +544,8 @@ export function parseModelString(
const id = parseInt(value.substring(2), 16);
const chunk = getChunk(response, id);
switch (chunk.status) {
case RESOLVED_MODEL:
initializeModelChunk(chunk);
case RESOLVED_JSON_VALUE:
initializeJSONValueChunk(chunk);
break;
}
// The status might have changed after initialization.
Expand All @@ -569,8 +569,8 @@ export function parseModelString(
const id = parseInt(value.substring(1), 16);
const chunk = getChunk(response, id);
switch (chunk.status) {
case RESOLVED_MODEL:
initializeModelChunk(chunk);
case RESOLVED_JSON_VALUE:
initializeJSONValueChunk(chunk);
break;
case RESOLVED_MODULE:
initializeModuleChunk(chunk);
Expand All @@ -584,8 +584,8 @@ export function parseModelString(
case BLOCKED:
const parentChunk = initializingChunk;
chunk.then(
createModelResolver(parentChunk, parentObject, key),
createModelReject(parentChunk),
createValueResolver(parentChunk, parentObject, key),
createValueReject(parentChunk),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be either createValueResolver/createValueRejecter or createValueResolve/createValueReject.

);
return null;
default:
Expand All @@ -597,7 +597,7 @@ export function parseModelString(
return value;
}

export function parseModelTuple(
export function parseJSONValueTuple(
response: Response,
value: {+[key: string]: JSONValue} | $ReadOnlyArray<JSONValue>,
): any {
Expand All @@ -619,45 +619,45 @@ function missingCall() {
}

export function createResponse(
bundlerConfig: SSRManifest,
ssrManifest: SSRManifest,
callServer: void | CallServerCallback,
): ResponseBase {
const chunks: Map<number, SomeChunk<any>> = new Map();
const response = {
_bundlerConfig: bundlerConfig,
_ssrManifest: ssrManifest,
_callServer: callServer !== undefined ? callServer : missingCall,
_chunks: chunks,
};
return response;
}

export function resolveModel(
export function resolveJSONValue(
response: Response,
id: number,
model: UninitializedModel,
value: UninitializedValue,
): void {
const chunks = response._chunks;
const chunk = chunks.get(id);
if (!chunk) {
chunks.set(id, createResolvedModelChunk(response, model));
chunks.set(id, createResolvedJSONValueChunk(response, value));
} else {
resolveModelChunk(chunk, model);
resolveJSONValueChunk(chunk, value);
}
}

export function resolveModule(
response: Response,
id: number,
model: UninitializedModel,
value: UninitializedValue,
): void {
const chunks = response._chunks;
const chunk = chunks.get(id);
const clientReferenceMetadata: ClientReferenceMetadata = parseModel(
const clientReferenceMetadata: ClientReferenceMetadata = parseJSONValue(
response,
model,
value,
);
const clientReference = resolveClientReference<$FlowFixMe>(
response._bundlerConfig,
response._ssrManifest,
clientReferenceMetadata,
);

Expand Down
Loading