react-tap-event-plugin: adding injectTapEventPlugin() break my hot-reload setup

After I add this:

import injectTapEventPlugin from 'react-tap-event-plugin';

// Needed for onTouchTap
// Can go away when react 1.0 release
// Check this repo:
// https://github.com/zilverline/react-tap-event-plugin
injectTapEventPlugin();

Both of my hot reload setup don’t “hot reload” anymore:

If I remove it, then my changes on save are hot-reloaded in the browser (without the need to refresh the page).

any ideas?

thanks.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 8
  • Comments: 20

Most upvoted comments

injectTapEventPlugin(): Can only be called once per application lifecycle

Let’s the story, the place you’re calling it causes it to be called multiple times.

We moved the injection into a separate module, since this module doesn’t change it’s never reimported and therefore only executed once.

import injectTapEventPlugin from 'react-tap-event-plugin';

// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
// Used by Material-ui
injectTapEventPlugin();

How I’m doing this with the SystemJS hot reloader:

import getHotReloadStore from 'systemjs-hot-reloader-store';
const hotStore = getHotReloadStore('myproject:index'); // store for state over hot reloads

if (!hotStore.tapInjected) {
  injectTapEventPlugin();
  hotStore.tapInjected = true;
}

Seems my pr https://github.com/zilverline/react-tap-event-plugin/pull/106 will solve it.

I add isInjected function and If we use webpack and hot reload, just write code below:

import injectTapEventPlugin from 'react-tap-event-plugin'

if (!injectTapEventPlugin.isInjected()) {
  injectTapEventPlugin()
}

This will prevent the error occur.

@Gabber It is recommended to call injectTapEventPlugin() just before you call ReactDOM.render(). 1.Find ReactDOM.render() in your code 2.Put injectTapEventPlugin() on top of render() method.

Just wrap in a try catch. Quick ‘hacky’ fix.

hi guys–wondering if there is:

A) Consensus on a workaround for this B) If there is a fix for this now?

Thanks!

cc @guybedford