Skip to content

Commit fe3f0ec

Browse files
authored
[Flight] Don't use object property initializer for async iterable (#33591)
It turns out this was being compiled to a `_defineProperty` helper by Babel or Closure. We're supposed to have it error the build when we use features like this that might get compiled. We should stick to simple ES5 features.
1 parent d70ee32 commit fe3f0ec

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,32 +2077,34 @@ function startAsyncIterable<T>(
20772077
}
20782078
},
20792079
};
2080-
const iterable: $AsyncIterable<T, T, void> = {
2081-
[ASYNC_ITERATOR](): $AsyncIterator<T, T, void> {
2082-
let nextReadIndex = 0;
2083-
return createIterator(arg => {
2084-
if (arg !== undefined) {
2085-
throw new Error(
2086-
'Values cannot be passed to next() of AsyncIterables passed to Client Components.',
2080+
2081+
const iterable: $AsyncIterable<T, T, void> = ({}: any);
2082+
// $FlowFixMe[cannot-write]
2083+
iterable[ASYNC_ITERATOR] = (): $AsyncIterator<T, T, void> => {
2084+
let nextReadIndex = 0;
2085+
return createIterator(arg => {
2086+
if (arg !== undefined) {
2087+
throw new Error(
2088+
'Values cannot be passed to next() of AsyncIterables passed to Client Components.',
2089+
);
2090+
}
2091+
if (nextReadIndex === buffer.length) {
2092+
if (closed) {
2093+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
2094+
return new ReactPromise(
2095+
INITIALIZED,
2096+
{done: true, value: undefined},
2097+
null,
2098+
response,
20872099
);
20882100
}
2089-
if (nextReadIndex === buffer.length) {
2090-
if (closed) {
2091-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
2092-
return new ReactPromise(
2093-
INITIALIZED,
2094-
{done: true, value: undefined},
2095-
null,
2096-
response,
2097-
);
2098-
}
2099-
buffer[nextReadIndex] =
2100-
createPendingChunk<IteratorResult<T, T>>(response);
2101-
}
2102-
return buffer[nextReadIndex++];
2103-
});
2104-
},
2101+
buffer[nextReadIndex] =
2102+
createPendingChunk<IteratorResult<T, T>>(response);
2103+
}
2104+
return buffer[nextReadIndex++];
2105+
});
21052106
};
2107+
21062108
// TODO: If it's a single shot iterator we can optimize memory by cleaning up the buffer after
21072109
// reading through the end, but currently we favor code size over this optimization.
21082110
resolveStream(

0 commit comments

Comments
 (0)