-
Notifications
You must be signed in to change notification settings - Fork 49.9k
[Fiber] Remove array indirection in host context #8544
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
Conversation
| function getRootHostContainer() : C { | ||
| if (containerDepth === -1) { | ||
| throw new Error('Expected to find a root container.'); | ||
| if (rootInstance == null) { |
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.
For the new Context API I was thinking that we should require a default value so that the type is always guaranteed to be satisfied and the user doesn't have to add extra null checks. Maybe we should do the same for host context?
| contextFibers, | ||
| contextValues, | ||
| contextDepth, | ||
| }; |
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.
Why does context arrays have to be stored separately here? Can't you just push another context onto the stack of contexts? Even if that is null. Then pop it on the way back up.
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.
I'd need to know how many can I pop. If I make null the sentinel then I need to somehow forbid renderers from specifying something like string | null as type argument. Is this even possible with Flow?
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.
Oh never mind, I see how this could work.
This lets us keep subtrees separated without maintaining independent context arrays for subtrees.
|
Addressed #8544 (comment) in 6463d67. |
| rootInstance = portalStack[portalDepth]; | ||
| portalStack[portalDepth] = null; | ||
| portalDepth--; | ||
| // If we pushed any context while in a portal, we need to roll it back. |
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.
How can you ever pop a host container with a context deeper than one null? Wouldn't this always be exactly one null?
Because any new context provider will be below the portal in the tree and pop on the way up to the portal.
Think of this problem in terms of a normal execution stack. You wouldn't need multiple arrays and these special cases for unwinding in a normal execution stack other than when you unwind for errors so you shouldn't need it here.
I was trying to be smart but didn't need to.
| containerDepth--; | ||
| } | ||
|
|
||
| function getHostContext() : CX | null { |
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.
Ideally getHotsContext could just return a value from the closure instead of going through the array just like getRootHostContainer does.
As discussed in #8490 (comment).