@samitouri / QOS-React-1 / commits / fe3f0ec037

[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.

Sebastian Markbåge committed Jun 22, 2025 at 10:40 UTC fe3f0ec0374b7323bf259e4154eb4ee739caac7b
1 file changed +25 -23
packages/react-client/src/ReactFlightClient.js
+25 -23
@@ -2077,32 +2077,34 @@ function startAsyncIterable<T>(
2077 }
2078 },
2079 };
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,
2099 );
2100 }
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 + });
2106 };
2107 +
2108 // TODO: If it's a single shot iterator we can optimize memory by cleaning up the buffer after
2109 // reading through the end, but currently we favor code size over this optimization.
2110 resolveStream(