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

Unify context stack implementations #12359

Merged
merged 3 commits into from Mar 16, 2018
Merged

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Mar 13, 2018

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 of React.createContext.

@acdlite acdlite changed the title Unifycontextstacks Unify context stack implementations Mar 13, 2018
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.
findCurrentUnmaskedContext(fiber: Fiber): Object,
};

export default function(stack: Stack): LegacyContext {
Copy link
Collaborator Author

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.

Copy link
Contributor

@bvaughn bvaughn left a 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;
}
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

@pull-bot
Copy link

Details of bundled changes.

Comparing: ad9544f...3ae3d45

create-subscription

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
create-subscription.development.js n/a n/a 0 B 5.31 KB 0 B 1.89 KB NODE_DEV
create-subscription.production.min.js n/a n/a 0 B 2.52 KB 0 B 1.21 KB NODE_PROD

Generated by 🚫 dangerJS

@acdlite acdlite merged commit 208b490 into facebook:master Mar 16, 2018
LeonYuAng3NT pushed a commit to LeonYuAng3NT/react that referenced this pull request Mar 22, 2018
* 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
rhagigi pushed a commit to rhagigi/react that referenced this pull request Apr 19, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants