@samitouri / QOS-React-2 / commits / aa736a0fa6

Add queue microtask to host configs (#20668)

* Queue discrete events in microtask * Fix flow types * Add to createReactNoop * More flow types * Remove import * Add to custom HostConfig as well

Ricky committed Jan 27, 2021 at 15:01 UTC aa736a0fa6e22f902bd7a98dcb9b24d8c4310e35
7 files changed +53
packages/react-art/src/ReactARTHostConfig.js
+3
@@ -330,6 +330,9 @@ export function getChildHostContext() {
330 export const scheduleTimeout = setTimeout;
331 export const cancelTimeout = clearTimeout;
332 export const noTimeout = -1;
333 +export function queueMicrotask(callback: Function) {
334 + invariant(false, 'Not implemented.');
335 +}
336
337 export function shouldSetTextContent(type, props) {
338 return (
packages/react-dom/src/client/ReactDOMHostConfig.js
+15
@@ -384,6 +384,21 @@ export const scheduleTimeout: any =
384 export const cancelTimeout: any =
385 typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
386 export const noTimeout = -1;
387 +export const queueMicrotask: any =
388 + typeof global.queueMicrotask === 'function'
389 + ? global.queueMicrotask
390 + : typeof Promise !== 'undefined'
391 + ? callback =>
392 + Promise.resolve(null)
393 + .then(callback)
394 + .catch(handleErrorInNextTick)
395 + : scheduleTimeout;
396 +
397 +function handleErrorInNextTick(error) {
398 + setTimeout(() => {
399 + throw error;
400 + });
401 +}
402
403 // -------------------
404 // Mutation
packages/react-native-renderer/src/ReactFabricHostConfig.js
+3
@@ -348,6 +348,9 @@ export const warnsIfNotActing = false;
348 export const scheduleTimeout = setTimeout;
349 export const cancelTimeout = clearTimeout;
350 export const noTimeout = -1;
351 +export function queueMicrotask(callback: Function) {
352 + invariant(false, 'Not implemented.');
353 +}
354
355 // -------------------
356 // Persistence
packages/react-native-renderer/src/ReactNativeHostConfig.js
+3
@@ -247,6 +247,9 @@ export const warnsIfNotActing = true;
247 export const scheduleTimeout = setTimeout;
248 export const cancelTimeout = clearTimeout;
249 export const noTimeout = -1;
250 +export function queueMicrotask(callback: Function) {
251 + invariant(false, 'Not implemented.');
252 +}
253
254 export function shouldSetTextContent(type: string, props: Props): boolean {
255 // TODO (bvaughn) Revisit this decision.
packages/react-noop-renderer/src/createReactNoop.js
+13
@@ -371,6 +371,19 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
371 scheduleTimeout: setTimeout,
372 cancelTimeout: clearTimeout,
373 noTimeout: -1,
374 + queueMicrotask:
375 + typeof queueMicrotask === 'function'
376 + ? queueMicrotask
377 + : typeof Promise !== 'undefined'
378 + ? callback =>
379 + Promise.resolve(null)
380 + .then(callback)
381 + .catch(error => {
382 + setTimeout(() => {
383 + throw error;
384 + });
385 + })
386 + : setTimeout,
387
388 prepareForCommit(): null | Object {
389 return null;
packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js
+1
@@ -54,6 +54,7 @@ export const shouldSetTextContent = $$$hostConfig.shouldSetTextContent;
54 export const createTextInstance = $$$hostConfig.createTextInstance;
55 export const scheduleTimeout = $$$hostConfig.scheduleTimeout;
56 export const cancelTimeout = $$$hostConfig.cancelTimeout;
57 +export const queueMicrotask = $$$hostConfig.queueMicrotask;
58 export const noTimeout = $$$hostConfig.noTimeout;
59 export const now = $$$hostConfig.now;
60 export const isPrimaryRenderer = $$$hostConfig.isPrimaryRenderer;
packages/react-test-renderer/src/ReactTestHostConfig.js
+15
@@ -220,6 +220,21 @@ export const warnsIfNotActing = true;
220
221 export const scheduleTimeout = setTimeout;
222 export const cancelTimeout = clearTimeout;
223 +export const queueMicrotask =
224 + typeof global.queueMicrotask === 'function'
225 + ? global.queueMicrotask
226 + : typeof Promise !== 'undefined'
227 + ? (callback: Function) =>
228 + Promise.resolve(null)
229 + .then(callback)
230 + .catch(handleErrorInNextTick)
231 + : scheduleTimeout;
232 +
233 +function handleErrorInNextTick(error) {
234 + setTimeout(() => {
235 + throw error;
236 + });
237 +}
238 export const noTimeout = -1;
239
240 // -------------------