mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
[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.
This commit is contained in:
parent
d70ee32b88
commit
fe3f0ec037
48
packages/react-client/src/ReactFlightClient.js
vendored
48
packages/react-client/src/ReactFlightClient.js
vendored
|
|
@ -2077,32 +2077,34 @@ function startAsyncIterable<T>(
|
|||
}
|
||||
},
|
||||
};
|
||||
const iterable: $AsyncIterable<T, T, void> = {
|
||||
[ASYNC_ITERATOR](): $AsyncIterator<T, T, void> {
|
||||
let nextReadIndex = 0;
|
||||
return createIterator(arg => {
|
||||
if (arg !== undefined) {
|
||||
throw new Error(
|
||||
'Values cannot be passed to next() of AsyncIterables passed to Client Components.',
|
||||
|
||||
const iterable: $AsyncIterable<T, T, void> = ({}: any);
|
||||
// $FlowFixMe[cannot-write]
|
||||
iterable[ASYNC_ITERATOR] = (): $AsyncIterator<T, T, void> => {
|
||||
let nextReadIndex = 0;
|
||||
return createIterator(arg => {
|
||||
if (arg !== undefined) {
|
||||
throw new Error(
|
||||
'Values cannot be passed to next() of AsyncIterables passed to Client Components.',
|
||||
);
|
||||
}
|
||||
if (nextReadIndex === buffer.length) {
|
||||
if (closed) {
|
||||
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
||||
return new ReactPromise(
|
||||
INITIALIZED,
|
||||
{done: true, value: undefined},
|
||||
null,
|
||||
response,
|
||||
);
|
||||
}
|
||||
if (nextReadIndex === buffer.length) {
|
||||
if (closed) {
|
||||
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
||||
return new ReactPromise(
|
||||
INITIALIZED,
|
||||
{done: true, value: undefined},
|
||||
null,
|
||||
response,
|
||||
);
|
||||
}
|
||||
buffer[nextReadIndex] =
|
||||
createPendingChunk<IteratorResult<T, T>>(response);
|
||||
}
|
||||
return buffer[nextReadIndex++];
|
||||
});
|
||||
},
|
||||
buffer[nextReadIndex] =
|
||||
createPendingChunk<IteratorResult<T, T>>(response);
|
||||
}
|
||||
return buffer[nextReadIndex++];
|
||||
});
|
||||
};
|
||||
|
||||
// TODO: If it's a single shot iterator we can optimize memory by cleaning up the buffer after
|
||||
// reading through the end, but currently we favor code size over this optimization.
|
||||
resolveStream(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user