Skip to content

Commit 3ba6560

Browse files
committed
make Chunk types opaque where possible
Previously Chunks were not opaque so you could construct conincidental types that satisifed the type condition but were not routed through a Chunk factory. This is dangerous because it allows for things like the transpoition of escaping and chunking which has led to bugs in certain environments. Ideally all chunk types would be opaque however the ReactNative Fizz runtime constructs type-compatible entries with PrecomputedChunk without calling into the Chunk factory. This should be fixed but is outside the scope of this change so I left those not opaque where they would otherwise lead to new type errors
1 parent 796bfd7 commit 3ba6560

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export interface Destination {
1212
destroy(error: Error): mixed;
1313
}
1414

15-
export type PrecomputedChunk = string;
16-
export type Chunk = string;
15+
export opaque type PrecomputedChunk = string;
16+
export opaque type Chunk = string;
1717

1818
export function scheduleWork(callback: () => void) {
1919
callback();

packages/react-server-dom-relay/src/ReactServerStreamConfigFB.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type Destination = {
1414
error: mixed,
1515
};
1616

17-
export type PrecomputedChunk = string;
18-
export type Chunk = string;
17+
export opaque type PrecomputedChunk = string;
18+
export opaque type Chunk = string;
1919

2020
export function scheduleWork(callback: () => void) {
2121
// We don't schedule work in this model, and instead expect performWork to always be called repeatedly.

packages/react-server/src/ReactServerStreamConfigBrowser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
export type Destination = ReadableStreamController;
1111

1212
export type PrecomputedChunk = Uint8Array;
13-
export type Chunk = Uint8Array;
13+
export opaque type Chunk = Uint8Array;
1414

1515
export function scheduleWork(callback: () => void) {
1616
callback();

packages/react-server/src/ReactServerStreamConfigNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface MightBeFlushable {
1717
export type Destination = Writable & MightBeFlushable;
1818

1919
export type PrecomputedChunk = Uint8Array;
20-
export type Chunk = string;
20+
export opaque type Chunk = string;
2121

2222
export function scheduleWork(callback: () => void) {
2323
setImmediate(callback);

0 commit comments

Comments
 (0)