zilverline / react-tap-event-plugin

Instant TapEvents for React
http://facebook.github.io/react/
MIT License
1.07k stars 110 forks source link

adding injectTapEventPlugin() break my hot-reload setup #61

Open sulliwane opened 8 years ago

sulliwane commented 8 years ago

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.

diegoaguilar commented 8 years ago

@sulliwane did you solve or figured out about this?

julienvincent commented 8 years ago

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

madjam002 commented 8 years ago

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

julienvincent commented 8 years ago

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

peteruithoven commented 8 years ago

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;
}
julienvincent commented 8 years ago

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

diegoaguilar commented 8 years ago

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

julienvincent commented 8 years ago

@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 commented 8 years ago

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

peteruithoven commented 8 years ago

@julienvincent Thanks, fixed it.

nomadtechie commented 8 years ago

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

extonec commented 8 years ago
import React, {Component} from 'react';
import injectTapEventPlugin from 'react-tap-event-plugin';

class App extends Component {
  componentWillMount() {
    injectTapEventPlugin();
  }
  render() {...};
}
natdm commented 8 years ago

@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)
peteruithoven commented 8 years ago
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();
Gabber commented 7 years ago

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

olyakostuik commented 7 years ago

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

ralexand56 commented 7 years ago

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

creeperyang commented 7 years ago

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.

kfern commented 6 years ago

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

creeperyang commented 6 years ago

@kfern Just long time after I opened my pr.