Skip to content

Commit 2f8d25b

Browse files
committed
Encode strings
1 parent db7e963 commit 2f8d25b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ describe('ReactFlightDOMNode', () => {
9797
function Text({children}) {
9898
return <span>{children}</span>;
9999
}
100+
// Large strings can get encoded differently so we need to test that.
101+
const largeString = 'world'.repeat(1000);
100102
function HTML() {
101103
return (
102104
<div>
103105
<Text>hello</Text>
104-
<Text>world</Text>
106+
<Text>{largeString}</Text>
105107
</div>
106108
);
107109
}
@@ -127,7 +129,7 @@ describe('ReactFlightDOMNode', () => {
127129
html: (
128130
<div>
129131
<span>hello</span>
130-
<span>world</span>
132+
<span>{largeString}</span>
131133
</div>
132134
),
133135
});

packages/react-server-dom-webpack/src/server/ReactFlightDOMServerNode.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export {
5454
createClientModuleProxy,
5555
} from '../ReactFlightWebpackReferences';
5656

57+
import {textEncoder} from 'react-server/src/ReactServerStreamConfigNode';
58+
5759
import type {TemporaryReferenceSet} from 'react-server/src/ReactFlightServerTemporaryReferences';
5860

5961
export {createTemporaryReferenceSet} from 'react-server/src/ReactFlightServerTemporaryReferences';
@@ -138,6 +140,9 @@ function createFakeWritableFromReadableStreamController(
138140
// a fake writable for now to push into the Readable.
139141
return ({
140142
write(chunk: string | Uint8Array) {
143+
if (typeof chunk === 'string') {
144+
chunk = textEncoder.encode(chunk);
145+
}
141146
controller.enqueue(chunk);
142147
// in web streams there is no backpressure so we can alwas write more
143148
return true;

packages/react-server/src/ReactServerStreamConfigNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export function close(destination: Destination) {
189189
destination.end();
190190
}
191191

192-
const textEncoder = new TextEncoder();
192+
export const textEncoder: TextEncoder = new TextEncoder();
193193

194194
export function stringToChunk(content: string): Chunk {
195195
return content;

0 commit comments

Comments
 (0)