next.js
4d2a793c - use setImmediate (if present) in edge react-dom/RSDW/RSDT (#68952)

Commit
1 year ago
use setImmediate (if present) in edge react-dom/RSDW/RSDT (#68952) This is a hack that we need until we refactor everything to use the Node builds of 'react-dom/server' and 'react-server-dom-{webpack,turbopack}' when running in Node. We're currently using the Edge builds of 'react-dom/server' and 'react-server-dom-{webpack,turbopack}' everywhere. But if we're in Node, we'd like it to act more like the Node build, for performance and correctness reasons (e.g. in DynamicIO). In particular, we want to change the implementation of `scheduleWork` from [the Edge one](https://github.com/facebook/react/blob/19bd26beb689e554fceb0b929dc5199be8cba594/packages/react-server/src/ReactServerStreamConfigEdge.js#L31-L33) to [the Node one](https://github.com/facebook/react/blob/19bd26beb689e554fceb0b929dc5199be8cba594/packages/react-server/src/ReactServerStreamConfigNode.js#L25-L27). Since `scheduleWork` is inlined, we have to convert `setTimeout` calls like this ``` setTimeout(() => ..., 0) ``` into this: ``` setImmediate(() => ...) ``` ReactDOM only ever calls `setTimeout` with `0` (and no further arguments), so we can just naively replace `setTimeout` with `setImmediate`. Technically the `0` will then be passed to the callback as an argument, but the callbacks will always ignore it anyway.
Author
Parents
Loading