Giter VIP home page Giter VIP logo

Comments (18)

ctrlplusb avatar ctrlplusb commented on September 10, 2024 1

All, I am almost done with 1.0.0-alpha.2, which includes significant improvements towards supporting hot reloading, including React Hot Loader. So far it is working swimmingly, but I need to put it through some of my larger projects to know for sure.

This should land within a few days.

from react-async-component.

plhosk avatar plhosk commented on September 10, 2024

As a temporary workaround it started working when I replaced

      <Match pattern="/" exactly component={IntroductionAsync} />

with the following:

      <Match
        pattern="/"
        exactly
        render={() => {
          const AsyncComponent = createAsyncComponent({
            resolve: () => System.import('./Introduction'),
          })
          return <AsyncComponent />
        }}
      />

(EDIT: This workaround is not recommended and will cause rendering issues)

Any idea why it wasn't working when I had the code for createAsyncComponent in its own file?

from react-async-component.

carsonxyz avatar carsonxyz commented on September 10, 2024

Experiencing the same issue myself.

from react-async-component.

swernerx avatar swernerx commented on September 10, 2024

Ooops. The fix would be problematic as it recreates the binding for each render. I don't think that would be a good idea.

from react-async-component.

carsonxyz avatar carsonxyz commented on September 10, 2024

@swernerx I noticed that as well when I tried it and saw that the component was being lazy loaded again and again.

@ctrlplusb could this be a bug or an implementation issue?

from react-async-component.

ctrlplusb avatar ctrlplusb commented on September 10, 2024

Woops, replied on the wrong thread.

To be honest I expect RHL will give us issues but so far my personal experience has been okay. It would be good to document where and when the hot reloading stops.

Falling back to standard webpack hot reloading is more reliable, but you sacrifice state maintenance.

from react-async-component.

ctrlplusb avatar ctrlplusb commented on September 10, 2024

Yep, agreed with @swernerx - that workaround is not recommended. Your component will always be lazy loaded which could lead to render flashing.

from react-async-component.

plhosk avatar plhosk commented on September 10, 2024

Thanks, I edited my comment with a warning. Hopefully a real solution can be found.

from react-async-component.

bradbarrow avatar bradbarrow commented on September 10, 2024

Hi folks, I'm experiencing the same.

I'm working in a react-universally repo from a month or so ago.

I just updated from code-split-component and left most of the rest of the app alone. I've followed the approach recommended in the README but I have the same issue as above - HMR logs in console with no actual updates.

from react-async-component.

wmertens avatar wmertens commented on September 10, 2024

There was an issue with HMR 3 but that has been fixed now gaearon/react-hot-loader#303 - is that what you are seeing?

from react-async-component.

GuillaumeCisco avatar GuillaumeCisco commented on September 10, 2024

It works great for me with react-hot-loader and current or alpha version of react-async-component.
I use this piece of code:

import 'babel-core/register';
import 'babel-polyfill';

import FastClick from 'fastclick';
import React from 'react';
import {render} from 'react-dom';
import {createRenderer} from 'fela';
import {Provider} from 'react-fela';
import {AsyncComponentProvider} from 'react-async-component';
import injectTapEventPlugin from 'react-tap-event-plugin';
import {AppContainer} from 'react-hot-loader';
import Root from './app/Root/index';
import configureStore from './app/configureStore/index';

const store = configureStore();

FastClick.attach(document.body);
// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
injectTapEventPlugin();

const root = document.getElementById('root');
const renderer = createRenderer();
const mountNode = document.getElementById('stylesheet');
const app = <AsyncComponentProvider>
    <Provider renderer={renderer} mountNode={mountNode}>
        <Root {...{store}} />
    </Provider>
</AsyncComponentProvider>;

const renderHotApp = (RootElement) => {
    render(<AppContainer key={Math.random()}>
        <AsyncComponentProvider>
            <Provider renderer={renderer} mountNode={mountNode}>
                <RootElement {...{store}} />
            </Provider>
        </AsyncComponentProvider>
    </AppContainer>, root);
};


if (process.env.NODE_ENV !== 'production') {
    if (module.hot) {
        module.hot.accept('./app/Root/index', () =>
            System.import('./app/Root/index').then(module =>
                renderHotApp(module.default),
            ),
        );
    }
    renderHotApp(Root);
}
else {
    render(app, root);
}

Note that I use:

<AppContainer key={Math.random()}>

Otherwise, the async-ed components are not loaded.
I use react-router v4 and react-fela :)

from react-async-component.

ctrlplusb avatar ctrlplusb commented on September 10, 2024

Hey all;

React hot loader works with alpha-2 release 🎉

I'll be updating the next branch of react-universally soon.

from react-async-component.

GuillaumeCisco avatar GuillaumeCisco commented on September 10, 2024

Hey @ctrlplusb I've just tested the alpha-2 release, it is the same for my settings.
I still need to put:

<AppContainer key={Math.random()}>

Is this normal?

from react-async-component.

ctrlplusb avatar ctrlplusb commented on September 10, 2024

Hmmm, no that shouldn't be the case, but RHL can be very fidgety to get working, and there are definitely some cases where it won't work at all.

Take a look at my starter kit for an example of how I set it up. I have it hot reloading in there pretty well. 👍

from react-async-component.

GuillaumeCisco avatar GuillaumeCisco commented on September 10, 2024

Thank you @ctrlplusb
I've just looked at your setup and tried to reproduce it but I have the same issue.
I need module.hot.accept and key={Math.random()}

But I used one of your file which is very clever ReactHotLoader.js -> https://github.com/ctrlplusb/react-universally/blob/d71b1e4475b31155260ea7ad3d793890aef5aed4/client/components/ReactHotLoader.js

My new setup is now simplier:

/* globals document */

import 'babel-core/register';
import 'babel-polyfill';

import FastClick from 'fastclick';
import React from 'react';
import {render} from 'react-dom';
import {createRenderer} from 'fela';
import {Provider as FelaProvider} from 'react-fela';
import {AsyncComponentProvider} from 'react-async-component';
import injectTapEventPlugin from 'react-tap-event-plugin';
import ReactHotLoader from './ReactHotLoader';
import Root from './app/Root/index';
import configureStore from './app/configureStore/index';

const store = configureStore();

FastClick.attach(document.body);
// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
injectTapEventPlugin();

const root = document.getElementById('root');
const renderer = createRenderer();
const mountNode = document.getElementById('stylesheet');

const renderApp = RootElement => {
    const app = <ReactHotLoader key={Math.random()}>
        <AsyncComponentProvider>
            <FelaProvider renderer={renderer} mountNode={mountNode}>
                <RootElement {...{store}} />
            </FelaProvider>
        </AsyncComponentProvider>
    </ReactHotLoader>;

    render(app, root);
};

if (process.env.NODE_ENV !== 'production' && module.hot) {
    module.hot.accept('./app/Root/index', () =>
        System.import('./app/Root/index').then(module => renderApp(module.default)),
    );
}

renderApp(Root);

My RootElement includes the Router because it is different when I'm in dev or prod environment ;)

from react-async-component.

gooddaddy avatar gooddaddy commented on September 10, 2024
    "react-async-bootstrapper": "^1.1.2",
    "react-async-component": "^1.0.2",
   "react": "^16.0.0",
    "webpack": "^3.8.1",
    "webpack-dev-middleware": "^1.12.0",
    "webpack-hot-middleware": "^2.20.0",

I still need to put:
<AppContainer key={Math.random()}>,
If I do not, it will not work properly, always second times to take effect(如果不这样做,它会不正常工作,总是第二次才生效)。

from react-async-component.

rhyek avatar rhyek commented on September 10, 2024

I also need to use <AppContainer key={Math.random()}>, but I've noticed reloading works fine without it for components not connected to redux. Connected components only reload for every other change.

from react-async-component.

rhyek avatar rhyek commented on September 10, 2024

Fyi, connected components only reloading every other change is no longer an issue with react-hot-loader 4 beta 7.

from react-async-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.