Skip to content

Commit 1db6222

Browse files
authored
restore next14 sync base branch (facebook#31841)
The original commit for nextjs 14 is 14898b6 but since that was lost in the facebook repo of React when the next nextjs-sync branch was created it is being restored
1 parent 6c3b8db commit 1db6222

File tree

10 files changed

+77
-94
lines changed

10 files changed

+77
-94
lines changed

packages/react-dom-bindings/src/server/ReactDOMLegacyServerStreamConfig.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ export function typedArrayToBinaryChunk(
5858
throw new Error('Not implemented.');
5959
}
6060

61-
export function clonePrecomputedChunk(
62-
chunk: PrecomputedChunk,
63-
): PrecomputedChunk {
64-
return chunk;
65-
}
66-
6761
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
6862
throw new Error('Not implemented.');
6963
}

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
writeChunkAndReturn,
4949
stringToChunk,
5050
stringToPrecomputedChunk,
51-
clonePrecomputedChunk,
5251
} from 'react-server/src/ReactServerStreamConfig';
5352
import {
5453
resolveRequest,
@@ -4227,15 +4226,13 @@ export function writeCompletedBoundaryInstruction(
42274226
) {
42284227
resumableState.instructions |=
42294228
SentStyleInsertionFunction | SentCompleteBoundaryFunction;
4230-
writeChunk(
4231-
destination,
4232-
clonePrecomputedChunk(completeBoundaryWithStylesScript1FullBoth),
4233-
);
4229+
writeChunk(destination, completeBoundaryWithStylesScript1FullBoth);
42344230
} else if (
42354231
(resumableState.instructions & SentStyleInsertionFunction) ===
42364232
NothingSent
42374233
) {
42384234
resumableState.instructions |= SentStyleInsertionFunction;
4235+
42394236
writeChunk(destination, completeBoundaryWithStylesScript1FullPartial);
42404237
} else {
42414238
writeChunk(destination, completeBoundaryWithStylesScript1Partial);

packages/react-dom/src/__tests__/ReactDOMFloat-test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,65 @@ describe('ReactDOMFloat', () => {
731731
).toEqual(['<script src="src-of-external-runtime" async=""></script>']);
732732
});
733733

734+
// @gate enableFloat
735+
it('can send style insertion implementation independent of boundary commpletion instruction implementation', async () => {
736+
await act(() => {
737+
renderToPipeableStream(
738+
<html>
739+
<body>
740+
<Suspense fallback="loading foo...">
741+
<BlockedOn value="foo">foo</BlockedOn>
742+
</Suspense>
743+
<Suspense fallback="loading bar...">
744+
<BlockedOn value="bar">
745+
<link rel="stylesheet" href="bar" precedence="bar" />
746+
bar
747+
</BlockedOn>
748+
</Suspense>
749+
</body>
750+
</html>,
751+
).pipe(writable);
752+
});
753+
754+
expect(getMeaningfulChildren(document)).toEqual(
755+
<html>
756+
<head />
757+
<body>
758+
{'loading foo...'}
759+
{'loading bar...'}
760+
</body>
761+
</html>,
762+
);
763+
764+
await act(() => {
765+
resolveText('foo');
766+
});
767+
expect(getMeaningfulChildren(document)).toEqual(
768+
<html>
769+
<head />
770+
<body>
771+
foo
772+
{'loading bar...'}
773+
</body>
774+
</html>,
775+
);
776+
await act(() => {
777+
resolveText('bar');
778+
});
779+
expect(getMeaningfulChildren(document)).toEqual(
780+
<html>
781+
<head>
782+
<link rel="stylesheet" href="bar" data-precedence="bar" />
783+
</head>
784+
<body>
785+
foo
786+
{'loading bar...'}
787+
<link rel="preload" href="bar" as="style" />
788+
</body>
789+
</html>,
790+
);
791+
});
792+
734793
// @gate enableFloat
735794
it('can avoid inserting a late stylesheet if it already rendered on the client', async () => {
736795
await act(() => {

packages/react-noop-renderer/src/ReactNoopFlightServer.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ const ReactNoopFlightServer = ReactFlightServer({
4646
stringToPrecomputedChunk(content: string): Uint8Array {
4747
return textEncoder.encode(content);
4848
},
49-
clonePrecomputedChunk(chunk: Uint8Array): Uint8Array {
50-
return chunk;
51-
},
5249
isClientReference(reference: Object): boolean {
5350
return reference.$$typeof === Symbol.for('react.client.reference');
5451
},

packages/react-server/src/ReactServerStreamConfigBrowser.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function flushBuffered(destination: Destination) {
2222
// transform streams. https://github.com/whatwg/streams/issues/960
2323
}
2424

25-
const VIEW_SIZE = 512;
25+
const VIEW_SIZE = 2048;
2626
let currentView = null;
2727
let writtenBytes = 0;
2828

@@ -40,15 +40,6 @@ export function writeChunk(
4040
}
4141

4242
if (chunk.byteLength > VIEW_SIZE) {
43-
if (__DEV__) {
44-
if (precomputedChunkSet.has(chunk)) {
45-
console.error(
46-
'A large precomputed chunk was passed to writeChunk without being copied.' +
47-
' Large chunks get enqueued directly and are not copied. This is incompatible with precomputed chunks because you cannot enqueue the same precomputed chunk twice.' +
48-
' Use "cloneChunk" to make a copy of this large precomputed chunk before writing it. This is a bug in React.',
49-
);
50-
}
51-
}
5243
// this chunk may overflow a single view which implies it was not
5344
// one that is cached by the streaming renderer. We will enqueu
5445
// it directly and expect it is not re-used
@@ -120,15 +111,15 @@ export function stringToChunk(content: string): Chunk {
120111
return textEncoder.encode(content);
121112
}
122113

123-
const precomputedChunkSet: Set<Chunk | BinaryChunk> = __DEV__
124-
? new Set()
125-
: (null: any);
126-
127114
export function stringToPrecomputedChunk(content: string): PrecomputedChunk {
128115
const precomputedChunk = textEncoder.encode(content);
129116

130117
if (__DEV__) {
131-
precomputedChunkSet.add(precomputedChunk);
118+
if (precomputedChunk.byteLength > VIEW_SIZE) {
119+
console.error(
120+
'precomputed chunks must be smaller than the view size configured for this host. This is a bug in React.',
121+
);
122+
}
132123
}
133124

134125
return precomputedChunk;
@@ -151,14 +142,6 @@ export function typedArrayToBinaryChunk(
151142
return content.byteLength > VIEW_SIZE ? buffer.slice() : buffer;
152143
}
153144

154-
export function clonePrecomputedChunk(
155-
precomputedChunk: PrecomputedChunk,
156-
): PrecomputedChunk {
157-
return precomputedChunk.byteLength > VIEW_SIZE
158-
? precomputedChunk.slice()
159-
: precomputedChunk;
160-
}
161-
162145
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
163146
return chunk.byteLength;
164147
}

packages/react-server/src/ReactServerStreamConfigBun.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ export function typedArrayToBinaryChunk(
7070
return content;
7171
}
7272

73-
export function clonePrecomputedChunk(
74-
chunk: PrecomputedChunk,
75-
): PrecomputedChunk {
76-
return chunk;
77-
}
78-
7973
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
8074
return Buffer.byteLength(chunk, 'utf8');
8175
}

packages/react-server/src/ReactServerStreamConfigEdge.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function flushBuffered(destination: Destination) {
2222
// transform streams. https://github.com/whatwg/streams/issues/960
2323
}
2424

25-
const VIEW_SIZE = 512;
25+
const VIEW_SIZE = 2048;
2626
let currentView = null;
2727
let writtenBytes = 0;
2828

@@ -40,15 +40,6 @@ export function writeChunk(
4040
}
4141

4242
if (chunk.byteLength > VIEW_SIZE) {
43-
if (__DEV__) {
44-
if (precomputedChunkSet.has(chunk)) {
45-
console.error(
46-
'A large precomputed chunk was passed to writeChunk without being copied.' +
47-
' Large chunks get enqueued directly and are not copied. This is incompatible with precomputed chunks because you cannot enqueue the same precomputed chunk twice.' +
48-
' Use "cloneChunk" to make a copy of this large precomputed chunk before writing it. This is a bug in React.',
49-
);
50-
}
51-
}
5243
// this chunk may overflow a single view which implies it was not
5344
// one that is cached by the streaming renderer. We will enqueu
5445
// it directly and expect it is not re-used
@@ -120,15 +111,15 @@ export function stringToChunk(content: string): Chunk {
120111
return textEncoder.encode(content);
121112
}
122113

123-
const precomputedChunkSet: Set<Chunk | BinaryChunk> = __DEV__
124-
? new Set()
125-
: (null: any);
126-
127114
export function stringToPrecomputedChunk(content: string): PrecomputedChunk {
128115
const precomputedChunk = textEncoder.encode(content);
129116

130117
if (__DEV__) {
131-
precomputedChunkSet.add(precomputedChunk);
118+
if (precomputedChunk.byteLength > VIEW_SIZE) {
119+
console.error(
120+
'precomputed chunks must be smaller than the view size configured for this host. This is a bug in React.',
121+
);
122+
}
132123
}
133124

134125
return precomputedChunk;
@@ -151,14 +142,6 @@ export function typedArrayToBinaryChunk(
151142
return content.byteLength > VIEW_SIZE ? buffer.slice() : buffer;
152143
}
153144

154-
export function clonePrecomputedChunk(
155-
precomputedChunk: PrecomputedChunk,
156-
): PrecomputedChunk {
157-
return precomputedChunk.byteLength > VIEW_SIZE
158-
? precomputedChunk.slice()
159-
: precomputedChunk;
160-
}
161-
162145
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
163146
return chunk.byteLength;
164147
}

packages/react-server/src/ReactServerStreamConfigFB.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ export function typedArrayToBinaryChunk(
6060
throw new Error('Not implemented.');
6161
}
6262

63-
export function clonePrecomputedChunk(
64-
chunk: PrecomputedChunk,
65-
): PrecomputedChunk {
66-
return chunk;
67-
}
68-
6963
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
7064
throw new Error('Not implemented.');
7165
}

packages/react-server/src/ReactServerStreamConfigNode.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ function writeViewChunk(
9999
return;
100100
}
101101
if (chunk.byteLength > VIEW_SIZE) {
102-
if (__DEV__) {
103-
if (precomputedChunkSet && precomputedChunkSet.has(chunk)) {
104-
console.error(
105-
'A large precomputed chunk was passed to writeChunk without being copied.' +
106-
' Large chunks get enqueued directly and are not copied. This is incompatible with precomputed chunks because you cannot enqueue the same precomputed chunk twice.' +
107-
' Use "cloneChunk" to make a copy of this large precomputed chunk before writing it. This is a bug in React.',
108-
);
109-
}
110-
}
111102
// this chunk may overflow a single view which implies it was not
112103
// one that is cached by the streaming renderer. We will enqueu
113104
// it directly and expect it is not re-used
@@ -201,14 +192,14 @@ export function stringToChunk(content: string): Chunk {
201192
return content;
202193
}
203194

204-
const precomputedChunkSet = __DEV__ ? new Set<PrecomputedChunk>() : null;
205-
206195
export function stringToPrecomputedChunk(content: string): PrecomputedChunk {
207196
const precomputedChunk = textEncoder.encode(content);
208197

209198
if (__DEV__) {
210-
if (precomputedChunkSet) {
211-
precomputedChunkSet.add(precomputedChunk);
199+
if (precomputedChunk.byteLength > VIEW_SIZE) {
200+
console.error(
201+
'precomputed chunks must be smaller than the view size configured for this host. This is a bug in React.',
202+
);
212203
}
213204
}
214205

@@ -222,14 +213,6 @@ export function typedArrayToBinaryChunk(
222213
return new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
223214
}
224215

225-
export function clonePrecomputedChunk(
226-
precomputedChunk: PrecomputedChunk,
227-
): PrecomputedChunk {
228-
return precomputedChunk.length > VIEW_SIZE
229-
? precomputedChunk.slice()
230-
: precomputedChunk;
231-
}
232-
233216
export function byteLengthOfChunk(chunk: Chunk | PrecomputedChunk): number {
234217
return typeof chunk === 'string'
235218
? Buffer.byteLength(chunk, 'utf8')

packages/react-server/src/forks/ReactServerStreamConfig.custom.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export const closeWithError = $$$config.closeWithError;
4141
export const stringToChunk = $$$config.stringToChunk;
4242
export const stringToPrecomputedChunk = $$$config.stringToPrecomputedChunk;
4343
export const typedArrayToBinaryChunk = $$$config.typedArrayToBinaryChunk;
44-
export const clonePrecomputedChunk = $$$config.clonePrecomputedChunk;
4544
export const byteLengthOfChunk = $$$config.byteLengthOfChunk;
4645
export const byteLengthOfBinaryChunk = $$$config.byteLengthOfBinaryChunk;
4746
export const createFastHash = $$$config.createFastHash;

0 commit comments

Comments
 (0)