mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
2153a29661
Currently, only the browser build exposes the `$$FORM_ACTION` helper. It's used for creating progressive enhancement fro Server Actions imported from Client Components. This helper is only useful in SSR builds so it should be included in the Edge/Node builds of the client. I also removed it from the browser build. We assume that only the Edge or Node builds of the client are used together with SSR. On the client this feature is not needed so we can exclude the code. This might be a bit unnecessary because it's not that much code and in theory you might use SSR in a Service Worker or something where the Browser build would be used but currently we assume that build is only for the client. That's why it also don't take an option for reverse look up of file names.
59 lines
1.5 KiB
JavaScript
59 lines
1.5 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
|
|
*/
|
|
|
|
import type {Thenable} from 'shared/ReactTypes.js';
|
|
|
|
import type {Response} from 'react-client/src/ReactFlightClient';
|
|
|
|
import type {SSRManifest} from 'react-client/src/ReactFlightClientConfig';
|
|
|
|
import type {Readable} from 'stream';
|
|
|
|
import {
|
|
createResponse,
|
|
getRoot,
|
|
reportGlobalError,
|
|
processBinaryChunk,
|
|
close,
|
|
} from 'react-client/src/ReactFlightClient';
|
|
|
|
import {createServerReference as createServerReferenceImpl} from 'react-client/src/ReactFlightReplyClient';
|
|
|
|
function noServerCall() {
|
|
throw new Error(
|
|
'Server Functions cannot be called during initial render. ' +
|
|
'This would create a fetch waterfall. Try to use a Server Component ' +
|
|
'to pass data to Client Components instead.',
|
|
);
|
|
}
|
|
|
|
export function createServerReference<A: Iterable<any>, T>(
|
|
id: any,
|
|
callServer: any,
|
|
): (...A) => Promise<T> {
|
|
return createServerReferenceImpl(id, noServerCall);
|
|
}
|
|
|
|
function createFromNodeStream<T>(
|
|
stream: Readable,
|
|
moduleMap: $NonMaybeType<SSRManifest>,
|
|
): Thenable<T> {
|
|
const response: Response = createResponse(moduleMap, noServerCall);
|
|
stream.on('data', chunk => {
|
|
processBinaryChunk(response, chunk);
|
|
});
|
|
stream.on('error', error => {
|
|
reportGlobalError(response, error);
|
|
});
|
|
stream.on('end', () => close(response));
|
|
return getRoot(response);
|
|
}
|
|
|
|
export {createFromNodeStream};
|