GeezerVison is showing github.com — Add `supportsMicrotasks` to the host config (#20809) · react/react@1a74726
File treeExpand file treeCollapse file tree Open diff view settings react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-art/src/ReactARTHostConfig.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -249,6 +249,7 @@ export * from 'react-reconciler/src/ReactFiberHostConfigWithNoPersistence'; | 249 | 249 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration'; | 250 | 250 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes'; | 251 | 251 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors'; | | 252 | +export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks'; | 252 | 253 |
| 253 | 254 | export function appendInitialChild(parentInstance, child) { | 254 | 255 | if (typeof child === 'string') { | @@ -338,9 +339,6 @@ export function getChildHostContext() { | 338 | 339 | export const scheduleTimeout = setTimeout; | 339 | 340 | export const cancelTimeout = clearTimeout; | 340 | 341 | export const noTimeout = -1; | 341 | | -export function scheduleMicrotask(callback: Function) { | 342 | | - invariant(false, 'Not implemented.'); | 343 | | -} | 344 | 342 |
| 345 | 343 | export function shouldSetTextContent(type, props) { | 346 | 344 | return ( | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMHostConfig.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,6 +67,7 @@ import { | 67 | 67 | enableCreateEventHandleAPI, | 68 | 68 | enableScopeAPI, | 69 | 69 | enableNewReconciler, | | 70 | + enableDiscreteEventMicroTasks, | 70 | 71 | } from 'shared/ReactFeatureFlags'; | 71 | 72 | import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags'; | 72 | 73 | import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem'; | @@ -399,6 +400,11 @@ export const scheduleTimeout: any = | 399 | 400 | export const cancelTimeout: any = | 400 | 401 | typeof clearTimeout === 'function' ? clearTimeout : (undefined: any); | 401 | 402 | export const noTimeout = -1; | | 403 | + | | 404 | +// ------------------- | | 405 | +// Microtasks | | 406 | +// ------------------- | | 407 | +export const supportsMicrotasks = enableDiscreteEventMicroTasks; | 402 | 408 | export const scheduleMicrotask: any = | 403 | 409 | typeof queueMicrotask === 'function' | 404 | 410 | ? queueMicrotask | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricHostConfig.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -193,6 +193,7 @@ export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMutation'; | 193 | 193 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration'; | 194 | 194 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes'; | 195 | 195 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors'; | | 196 | +export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks'; | 196 | 197 |
| 197 | 198 | export function appendInitialChild( | 198 | 199 | parentInstance: Instance, | @@ -360,9 +361,6 @@ export const warnsIfNotActing = false; | 360 | 361 | export const scheduleTimeout = setTimeout; | 361 | 362 | export const cancelTimeout = clearTimeout; | 362 | 363 | export const noTimeout = -1; | 363 | | -export function scheduleMicrotask(callback: Function) { | 364 | | - invariant(false, 'Not implemented.'); | 365 | | -} | 366 | 364 |
| 367 | 365 | // ------------------- | 368 | 366 | // Persistence | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeHostConfig.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,6 +97,7 @@ export * from 'react-reconciler/src/ReactFiberHostConfigWithNoPersistence'; | 97 | 97 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration'; | 98 | 98 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes'; | 99 | 99 | export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors'; | | 100 | +export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks'; | 100 | 101 |
| 101 | 102 | export function appendInitialChild( | 102 | 103 | parentInstance: Instance, | @@ -255,9 +256,6 @@ export const warnsIfNotActing = true; | 255 | 256 | export const scheduleTimeout = setTimeout; | 256 | 257 | export const cancelTimeout = clearTimeout; | 257 | 258 | export const noTimeout = -1; | 258 | | -export function scheduleMicrotask(callback: Function) { | 259 | | - invariant(false, 'Not implemented.'); | 260 | | -} | 261 | 259 |
| 262 | 260 | export function shouldSetTextContent(type: string, props: Props): boolean { | 263 | 261 | // TODO (bvaughn) Revisit this decision. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,10 @@ import { | 27 | 27 | LegacyRoot, | 28 | 28 | } from 'react-reconciler/src/ReactRootTags'; | 29 | 29 |
| 30 | | -import {enableNativeEventPriorityInference} from 'shared/ReactFeatureFlags'; | | 30 | +import { | | 31 | + enableNativeEventPriorityInference, | | 32 | + enableDiscreteEventMicroTasks, | | 33 | +} from 'shared/ReactFeatureFlags'; | 31 | 34 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | 32 | 35 | import enqueueTask from 'shared/enqueueTask'; | 33 | 36 | const {IsSomeRendererActing} = ReactSharedInternals; | @@ -372,6 +375,8 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 372 | 375 | scheduleTimeout: setTimeout, | 373 | 376 | cancelTimeout: clearTimeout, | 374 | 377 | noTimeout: -1, | | 378 | + | | 379 | + supportsMicrotasks: enableDiscreteEventMicroTasks, | 375 | 380 | scheduleMicrotask: | 376 | 381 | typeof queueMicrotask === 'function' | 377 | 382 | ? queueMicrotask | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/README.md +4-1Lines changed: 4 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -203,9 +203,12 @@ You can proxy this to `clearTimeout` or its equivalent in your environment. | 203 | 203 |
| 204 | 204 | This is a property (not a function) that should be set to something that can never be a valid timeout ID. For example, you can set it to `-1`. | 205 | 205 |
| | 206 | +#### `supportsMicrotask` | | 207 | + | | 208 | +Set this to true to indicate that your renderer supports `scheduleMicrotask`. We use microtasks as part of our discrete event implementation in React DOM. If you're not sure if your renderer should support this, you probably should. The option to not implement `scheduleMicrotask` exists so that platforms with more control over user events, like React Native, can choose to use a different mechanism. | 206 | 209 | #### `scheduleMicrotask(fn)` | 207 | 210 |
| 208 | | -You can proxy this to `queueMicrotask` or its equivalent in your environment. | | 211 | +Optional. You can proxy this to `queueMicrotask` or its equivalent in your environment. | 209 | 212 |
| 210 | 213 | #### `isPrimaryRenderer` | 211 | 214 |
| |
Collapse file Copy file name to clipboard +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/** | | 2 | + * Copyright (c) Facebook, Inc. and its affiliates. | | 3 | + * | | 4 | + * This source code is licensed under the MIT license found in the | | 5 | + * LICENSE file in the root directory of this source tree. | | 6 | + * | | 7 | + * @flow | | 8 | + */ | | 9 | + | | 10 | +import invariant from 'shared/invariant'; | | 11 | + | | 12 | +// Renderers that don't support microtasks | | 13 | +// can re-export everything from this module. | | 14 | + | | 15 | +function shim(...args: any) { | | 16 | + invariant( | | 17 | + false, | | 18 | + 'The current renderer does not support microtasks. ' + | | 19 | + 'This error is likely caused by a bug in React. ' + | | 20 | + 'Please file an issue.', | | 21 | + ); | | 22 | +} | | 23 | + | | 24 | +// Test selectors (when unsupported) | | 25 | +export const supportsMicrotasks = false; | | 26 | +export const scheduleMicrotask = shim; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,8 +93,9 @@ import { | 93 | 93 | warnsIfNotActing, | 94 | 94 | afterActiveInstanceBlur, | 95 | 95 | clearContainer, | 96 | | - scheduleMicrotask, | 97 | 96 | getCurrentEventPriority, | | 97 | + supportsMicrotasks, | | 98 | + scheduleMicrotask, | 98 | 99 | } from './ReactFiberHostConfig'; | 99 | 100 |
| 100 | 101 | import { | @@ -219,7 +220,6 @@ import { | 219 | 220 | syncNestedUpdateFlag, | 220 | 221 | } from './ReactProfilerTimer.new'; | 221 | 222 |
| 222 | | -import {enableDiscreteEventMicroTasks} from 'shared/ReactFeatureFlags'; | 223 | 223 | // DEV stuff | 224 | 224 | import getComponentName from 'shared/getComponentName'; | 225 | 225 | import ReactStrictModeWarnings from './ReactStrictModeWarnings.new'; | @@ -756,7 +756,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) { | 756 | 756 | performSyncWorkOnRoot.bind(null, root), | 757 | 757 | ); | 758 | 758 | } else if ( | 759 | | - enableDiscreteEventMicroTasks && | | 759 | + supportsMicrotasks && | 760 | 760 | newCallbackPriority === InputDiscreteLanePriority | 761 | 761 | ) { | 762 | 762 | scheduleMicrotask(performSyncWorkOnRoot.bind(null, root)); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.old.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,8 +93,9 @@ import { | 93 | 93 | warnsIfNotActing, | 94 | 94 | afterActiveInstanceBlur, | 95 | 95 | clearContainer, | 96 | | - scheduleMicrotask, | 97 | 96 | getCurrentEventPriority, | | 97 | + supportsMicrotasks, | | 98 | + scheduleMicrotask, | 98 | 99 | } from './ReactFiberHostConfig'; | 99 | 100 |
| 100 | 101 | import { | @@ -219,7 +220,6 @@ import { | 219 | 220 | syncNestedUpdateFlag, | 220 | 221 | } from './ReactProfilerTimer.old'; | 221 | 222 |
| 222 | | -import {enableDiscreteEventMicroTasks} from 'shared/ReactFeatureFlags'; | 223 | 223 | // DEV stuff | 224 | 224 | import getComponentName from 'shared/getComponentName'; | 225 | 225 | import ReactStrictModeWarnings from './ReactStrictModeWarnings.old'; | @@ -756,7 +756,7 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) { | 756 | 756 | performSyncWorkOnRoot.bind(null, root), | 757 | 757 | ); | 758 | 758 | } else if ( | 759 | | - enableDiscreteEventMicroTasks && | | 759 | + supportsMicrotasks && | 760 | 760 | newCallbackPriority === InputDiscreteLanePriority | 761 | 761 | ) { | 762 | 762 | scheduleMicrotask(performSyncWorkOnRoot.bind(null, root)); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,7 +54,6 @@ export const shouldSetTextContent = $$$hostConfig.shouldSetTextContent; | 54 | 54 | export const createTextInstance = $$$hostConfig.createTextInstance; | 55 | 55 | export const scheduleTimeout = $$$hostConfig.scheduleTimeout; | 56 | 56 | export const cancelTimeout = $$$hostConfig.cancelTimeout; | 57 | | -export const scheduleMicrotask = $$$hostConfig.scheduleMicrotask; | 58 | 57 | export const noTimeout = $$$hostConfig.noTimeout; | 59 | 58 | export const now = $$$hostConfig.now; | 60 | 59 | export const isPrimaryRenderer = $$$hostConfig.isPrimaryRenderer; | @@ -75,6 +74,13 @@ export const prepareScopeUpdate = $$$hostConfig.preparePortalMount; | 75 | 74 | export const getInstanceFromScope = $$$hostConfig.getInstanceFromScope; | 76 | 75 | export const getCurrentEventPriority = $$$hostConfig.getCurrentEventPriority; | 77 | 76 |
| | 77 | +// ------------------- | | 78 | +// Microtasks | | 79 | +// (optional) | | 80 | +// ------------------- | | 81 | +export const supportsMicrotasks = $$$hostConfig.supportsMicrotasks; | | 82 | +export const scheduleMicrotask = $$$hostConfig.scheduleMicrotask; | | 83 | + | 78 | 84 | // ------------------- | 79 | 85 | // Test selectors | 80 | 86 | // (optional) | |
|