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

HMR doesn't rerender components extended from BaseComponent #245

Closed
igor10k opened this issue Mar 6, 2016 · 17 comments
Closed

HMR doesn't rerender components extended from BaseComponent #245

igor10k opened this issue Mar 6, 2016 · 17 comments

Comments

@igor10k
Copy link

igor10k commented Mar 6, 2016

I've used foreman start -f Procfile.dev to start the server, went to localhost:3000. Opened Layout.jsx and tried changing some text, but nothing happened in the browser even though I see in the terminal that webpack sends the hot-update.
Then I tried replacing extends BaseComponent with extends React.Component which basically means I made shouldComponentUpdate always return true. After these changes modifying Layout.jsx was instantly reflected in the browser.
Something is definitely wrong since HMR should do .forceUpdate() for every changed component and rerender the component ignoring the shouldComponentUpdate.

@justin808
Copy link
Member

@igor10k Keep me posted on what you find out. If you figure out a good change, please submit a PR.

I've tested the hot reloading and changing the the JSX in the render method, and hot reloading works great.

@igor10k
Copy link
Author

igor10k commented Mar 7, 2016

@justin808 I made a 1-minute video showing the process and the difference when using BaseComponent and React.Component for Layout.jsx. I cloned the tutorial repo about 3 days ago, so it's quite fresh. I do a manual refresh in the video just once after I change BaseComponent to React.Component (and accidentally click the readme link 😃 ).

https://dl.dropboxusercontent.com/u/2526191/react_on_rails_hmr.mov

Maybe you are doing some other changes that do trigger the hot reloading.

@justin808
Copy link
Member

@igor10k We're not doing anything in particular. This sounds like a bug in the hmr.

@igor10k
Copy link
Author

igor10k commented Mar 8, 2016

@justin808 so are you having the same behavior?

@igor10k
Copy link
Author

igor10k commented Mar 9, 2016

@justin808 gaearon/react-transform-boilerplate#123

Fixed HMR by adding "superClasses": ["React.Component", "BaseComponent"] to the babel config.

@justin808
Copy link
Member

👏 Nice job @igor10k. Any chance that you can throw that in a document PR here: https://github.com/shakacode/react_on_rails/tree/master/docs/additional_reading

We can call the file "hot-module-replacement.md".

Thanks!

@igor10k
Copy link
Author

igor10k commented Mar 10, 2016

I don't think that there's a need for another doc. How about just adding that superClasses line to the config and adding a comment above describing it. Something like "Enable rerendering of the components extended from BaseComponent" should be enough.

@justin808
Copy link
Member

shakacode/react_on_rails#332 discusses the issues.

@marcelkooi
Copy link

I copied down the repo yesterday and I'm seeing the same issue. Changing the BaseComponent to React.Component fixed the problem. @igor10k Are you saying that you added that line to your .babelrc file? I seem to get an error when I do that.

@igor10k
Copy link
Author

igor10k commented Mar 16, 2016

@Marz0
In this case the line should be added to webpack.client.rails.hot.config.js like

{
  test: /\.jsx?$/,
  loader: 'babel',
  exclude: /node_modules/,
  query: {
    plugins: [
      [
        'react-transform', {
          superClasses: ['React.Component', 'BaseComponent', 'Component'],
          transforms: [
            {
              transform: 'react-transform-hmr',
              imports: ['react'],
              locals: ['module'],
            },
          ],
        },
      ],
    ],
  },
},

@igor10k
Copy link
Author

igor10k commented Mar 16, 2016

Btw, I decided to get rid of BaseComponent in favor of pure-render-decorator because there are also other things that depend on using the original class like eslint-plugin-react and I don't favor the idea of configuring every single plugin to work with BaseComponent.

@justin808
Copy link
Member

@seoyoochan Maybe this contains the fix we need?

@seoyoochan
Copy link
Contributor

@justin808 will check if this is the fix.

@justin808
Copy link
Member

@seoyoochan Any update?

@seoyoochan
Copy link
Contributor

@justin808 this was not related to my issue, stylesheet hrm rendering. It seems application_non_webpack.scss needs to be watched and hot reloaded.

@LinuCC
Copy link

LinuCC commented Apr 3, 2016

This really is a one-liner with the change to webpack.client.rails.hot.config.js @igor10k proposed, or a bit more (plus another babel-plugin) with the decorator.

Which of those two would you prefer, @justin808?

@justin808
Copy link
Member

I'm going to try out the one liner change to the config.js file and merge that if it works for me.

justin808 added a commit that referenced this issue Apr 4, 2016
See discussion:
#245
ryanbelke pushed a commit to ryanbelke/rails-react-yourtime that referenced this issue Jan 4, 2019
joseph0919 added a commit to joseph0919/React_Webpack_Rails_Tutorial that referenced this issue May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@justin808 @igor10k @seoyoochan @LinuCC @marcelkooi and others