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

Separate current owner and dispatcher #14548

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jan 8, 2019

This is part tech-debt cleanup, since the dispatcher didn't really belong in the owner ref to begin with.

Also this will be used by the DevTools to support hooks. DevTools need a way to modify the current dispatcher, so renderers will need to inject this ref at runtime.

Note that external libraries depending on React internals may be impacted by this, but there are migration strategies involving feature detection and in general, we don't really support accessing the internals data structure.

@TrySound
Copy link
Contributor

TrySound commented Jan 8, 2019

Could you mention this in changelog? Me and probably somebody else use currentOwner to read from context since v16.6

@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 8, 2019

Sure. We can add an entry to the changelog about this, since it impacts libraries like Relay.

In Relay's case, they would need to change this to something more like this:

const React = require("React");

const {ReactCurrentDispatcher, ReactCurrentOwner}
  = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

function readContext<T>(Context: React.Context<T>): T {
  const dispatcher =
    ReactCurrentDispatcher != null
      ? ReactCurrentDispatcher.current
      : ReactCurrentOwner.currentDispatcher;
  return dispatcher.readContext(Context);
}

module.exports = readContext;

cc @kassens

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.

4 participants