Open sulliwane opened 8 years ago
@sulliwane did you solve or figured out about this?
Just wrap in a try catch. Quick 'hacky' fix.
I've tried to reproduce this, do you get any other errors in the console output?
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)
});
Hope that helps.
Note: I do realise that this is more a problem with my hot-reload setup then with your library
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;
}
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 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 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.
If said repo still fires the error you are experiencing, then link it here
@julienvincent Thanks, fixed it.
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
import React, {Component} from 'react';
import injectTapEventPlugin from 'react-tap-event-plugin';
class App extends Component {
componentWillMount() {
injectTapEventPlugin();
}
render() {...};
}
@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)
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();
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 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.
Putting it next to my render method doesn't work for me. Why does this happen in the first place?
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 PR #106 is open with error "This branch has conflicts that must be resolved" Conflicting files: src/injectTapEventPlugin.js
@kfern Just long time after I opened my pr.
After I add this:
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.