dillon1000/react
Commit
Browse files Move context comparison to consumer
In the lazy context implementation, not all context changes are propagated from the provider, so we can't rely on the propagation alone to mark the consumer as dirty. The consumer needs to compare to the previous value, like we do for state and context. I added a `memoizedValue` field to the context dependency type. Then in the consumer, we iterate over the current dependencies to see if something changed. We only do this iteration after props and state has already bailed out, so it's a relatively uncommon path, except at the root of a changed subtree. Alternatively, we could move these comparisons into `readContext`, but that's a much hotter path, so I think this is an appropriate trade off.
Changed paths22 files
First-parent comparisonpackages/react-dom/src/__tests__/ReactLegacyContextDisabled-test.internal.js ModifiedM packages/react-reconciler/src/ReactFiberBeginWork.new.js ModifiedM packages/react-reconciler/src/ReactFiberBeginWork.old.js ModifiedM packages/react-reconciler/src/ReactFiberClassComponent.new.js ModifiedM packages/react-reconciler/src/ReactFiberClassComponent.old.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.new.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.old.js ModifiedM packages/react-reconciler/src/ReactFiberNewContext.new.js ModifiedM packages/react-reconciler/src/ReactFiberNewContext.old.js ModifiedM packages/react-reconciler/src/ReactInternalTypes.js ModifiedA packages/react-reconciler/src/__tests__/ReactContextPropagation-test.js AddedM packages/react/src/__tests__/ReactContextValidator-test.js ModifiedM packages/shared/ReactFeatureFlags.js ModifiedM packages/shared/forks/ReactFeatureFlags.native-fb.js ModifiedM packages/shared/forks/ReactFeatureFlags.native-oss.js ModifiedM packages/shared/forks/ReactFeatureFlags.test-renderer.js ModifiedM packages/shared/forks/ReactFeatureFlags.test-renderer.native.js ModifiedM packages/shared/forks/ReactFeatureFlags.test-renderer.www.js ModifiedM packages/shared/forks/ReactFeatureFlags.testing.js ModifiedM packages/shared/forks/ReactFeatureFlags.testing.www.js ModifiedM packages/shared/forks/ReactFeatureFlags.www-dynamic.js ModifiedM packages/shared/forks/ReactFeatureFlags.www.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…