-
Notifications
You must be signed in to change notification settings - Fork 801
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
webpack2 + hot-reload: Not works with System.import #303
Comments
Hi, I'd like to take a look at this. I have yet to mess around much with Webpack 2. Do you have a (minimal) project that reproduces the issue? |
I recently got my boilerplate working properly with System.imports without any RHL workarounds. Originally I had issues when doing static path System.imports, like so: System.import('../components/Foo') RHL would not hot reload them the moment I navigated to another route of my application. As a workaround I used to have to do hard require statements whilst in dev mode: if (process.env.NODE_ENV === 'development') {
require('../components/Foo');
} This was tedious to say the least as my async routes grew. I then introduced an expression based version of my System.import, for example: function asyncAppViewResolver(viewName) {
return (nextState, cb) =>
System.import('../components/App/views/' + viewName + '/index.js')
.then(module => cb(null, module.default))
.catch(err => console.log(err));
}
const routes = (
<Route path="/" component={App}>
<IndexRoute getComponent={asyncAppViewResolver('Home')} />
<Route path="about" getComponent={asyncAppViewResolver('About')} />
</Route>
); This is more concise, and strangely enough I no longer need to do any workarounds to get RHL working with this. I suspect the way that webpack wraps these kinds of statements plays nicer with RHL. You can try it out from my repo: https://github.com/ctrlplusb/react-universally |
Thanks for the example @ctrlplusb, we should definitely put this in our docs. Do you think the issue with static path |
This is definitely a bug.
Happening here: modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId)); |
@birkir: I'm not sure where that comes from without more context. What version of RHL/Webpack, and do you have a simple repo project? Also, it might not strictly fall under this issue, so please open a new issue if you think it's a problem with React Hot Loader. |
Oh yeah, sorry. ueno-llc/starter-kit-historical#16 I get this error on the first request to the server, once i hot reload (any code) everything starts to work as normally. |
Hey @ctrlplusb. Regarding your workaround. I've built out async route splitting / chunking using react router too with Webpack 2 and I got all my containers / routes loading on-demand with While in dev mode, I get the following:
All nice and fine,
as expected. Function gets called, module replacement happensss .... but then it doesn't. The UI never updates, the new component never gets rendered. I tried changing the new components (new meaning the one I'm trying to update) render to also log something on the console. Never gets called. No log, no render. I will try your workaround now and see if that helps. So if that works.. I can officially confirm this one. Unfortunately. Maybe I'm not on the right track, but I'm running out of ideas now. |
Update: using That can get out hand real quick though. Even with the
Update:
|
@ctrlplusb I looked at what I had and compared with yours, and it's basically the same.
Here's a group:
And some route definitions:
I cannot get it to work though. HMR does happen, I get the update, but the old component never updates. If anyone can provide some assistance it'd be most welcome. Also, I can confirm that I isolated the problem and it is Thank you! |
Just hit this, and I have the same symptoms/conclusion as @elodszopos. Components belonging to an async chunk will log, to the console, as if they have been updated, but their appearance in the UI doesn't change. Even if the component is something simple like only returning This also happens if the component is imported through a hoisted As this is an accept for a sync import Component from './module/request'
module.hot.accept('./module/request', acceptCallback) is compiled as (whitespace / newlines added, identifiers simplified for readability): /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__module_request__ =
__webpack_require__(/*! ./module/request */ "moduleId");
module.hot.accept(/*! ./module/request */ "moduleId",
function(__WEBPACK_OUTDATED_DEPENDENCIES__) {
/* harmony import */ __WEBPACK_IMPORTED_MODULE_4__module_request__ =
__webpack_require__(/*! ./module/request */ "moduleId");
(acceptCallback)(__WEBPACK_OUTDATED_DEPENDENCIES__);
}
); EDIT: to clarify, the |
Correction: hot reloading actually does work, but only in one of the copies of the component. Only last component to be rendered in the first pass gets updated. Is webpack losing the EDIT: looks like webpack only keeps the last callback. I changed my code to a method where I keep track of each callback, and execute all of them in the callback actually given to module.hot.accept. |
Just a little update. I fixed the issue by invalidating the first build from webpack. So to sum up, hot reloading system.imported code would only work on the second time the webpack builds. I don't know if I'm just using hot reloader the wrong way, but It's very similar to @ctrlplusb solution. https://github.com/ueno-llc/starter-kit/blob/master/webpack/dev.js#L118 |
Hi guys, I will have a look at your configurations to see if I can spot anything different to mine. Btw if you are using react router 4 it seems to play much nicer with RHL. I have a working example in here. Will report back soon with findings. |
Awesome @birkir @ctrlplusb. I'll give it a try with both of the (possible?) solutions to see if they work. Will report back as well. Also, if there's any info that you need from me to further clarify or possibly webpack / route setup, can provide that too. |
Did you guys found a solution for the HMR problem? I'm stuck with exactly same thing ... |
I kinda had the same problem. I'm currently running version 3.0.0-beta.2 with webpack@2.1.0-beta.12 It doesn't feel quite right though. |
Same problem here... |
Yep, I have the same isssue |
Here is the simplest demo. Code:
|
Just confirming that Webpack 2.2 has the same problem. It's probably in the way RHL handles the update? |
Worked around it by only using splitting for a prod build. See also https://github.com/luqin/react-router-loader to automate this in your webpack config based on filename/path. |
for me, this was causing HMR to fail in
|
Oh cool! I was doing something like "if dev then require else
system.import" your way is simpler ☺
…On Sun, Feb 19, 2017, 1:52 AM Mitch Robb ***@***.***> wrote:
for me, this was causing HMR to fail in System.imported components, which
was being done in react-router routes. The solution was simply require()ing
the modules at the top of the file if *DEV* === true (code that's
eliminated in the prod build). A little duplication but not too bad.
if (__DEV__) {
// require every module that will be System.import()ed below
require('./components/NotFound');
}
const notFoundRoute = {
path: '*',
getComponent: (nextState, cb) => {
System.import('./components/NotFound')
.then(loadRoute(cb))
.catch(errorLoading);
}
};
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#303 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADWloWnKn74FRLAkIX6BH6XiRobMmKnks5rd5I5gaJpZM4IklcJ>
.
|
As Does anyone have problems with the latests versions of webpack / webpack-dev-server and dynamic import? |
@wkwiatek, thanks for pointing that out. I didn't realize System.import had been deprecated. I did a global find/replace on
|
Thanks for reporting @olslash ! The question is whether your problem is connected to just dynamic import or rather asynchronous routes (with React Router). Don't you use React Router here? If yes -> we have another issue for that: #288 If not -> could you provide some repo with minimal setup that fails? |
Thanks for that link, I am using react router, and doing one of the tricks mentioned in there (forcing the root route to re-render on HMR updates) does fix the problem (poorly, but effectively shows that this is an RR issue). |
@wkwiatek why did you close this? Is it fixed now? |
@mqklin RHL v3 works with Webpack 2 final, and dynamic imports (see #303 (comment)). Most of the cases here are due to React Router v3 async loading issues (#288). If there is something more, let me know, I'll definitely reopen it! |
@wkwiatek check this https://github.com/mqklin/hot-loader-lazy-modules-bug webpack 2, RHL 3, the simplest config, no React Router. Doesn't work. |
I just copy-pasted your code into my playground and it worked. However, it's doing full reload (you're changing the state of the root component). I'll try to take a look later what's causing the issues in your repo. I bet there are some config-related problems (which are probably not covered in docs). |
Thank you for the example config. I can't use |
I totally understand, and RHL should work with both so we should investigate it deeper. Would you mind to create an issue for that (as related to webpack middlewares) with your specific example? I just don't want to mess in this thread which is really about |
Please look #490 |
The change is not applied. Webpack seems to generate a chunk with a new id with the changes for the chunk when using System.import.
The text was updated successfully, but these errors were encountered: