Skip to content

HostRoot no longer pops context provider during complete phase - #8568

Merged
bvaughn merged 1 commit into
react:masterfrom
bvaughn:top-level-context-push-pop
Dec 14, 2016
Merged

bvaughn merged 1 commit into
react:masterfrom
bvaughn:top-level-context-push-pop

Conversation

@bvaughn

@bvaughn bvaughn commented Dec 13, 2016 •

Copy link
Copy Markdown
Contributor

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

gaearon commented Dec 13, 2016

Copy link
Copy Markdown
Collaborator

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

sebmarkbage commented Dec 13, 2016 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

bvaughn commented Dec 14, 2016 •

Copy link
Copy Markdown
Contributor Author

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.)

exports.isContextProvider = isContextProvider;

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

Copy link
Copy Markdown
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.

@gaearon gaearon left a comment

Copy link
Copy Markdown
Collaborator

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

gaearon commented Dec 14, 2016

Copy link
Copy Markdown
Collaborator

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

bvaughn commented Dec 14, 2016

Copy link
Copy Markdown
Contributor Author

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

gaearon commented Dec 14, 2016

Copy link
Copy Markdown
Collaborator

Ah okay this makes sense. 👍

Also added an invariant warning to guard against context being popped too many times.
@bvaughn
bvaughn force-pushed the top-level-context-push-pop branch from 6d8b3d6 to b4745ca Compare December 14, 2016 01:26
@bvaughn
bvaughn merged commit 3def431 into react:master Dec 14, 2016
@bvaughn
bvaughn deleted the top-level-context-push-pop branch December 14, 2016 01:27
@sophiebits

Copy link
Copy Markdown
Collaborator

Did this fix the redbox we were seeing?

@bvaughn

bvaughn commented Dec 15, 2016

Copy link
Copy Markdown
Contributor Author

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.

mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
HostRoot no longer pops context provider during complete phase
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
HostRoot no longer pops context provider during complete phase
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