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

Deprecate injecting custom event plugins #11690

Merged
merged 5 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/events/EventPluginRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import type {
} from './PluginModuleType';

import invariant from 'fbjs/lib/invariant';
import lowPriorityWarning from 'shared/lowPriorityWarning';

type NamesToPlugins = {[key: PluginName]: PluginModule<AnyNativeEvent>};
type EventPluginOrder = null | Array<PluginName>;

var shouldWarnOnInjection = false;

/**
* Injectable ordering of event plugins.
*/
Expand All @@ -29,6 +32,10 @@ var eventPluginOrder: EventPluginOrder = null;
*/
var namesToPlugins: NamesToPlugins = {};

export function enableWarningOnInjection() {
shouldWarnOnInjection = true;
}

/**
* Recomputes the plugin list using the injected plugins and plugin ordering.
*
Expand Down Expand Up @@ -221,6 +228,21 @@ export function injectEventPluginOrder(
export function injectEventPluginsByName(
injectedNamesToPlugins: NamesToPlugins,
): void {
if (__DEV__) {
if (shouldWarnOnInjection) {
const names = Object.keys(injectedNamesToPlugins).join(', ');
lowPriorityWarning(
false,
'Injecting custom event plugins (%s) is deprecated ' +
'and will not work in React 17+. Please update your code ' +
'to not depend on React internals. The stack trace for this ' +
'warning should reveal the library that is using them. ' +
'See https://github.com/facebook/react/issues/11689 for a discussion.',
names,
);
}
}

var isOrderingDirty = false;
for (var pluginName in injectedNamesToPlugins) {
if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,21 @@ describe('ReactBrowserEventEmitter', () => {

idCallOrder = [];
tapMoveThreshold = TapEventPlugin.tapMoveThreshold;
spyOnDev(console, 'warn');
EventPluginHub.injection.injectEventPluginsByName({
TapEventPlugin: TapEventPlugin,
});
});

afterEach(() => {
if (__DEV__) {
expect(console.warn.calls.count()).toBe(1);
expect(console.warn.calls.argsFor(0)[0]).toContain(
'Injecting custom event plugins (TapEventPlugin) is deprecated',
);
}
});

it('should store a listener correctly', () => {
registerSimpleTestHandler();
var listener = getListener(CHILD, ON_CLICK_KEY);
Expand Down
22 changes: 22 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,28 @@ describe('ReactDOM', () => {
}
});

// https://github.com/facebook/react/issues/11689
it('should warn when attempting to inject an event plugin', () => {
spyOnDev(console, 'warn');
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.EventPluginHub.injection.injectEventPluginsByName(
{
TapEventPlugin: {
extractEvents() {},
},
},
);
if (__DEV__) {
expect(console.warn.calls.count()).toBe(1);
expect(console.warn.calls.argsFor(0)[0]).toContain(
'Injecting custom event plugins (TapEventPlugin) is deprecated ' +
'and will not work in React 17+. Please update your code ' +
'to not depend on React internals. The stack trace for this ' +
'warning should reveal the library that is using them. ' +
'See https://github.com/facebook/react/issues/11689 for a discussion.',
);
}
});

it('throws in DEV if jsdom is destroyed by the time setState() is called', () => {
spyOnDev(console, 'error');
class App extends React.Component {
Expand Down
7 changes: 7 additions & 0 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,13 @@ const ReactDOM: Object = {
},
};

if (__DEV__) {
// Show deprecation warnings as we don't want to support injection forever.
// We do it now to let the internal injection happen without warnings.
// https://github.com/facebook/react/issues/11689
EventPluginRegistry.enableWarningOnInjection();
}

type RootOptions = {
hydrate?: boolean,
};
Expand Down