-
Notifications
You must be signed in to change notification settings - Fork 47.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify context stack implementations #12359
Conversation
7939451
to
7bdd390
Compare
Implements the new context API on top of the existing ReactStack that we already use for host context and legacy context. Now there is a single array that we push and pop from. This makes the interrupt path slightly slower, since when we reset the unit of work pointer, we have to iterate over the stack (like before) *and* switch on the type of work (not like before). On the other hand, this unifies all of the unwinding behavior in the UnwindWork module.
7bdd390
to
3bb28ba
Compare
findCurrentUnmaskedContext(fiber: Fiber): Object, | ||
}; | ||
|
||
export default function(stack: Stack): LegacyContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of noise in this diff, but all I did here was move this into a module constructor and add a corresponding Flow type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At a high level, this looks like a nice consolidation to me.
I don't have a sense of whether the slower interruption is problematic or not.
while (interruptedWork !== null) { | ||
unwindInterruptedWork(interruptedWork); | ||
interruptedWork = interruptedWork.return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we (DEV-only) assert that the stack is empty after unwinding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
Details of bundled changes.Comparing: ad9544f...3ae3d45 create-subscription
Generated by 🚫 dangerJS |
* Use module pattern so context stack is isolated per renderer * Unify context implementations Implements the new context API on top of the existing ReactStack that we already use for host context and legacy context. Now there is a single array that we push and pop from. This makes the interrupt path slightly slower, since when we reset the unit of work pointer, we have to iterate over the stack (like before) *and* switch on the type of work (not like before). On the other hand, this unifies all of the unwinding behavior in the UnwindWork module. * Add DEV only warning if stack is not reset properly
* Use module pattern so context stack is isolated per renderer * Unify context implementations Implements the new context API on top of the existing ReactStack that we already use for host context and legacy context. Now there is a single array that we push and pop from. This makes the interrupt path slightly slower, since when we reset the unit of work pointer, we have to iterate over the stack (like before) *and* switch on the type of work (not like before). On the other hand, this unifies all of the unwinding behavior in the UnwindWork module. * Add DEV only warning if stack is not reset properly
Implements the new context API on top of the existing ReactStack that we already use for host context and legacy context. Now there is a single array that we push and pop from.
This makes the interrupt path slightly slower, since when we reset the unit of work pointer, we have to iterate over the stack (like before) and switch on the type of work (not like before). On the other hand, this unifies all of the unwinding behavior in the UnwindWork module.
Also changes the context modules to use module constructors, so that each renderer gets a separate instance, which is currently broken when using react-reconciler.
This is not a total unification of legacy context and the new context API. A further step would be to implement the legacy,
contextTypes
-based API on top ofReact.createContext
.