1

Good day! Maybe it's a bad question, but I can't find answer on it. I have React app, that oriented on json object, that dynamically changes from outside.

Code from NAV:

   import MultiTable from '../multi';
   import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
   import Clock from '../clock'

   let routes = [
     {
       exact: true,
       path: '/Main',
       main: () => <Main />
     },
     {
       path: '/MultiTable',
       main: () => <MultiClock />
     }
   ];

   function requireAll(requireContext) {
     return requireContext.keys().map(requireContext);
   }

   const Configs = requireAll(require.context('../../../src/configs', false, /.json$/));
   const Files = requireAll(require.context('../../../src/data', false, /.json$/));

   const Multi = () => (
     <MuiThemeProvider>
       <MultiTable allData={[Files, Configs]}/>
     </MuiThemeProvider>
   );

   const MultiClock = () => (
     <div>
       <Clock/>
       <Multi/>
     </div>
   );

export default class Nav extends React.Component {
render() {
    return (
      <Router history='vah'>
        <div style={{display: 'flex'}} ref="nav">
          <Drawer
            docked={true}
            width={200}
          >
            <Link to='/Main' key="main">Main</Link>
            <Link to='/MultiTable' key="multi">WithClock</Link>
          </Drawer>
          <div style={{flex: 1}}>
            {routes.map((route, index) => (
              <Route
                key={index}
                path={route.path}
                exact={route.exact}
                component={route.main}
              />
            ))}
          </div>
        </div>
      </Router>
    );
  }
}

App forming tables from jsons and with hot-reloader on my dev-server I always see incoming information without full page refreshing. But when I adding new "static" component on Canvas - Clock - when something in Files or Configs changes - Clock refreshing too and blinking (showing that he is reloading).

In my logic: Clock doesn't cross with Files and Configs and must be not updated, when files changes.

Why this happening?

___UPD1: I want to understand why if changes some data in Multi, Element Clock is resreshing too and I don't need this, cause of blinking.

Example

___UPD2:

webpack config:

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: [
    'babel-polyfill',
    'react-hot-loader/patch',
    'webpack-dev-server/client?http://192.168.1.33:3000',
    'webpack/hot/only-dev-server',
    './app/index.js'
  ],
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, '../dist'),
    publicPath: '/static/'
  },
  module: {
    rules: [
      {test: /\.jsx?$/, use: ['babel-loader'], exclude: /node_modules/},
      {test: /\.(less|css)$/, loader: 'style-loader!css-loader!less-loader'},
      {test: /\.(xml)$/, loader: 'xml-loader'},
      {test: /\.(svg|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff|woff2)$/, loader: 'file-loader'}
    ],
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
  ],
  devServer: {
    host: '192.168.1.33',
    port: 3000,
    historyApiFallback: true,
    hot: true,
    compress: true
  }
};

in .babelrc:

{
  "presets": [
    ["es2015", {"modules": false}],
    "stage-2",
    "react"
  ],
  "plugins": [
    "react-hot-loader/babel"
  ]
}

Main entry /app/index.js:

import React from 'react';
import ReactDOM  from 'react-dom'
import {AppContainer} from 'react-hot-loader'
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import Nav from './navigation/nav';
import './index.less';

const rootEl = document.getElementById('root');
const render = Component => {
  ReactDOM.render(
    <AppContainer>
      <MuiThemeProvider>
        <Component />
      </MuiThemeProvider>
    </AppContainer>,
    rootEl
  )
};

render(Nav);

if (module.hot) {
  module.hot.accept('./navigation/nav', () => {
    render(Nav)
  })
}

Maybe I really done some errors in configs and don't fully understanding of how this technologies must work. hot-loader+webpack+router

ANTVirGEO
  • 124
  • 1
  • 16
  • You question is still not very clear, especially this part: `Clock - when something in Files or Configs changes - Clock refreshing too.` What exactly you want the behavior? – Nagaraj Tantri Aug 16 '17 at 10:07
  • @NagarajTantri added gif example of how it looks. And update question – ANTVirGEO Aug 16 '17 at 10:31
  • Could you provide the process of using webpack-hot-reload? I mean, have you used CLI of webpack-hot-reload or used config file to do so? Also show us the webpack configuration. If you can provide a sample github project, still better, as this issue is peculiar and would require understanding webpack-hot-reload/webpack configs – Nagaraj Tantri Aug 16 '17 at 11:31
  • @NagarajTantri, filled question with my code (sorry that can't provide github project). As you can see I'm using handmade webpack config. I think maybe something wrong with my Routing? – ANTVirGEO Aug 16 '17 at 14:30
  • 1
    basic error reporting, if you can check your dev console in chrome: https://stackoverflow.com/questions/37271499/react-webpack-hmr-is-refreshing-the-page-not-hot-loading – Nagaraj Tantri Aug 16 '17 at 15:09
  • @NagarajTantri, hm. `[WDS] Hot Module Replacement enabled. [WDS] App updated. Recompiling... [WDS] App hot update... [HMR] Checking for updates on the server... [HMR] Updated modules: [HMR] - ./app/navigation/nav.js [HMR] App is up to date. ` He reload all NAV component, that's why he reload Clock to. Hot-reload reload **NOT** that component that __USE__ files, but component which that files importing? Will try to relocate importing to component **MultiTable** and see results – ANTVirGEO Aug 17 '17 at 00:56
  • If all your Nav is getting reloaded, then that could be the sign, your page reload is getting triggered. If its the react router change being anticipated? – Nagaraj Tantri Aug 17 '17 at 02:11
  • @Nagaraj Tantri, yes you are right. I think problem in react router. I've just created new component (**preNav**) without any routes. Then render this component from main entry, and add to that component **NAV**, **Clock** and some json imports. Now some changes in **preNav**, **NAV** or even imported to **preNav** files don't cause **Clock* refreshing. I think, that i need more theory in how react-router + hot-loadder works together – ANTVirGEO Aug 17 '17 at 10:19

0 Answers0