mirror of
https://github.com/facebook/react.git
synced 2026-02-24 12:43:00 +00:00
A while back we implemented a heuristic that if a chunk was large it was assumed to be produced by the render and thus was safe to stream which results in transferring the underlying object memory. Later we ran into an issue where a precomputed chunk grew large enough to trigger this hueristic and it started causing renders to fail because once a second render had occurred the precomputed chunk would not have an underlying buffer of bytes to send and these bytes would be omitted from the stream. We implemented a technique to detect large precomputed chunks and we enforced that these always be cloned before writing. Unfortunately our test coverage was not perfect and there has been for a very long time now a usage pattern where if you complete a boundary in one flush and then complete a boundary that has stylehsheet dependencies in another flush you can get a large precomputed chunk that was not being cloned to be sent twice causing streaming errors. I've thought about why we even went with this solution in the first place and I think it was a mistake. It relies on a dev only check to catch paired with potentially version specific order of operations on the streaming side. This is too unreliable. Additionally the low limit of view size for Edge is not used in Node.js but there is not real justification for this. In this change I updated the view size for edge streaming to match Node at 2048 bytes which is still relatively small and we have no data one way or another to preference 512 over this. Then I updated the assertion logic to error anytime a precomputed chunk exceeds the size. This eliminates the need to clone these chunks by just making sure our view size is always larger than the largest precomputed chunk we can possibly write. I'm generally in favor of this for a few reasons. First, we'll always know during testing whether we've violated the limit as long as we exercise each stream config because the precomputed chunks are created in module scope. Second, we can always split up large chunks so making sure the precomptued chunk is smaller than whatever view size we actually desire is relatively trivial.
78 lines
1.9 KiB
JavaScript
78 lines
1.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
|
|
*/
|
|
|
|
export type Destination = {
|
|
buffer: string,
|
|
done: boolean,
|
|
fatal: boolean,
|
|
error: mixed,
|
|
};
|
|
|
|
export opaque type PrecomputedChunk = string;
|
|
export opaque type Chunk = string;
|
|
export opaque type BinaryChunk = string;
|
|
|
|
export function flushBuffered(destination: Destination) {}
|
|
|
|
export const supportsRequestStorage = false;
|
|
export const requestStorage: AsyncLocalStorage<Request | void> = (null: any);
|
|
|
|
export function beginWriting(destination: Destination) {}
|
|
|
|
export function writeChunk(
|
|
destination: Destination,
|
|
chunk: Chunk | PrecomputedChunk | BinaryChunk,
|
|
): void {
|
|
destination.buffer += chunk;
|
|
}
|
|
|
|
export function writeChunkAndReturn(
|
|
destination: Destination,
|
|
chunk: Chunk | PrecomputedChunk | BinaryChunk,
|
|
): boolean {
|
|
destination.buffer += chunk;
|
|
return true;
|
|
}
|
|
|
|
export function completeWriting(destination: Destination) {}
|
|
|
|
export function close(destination: Destination) {
|
|
destination.done = true;
|
|
}
|
|
|
|
export function stringToChunk(content: string): Chunk {
|
|
return content;
|
|
}
|
|
|
|
export function stringToPrecomputedChunk(content: string): PrecomputedChunk {
|
|
return content;
|
|
}
|
|
|
|
export function typedArrayToBinaryChunk(
|
|
content: $ArrayBufferView,
|
|
): BinaryChunk {
|
|
throw new Error('Not implemented.');
|
|
}
|
|
|
|
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
|
|
throw new Error('Not implemented.');
|
|
}
|
|
|
|
export function byteLengthOfBinaryChunk(chunk: BinaryChunk): number {
|
|
throw new Error('Not implemented.');
|
|
}
|
|
|
|
export function closeWithError(destination: Destination, error: mixed): void {
|
|
destination.done = true;
|
|
destination.fatal = true;
|
|
destination.error = error;
|
|
}
|
|
|
|
export {createFastHashJS as createFastHash} from './createFastHashJS';
|