mirror of
https://github.com/facebook/react.git
synced 2026-02-25 05:03:03 +00:00
* Add stack unwinding phase for handling errors A rewrite of error handling, with semantics that more closely match stack unwinding. Errors that are thrown during the render phase unwind to the nearest error boundary, like before. But rather than synchronously unmount the children before retrying, we restart the failed subtree within the same render phase. The failed children are still unmounted (as if all their keys changed) but without an extra commit. Commit phase errors are different. They work by scheduling an error on the update queue of the error boundary. When we enter the render phase, the error is popped off the queue. The rest of the algorithm is the same. This approach is designed to work for throwing non-errors, too, though that feature is not implemented yet. * Add experimental getDerivedStateFromCatch lifecycle Fires during the render phase, so you can recover from an error within the same pass. This aligns error boundaries more closely with try-catch semantics. Let's keep this behind a feature flag until a future release. For now, the recommendation is to keep using componentDidCatch. Eventually, the advice will be to use getDerivedStateFromCatch for handling errors and componentDidCatch only for logging. * Reconcile twice to remount failed children, instead of using a boolean * Handle effect immediately after its thrown This way we don't have to store the thrown values on the effect list. * ReactFiberIncompleteWork -> ReactFiberUnwindWork * Remove startTime * Remove TypeOfException We don't need it yet. We'll reconsider once we add another exception type. * Move replay to outer catch block This moves it out of the hot path.
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
export type TypeOfSideEffect = number;
|
|
|
|
// Don't change these two values. They're used by React Dev Tools.
|
|
export const NoEffect = /* */ 0b00000000000;
|
|
export const PerformedWork = /* */ 0b00000000001;
|
|
|
|
// You can change the rest (and add more).
|
|
export const Placement = /* */ 0b00000000010;
|
|
export const Update = /* */ 0b00000000100;
|
|
export const PlacementAndUpdate = /* */ 0b00000000110;
|
|
export const Deletion = /* */ 0b00000001000;
|
|
export const ContentReset = /* */ 0b00000010000;
|
|
export const Callback = /* */ 0b00000100000;
|
|
export const DidCapture = /* */ 0b00001000000;
|
|
export const Ref = /* */ 0b00010000000;
|
|
export const ErrLog = /* */ 0b00100000000;
|
|
|
|
// Union of all host effects
|
|
export const HostEffectMask = /* */ 0b00111111111;
|
|
|
|
export const Incomplete = /* */ 0b01000000000;
|
|
export const ShouldCapture = /* */ 0b10000000000;
|