-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
webpack survey #341
Comments
done() |
Did. |
@sokra Thanks for taking time to answer on SO. I still spent an hour struggling to enable HMR because it is only briefly mentioned on this page that you need to enable |
Oh my god. Now that you explained it, I tried HMR and it blew me away. Hot module replacement is the most exciting thing I've seen in frontend dev since React. You really need to explain and document the hell out of this feature. It's the freaking future of frontend dev. |
@gaearon Yes it's pretty cool. @gaearon @rpflorence I merged your videos about Code Splitting and Hot Module Replacement with React and now there is this loader which decorates a React component with Code Splitting and Hot Module Replacement. You need to change only one line... 😄 cc @petehunt |
💣 |
I haven't had time to check yet so.. Will this reconcile DOM, or will it force re-render of the component? Keeping the DOM proved real hard for me. (Although it was night and I didn't think very hard.) I really wanted the update to occur without doing In my demo, I had to replace component's So this is roughly the code I had (I know but it was 5am): var mounted = [];
if (module.hot) {
module.hot.accept('./cover', function () {
var OldCover = sectionWidgets['cover'];
Cover = require('./cover');
sectionWidgets['cover'] = Cover;
window.IGNORE_SHIT = true;
_.each(mounted, function (s) {
_.each(s._renderedComponent._renderedChildren, function (child) {
if (child.__proto__ === (new OldCover.componentConstructor()).__proto__) {
child.__proto__ = (new Cover.componentConstructor()).__proto__;
}
});
s.forceUpdate();
});
window.IGNORE_SHIT = false;
}); function shouldUpdateReactComponent(prevComponentInstance, nextDescriptor) {
// TODO: Remove warning after a release.
if (prevComponentInstance && nextDescriptor &&
- (prevComponentInstance.constructor === nextDescriptor.constructor) && (
+ (prevComponentInstance.constructor === nextDescriptor.constructor || window.IGNORE_SHIT) && (
(prevComponentInstance.props && prevComponentInstance.props.key) ===
(nextDescriptor.props && nextDescriptor.props.key)
)) { I was thinking that, in order to support hot-swapping without cc @petehunt regarding last paragraph |
I created a "proxy" React component which has the real component in it's The Code Splitting part works similar by calling |
What's the easiest way to launch the example? I tried |
|
Says If I do
|
ups... I hold my repos in a |
If I edit Component C, it unmounts (before re-mounting again). You can say this by componentWillUnmount: function () {
window.alert('Ouch! Unmounting :-(');
} and trying to switch to "Component C (other param)". Its state also is reset on updates: getInitialState: function () {
return {
counter: 0
};
},
render: function() {
return (
<p onClick={this.incrementCounter}>
This is component C ({this.props.param}).
<br />
My state is {this.state.counter}.
</p>
);
},
incrementCounter: function () {
this.setState({
counter: this.state.counter + 1
});
} (If you click on it a couple times and then edit, it'll get back to 0.) What would be really cool is if React allowed us to preserve state (and DOM) between updates. I imagine it could work like this:
I think it requires some support in React core. This would enable true hot swapping. |
See this:
When we load the next version, React thinks it's a totally different component and bails out of reconciliation. |
Actually I tried to move the state to the new component, but react gave me some warnings that I shouldn't access The reconciliation is really a problem. Is it possible to override this behavior? But if we would tell React that it's the same component it wouldn't update it:
It doesn't seem to be possible without accessing react internals... I need to start reading react sources... |
Relevant file is (I re-read your last comment and yeah, that's exactly what you said :-). From my chat with @vjeux, it seems that changing We need to substitute React component instance on-the-fly without unmounting. |
We need help from a react developer... |
cc @spicyj @sebmarkbage @petehunt who may be able to help |
So I've said "webpack doesn't read source maps" in the survey... But then I've discovered that it does, it's just in a separate plugin. So I guess this should be more clearly documented? |
The problem is that references to component descriptors could be stored in any number of places. What we could do is wrap all components in "proxy" components which look up the "real" component in some mapping. Then all we'd have to do is rehydrate the state of each component instance which is easy: keep a state table keyed by (_rootNodeID, _mountDepth) and update it on componentDidUpdate(). Basically would add a local version of https://github.com/petehunt/react-multiplayer/blob/master/index.js to every component by default. Easiest way to implement this would be to monkeymatch |
I tried this. I serialized all states in the tree before a component update and called https://github.com/webpack/react-proxy-loader/blob/tree-state/mixinReactProxy.js#L19-L24 Ok let us assume we would inject the state correctly (or don't have state at all). There is still the problem that the DOM nodes are completely removed. This makes sense accoring to the documentation, because the new component is not the same as the old component, but here they may have very similar sub-trees.
Now it's an issue. Can I opt-in for react doing this for a single component? I. e. something like |
Lets start with some simple charts from the survey. project importance
Looks pretty promising... project size (modules count)
instagram.com has over 1000 modules. 😄 Maybe @petehunt reveals more stats in his talk at OSCON... features
(top 10 used/planed features) |
I think Pete suggested something different than what I've seen you try. Implementing a proxy class that forwards method calls to the freshest component version and monkey-patching This is probably beyond my current React/JS abilities but I'll try to play with this approach in my spare time. Edit: on a second thought, it's quite probable that I misunderstood Pete. Not sure. |
No you're correct, I did a bad job in describing it. You need to keep some sort of mapping from a class to all of its instances and overwrite each instance with the correctly autobound methods. |
Thanks for clarification. How would you go about overwriting autobound methods? I imagined it this way (but I'm not sure if this is possible or makes sense):
Basically I want something like |
I missed the part about the instances. But I'd need to keep track both of components and their descriptors? Or just the component instances? |
I think I got it working! Will publish in an hour or so. |
@sokra Can you please take a look at Edit: nevermind, I sorted it out |
@gaearon I see you already solved it. The The |
Thanks for the stats @sokra! |
The survey says that many people want to generate a stylesheet as separate file. So I focused on getting the #170 CSS bundle done. It should work now. I'll add a documentation page soon. Another complain was that the examples miss some documentation. So as next step I'll add a short text to each example. Than I'll create an example web app that features: react, separate stylesheet, server-side prerendering, hybrid routing with multiple entry points + History API, Code Splitting, long-term-caching and a commons chunk. |
dev tools
SourceMaps are booming... I didn't expected that much. interface
@shama A lot demand for the gulp-webpack integration... resource type
(top 10) JS was excepted, but CSS is also pretty big. I try to improve the CSS support (see above post). community
As expected... I'm working on that... but I need help. Everyone can edit the documentation. Please use this ability 😄 |
I finally wrote a blog post covering Hot Module Replacement with React. Thanks again for helping out and explaining stuff. |
Pretty awesome... I'll add it to the list of tutorials. Maybe you could add two new lifecycle methods You could also add a note about excluding stuff in your config: module: {
loaders: [
{ test: /\.jsx$/, loader: 'react-hot', exclude: [
/some-component\.jsx$/
] },
{ test: /\.jsx$/, loader: 'jsx' },
]
}, I would really like to see somebody using this in production... |
@gaearon that's one of the hottest things I've seen in front-end development for some time 😀 react's diff mechanism and webpack's hmr is a perfect match! |
Update 😄 project importance
project size (modules count)
features
(top 10 used/planed features) dev tools
interface
resource type
(top 10) community
|
I answered as "clearer examples" rather than "more examples". Last time I looked there was a lot of code to make authoring the examples easier which actually makes understanding them more difficult. |
Hey guys.
I would like to make a small survey about webpack usage. I would appreciate it, if you find some time to fill out this little survey.
The idea is to get more info about the users and the use cases, so I can focus on the important tasks.
I'll post a summary of the results in this issue.
Thanks
PS: Feel free to share it with other webpack users you know. Not everyone is reading github issues and I don't want to add a message into the library.
The text was updated successfully, but these errors were encountered: