react-tap-event-plugin icon indicating copy to clipboard operation
react-tap-event-plugin copied to clipboard

adding injectTapEventPlugin() break my hot-reload setup

Open sulliwane opened this issue 9 years ago • 20 comments

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:

  • https://github.com/mxstbr/react-boilerplate
  • https://github.com/kriasoft/react-starter-kit

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.

sulliwane avatar Feb 22 '16 00:02 sulliwane

@sulliwane did you solve or figured out about this?

diegoaguilar avatar Apr 04 '16 10:04 diegoaguilar

Just wrap in a try catch. Quick 'hacky' fix.

julienvincent avatar Apr 07 '16 22:04 julienvincent

I've tried to reproduce this, do you get any other errors in the console output?

madjam002 avatar Apr 11 '16 10:04 madjam002

I only received the error while using jspm's hot reloader, not webpack. I don't have the environment that was producing the error on hand, but this is the code that produced it:

  alreadyInjected = true;

  require('react/lib/EventPluginHub').injection.injectEventPluginsByName({
    'TapEventPlugin':       require('./TapEventPlugin.js')(shouldRejectClick)
  });

Here is the blob

Hope that helps.

Note: I do realise that this is more a problem with my hot-reload setup then with your library

julienvincent avatar Apr 11 '16 11:04 julienvincent

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;
}

peteruithoven avatar Apr 11 '16 15:04 peteruithoven

That is definitely a cleaner way of doing it. Can I just point out you wrote hotStore.tabInjected instead of hotStore.tapInjected. Sorry - just my OCD acting up ;)

julienvincent avatar Apr 11 '16 16:04 julienvincent

@julienvincent I'm a bit confused, any way to use injectTabEventPlugin and still get webpack's hot reload working? I generally use ES6 module imports.

diegoaguilar avatar Apr 11 '16 16:04 diegoaguilar

@diegoaguilar I have never experienced any issues with webpack hot-reloading and this plugin. What would be helpful in finding the issue is creating a bare, minimal repo that uses the latest webpack, babel (or whatever your transpiler is) and injectTabEventPlugin.

julienvincent avatar Apr 11 '16 16:04 julienvincent

If said repo still fires the error you are experiencing, then link it here

julienvincent avatar Apr 11 '16 16:04 julienvincent

@julienvincent Thanks, fixed it.

peteruithoven avatar Apr 11 '16 16:04 peteruithoven

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

nomadtechie avatar Jul 04 '16 23:07 nomadtechie

import React, {Component} from 'react';
import injectTapEventPlugin from 'react-tap-event-plugin';

class App extends Component {
  componentWillMount() {
    injectTapEventPlugin();
  }
  render() {...};
}

extonec avatar Aug 25 '16 15:08 extonec

@extonec - that still gives me the same issue. Strange that it works for you.

class App extends Component {
	componentWillMount() {
		// Needed for onTouchTap 
		// http://stackoverflow.com/a/34015469/988941 
		injectTapEventPlugin()
	}

	render() {
		return (
			<Provider store={store}>
				<MuiThemeProvider>
					<Router history={browserHistory}>
						{routes}
					</Router>
				</MuiThemeProvider>
			</Provider>
		)
	}
}

const render = () => {ReactDOM.render(<App />, document.getElementById('app'))};
store.subscribe(render);
store.subscribe(() => console.log(store.getState()))
render();

Yields:

bundle.js:1710 [HMR] Cannot check for update (Full reload needed)handleError @ bundle.js:1710applyCallback @ bundle.js:1640hotApply @ bundle.js:526cb @ bundle.js:1647hotUpdateDownloaded @ bundle.js:310hotAddUpdateChunk @ bundle.js:282webpackHotUpdateCallback @ bundle.js:4(anonymous function) @ 0.8cd3b21….hot-update.js:1
bundle.js:1711 [HMR] Invariant Violation: injectTapEventPlugin(): Can only be called once per application lifecycle.

	It is recommended to call injectTapEventPlugin() just before you call 	ReactDOM.render(). If you are using an external library which calls injectTapEventPlugin() 	itself, please contact the maintainer as it shouldn't be called in library code and 	should be injected by the application.
    at invariant (http://localhost:3001/static/bundle.js:30063:16)
    at injectTapEventPlugin (http://localhost:3001/static/bundle.js:30003:6)
    at App.componentWillMount (http://localhost:3001/static/bundle.js:1844:39)
    at http://localhost:3001/static/bundle.js:17272:24
    at measureLifeCyclePerf (http://localhost:3001/static/bundle.js:16999:13)
    at ReactCompositeComponentWrapper.performInitialMount (http://localhost:3001/static/bundle.js:17271:10)
    at ReactCompositeComponentWrapper.mountComponent (http://localhost:3001/static/bundle.js:17182:22)
    at Object.mountComponent (http://localhost:3001/static/bundle.js:9752:36)
    at ReactCompositeComponentWrapper.performInitialMount (http://localhost:3001/static/bundle.js:17295:35)
    at ReactCompositeComponentWrapper.mountComponent (http://localhost:3001/static/bundle.js:17182:22)

natdm avatar Nov 23 '16 15:11 natdm

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();

peteruithoven avatar Nov 23 '16 16:11 peteruithoven

Sorry maybe is me, but I've react 15.5.4 and react-tap-event-plugin 2.0.1, and i suffer the same error where i've to call injectTapEventPlugin()?

Gabber avatar May 26 '17 12:05 Gabber

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

olyakostuik avatar Jun 05 '17 09:06 olyakostuik

Putting it next to my render method doesn't work for me. Why does this happen in the first place?

ralexand56 avatar Jun 22 '17 03:06 ralexand56

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.

creeperyang avatar Aug 10 '17 06:08 creeperyang

@creeperyang PR #106 is open with error "This branch has conflicts that must be resolved" Conflicting files: src/injectTapEventPlugin.js

kfern avatar Feb 19 '18 15:02 kfern

@kfern Just long time after I opened my pr.

creeperyang avatar Feb 21 '18 16:02 creeperyang