@samitouri / QOS-React-2 / commits / 696e736be1

Warn if static flag is accidentally cleared (#20807)

* Warn if static flag is accidentally cleared "Static" fiber flags are flags that are meant to exist for the lifetime of a component. It's really important not to accidentally reset these, because we use them to decide whether or not to perform some operation on a tree (which we can do because they get bubbled via `subtreeFlags)`. We've had several bugs that were caused by this mistake, so we actually don't rely on static flags anywhere, yet. But we'd like to. So let's roll out this warning and see if it fires anywhere. Once we can confirm that there are no warnings, we can assume that it's safe to start using static flags. I did not wrap it behind a feature flag, because it's dev-only, and we can use our internal warning filter to hide this from the console. * Intentionally clear static flag to test warning * ...and fix it again

Andrew Clark committed Feb 11, 2021 at 16:20 UTC 696e736be11b22e8d4fa40438d235b63db7fddde
2 files changed +30
packages/react-reconciler/src/ReactFiberHooks.new.js
+15
@@ -471,6 +471,21 @@ export function renderWithHooks<Props, SecondArg>(
471 currentHookNameInDev = null;
472 hookTypesDev = null;
473 hookTypesUpdateIndexDev = -1;
474 +
475 + // Confirm that a static flag was not added or removed since the last
476 + // render. If this fires, it suggests that we incorrectly reset the static
477 + // flags in some other part of the codebase. This has happened before, for
478 + // example, in the SuspenseList implementation.
479 + if (
480 + current !== null &&
481 + (current.flags & PassiveStaticEffect) !==
482 + (workInProgress.flags & PassiveStaticEffect)
483 + ) {
484 + console.error(
485 + 'Internal React error: Expected static flag was missing. Please ' +
486 + 'notify the React team.',
487 + );
488 + }
489 }
490
491 didScheduleRenderPhaseUpdate = false;
packages/react-reconciler/src/ReactFiberHooks.old.js
+15
@@ -471,6 +471,21 @@ export function renderWithHooks<Props, SecondArg>(
471 currentHookNameInDev = null;
472 hookTypesDev = null;
473 hookTypesUpdateIndexDev = -1;
474 +
475 + // Confirm that a static flag was not added or removed since the last
476 + // render. If this fires, it suggests that we incorrectly reset the static
477 + // flags in some other part of the codebase. This has happened before, for
478 + // example, in the SuspenseList implementation.
479 + if (
480 + current !== null &&
481 + (current.flags & PassiveStaticEffect) !==
482 + (workInProgress.flags & PassiveStaticEffect)
483 + ) {
484 + console.error(
485 + 'Internal React error: Expected static flag was missing. Please ' +
486 + 'notify the React team.',
487 + );
488 + }
489 }
490
491 didScheduleRenderPhaseUpdate = false;