Skip to content
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

HostRoot no longer pops context provider during complete phase #8568

Merged
merged 1 commit into from
Dec 14, 2016

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Dec 13, 2016

In the begin work phase, we call pushContextProvider for ClassComponents. In the complete work phase, we call popContextProvider for both ClassComponents and HostRoots. The result is that we end up popping more times than we should.

This PR removes the popContextProvider call for HostRoot and adds an invariant warning to popContextProvider as well.

Note that no new tests fail with the new invariant warning once the superfluous popContextProvider call is removed. (Several fail with it in place.)

Note also that in the begin work phase we call pushHostContainer for HostRoots and HostPortals but we only call popHostContainer for HostPortals during the complete work phase. It seems like we should align these calls as well but I don't have enough context to tackle that yet.

@gaearon
Copy link
Collaborator

gaearon commented Dec 13, 2016

Note also that in the begin work phase we call pushHostContainer for HostRoots and HostPortals but we only call popHostContainer for HostPortals during the complete work phase.

If I recall correctly I needed the host container to still exist during the commit phase for this. However now that I think of it we would get the wrong one in the portal (root instead of portal root) so it's likely a bug. Can you figure out a failing test for this?

@sebmarkbage
Copy link
Collaborator

sebmarkbage commented Dec 13, 2016

We can also get the wrong one because we could reorder commit phase to not be lined up with the last reconciliation so this seem fragile regardless. We should always popHostContainer in complete and if we need it in commit we should readd it. Although it might be hard to do because the commit phase doesn't happen in top down order. It only visits nodes with side-effects.

@sebmarkbage
Copy link
Collaborator

I'm not sure how we can solve the problem of need the host container in the commit phase since we'd need to store an extra field for this. Maybe we should simply avoid that in the commit phase and only allow it in the complete phase. We probably want to calculate the props diff in complete anyway. It's currently only used for lazily subscribing to events, which we never undo so it's fine to do that in the complete phase. In fact, I think we might want to stop doing that lazily anyway.

@bvaughn
Copy link
Contributor Author

bvaughn commented Dec 14, 2016

Sounds like there is a bigger question about the host container stuff. Is this diff safe to merge in the meanwhile? (It's related, but not quite the same thing.)

@@ -77,6 +77,7 @@ function isContextProvider(fiber : Fiber) : boolean {
exports.isContextProvider = isContextProvider;

function popContextProvider() : void {
invariant(index >= 0, 'Unexpected context pop');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer > -1 here because we already compare to -1 in a few parts of the file.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I'd like my tiny nit changed

@gaearon
Copy link
Collaborator

gaearon commented Dec 14, 2016

Note that no new tests fail with the new invariant warning once the superfluous popContextProvider call is removed. (Several fail with it in place.)

Where are those tests? Are we sure we'll commit them later? Don't want them to get lost.

@bvaughn
Copy link
Contributor Author

bvaughn commented Dec 14, 2016

Sure. Happy to make the nit-change.

The tests are already committed. With only the invariant addition, several existing tests fail. With the removal of the superfluous popContextProvider, they no longer fail. Sorry if my initial comment was confusing.

@gaearon
Copy link
Collaborator

gaearon commented Dec 14, 2016

Ah okay this makes sense. 👍

Also added an invariant warning to guard against context being popped too many times.
@bvaughn bvaughn merged commit 3def431 into facebook:master Dec 14, 2016
@bvaughn bvaughn deleted the top-level-context-push-pop branch December 14, 2016 01:27
@sophiebits
Copy link
Contributor

Did this fix the redbox we were seeing?

@bvaughn
Copy link
Contributor Author

bvaughn commented Dec 15, 2016

Fixed some problems, not all. I think I have a fix for some more (still not all) but need to step through the failing tests to determine if it's really a causal-fix or just a symptom-fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants