-
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
Sub render #830
Sub render #830
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example needs cleaning, I think we need more test on this.
examples/async-portals/package.json
Outdated
"webpack-dev-server": "^2.9.7" | ||
}, | ||
"dependencies": { | ||
"emotion": "^8.0.12", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do not need emotion in this project.
render() { | ||
return ( | ||
<span> | ||
+{this.state.count}:{this.gen++} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples should reflect real examples, I think this is not a real example. I suggest to create a simple Portal example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or an Async Portal but without tricky things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using them for debug purposes. They reflect only the pure idea of RHL - don't lose the state.
This example is a good one, cos it actually not working for sync portal, as described above.
module: { | ||
rules: [ | ||
{ | ||
//exclude: /node_modules|packages/, // should work without exclude |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excluding node_modules
is a good thing, please add it and remove comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long CRA will not exclude node_modules and some projects might follow the same approach - we shall be ready (and we are ready).
class AsyncComponent extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have class properties 😁.
return element | ||
} | ||
|
||
setStandInOptions({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definitely merge projects.
@@ -63,7 +64,7 @@ describe('hot (dev)', () => { | |||
wrapper.unmount() | |||
}) | |||
|
|||
it('should redraw component on HRM', done => { | |||
it.only('should redraw component on HRM', done => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😨
Codecov Report
@@ Coverage Diff @@
## next #830 +/- ##
=======================================
+ Coverage 85% 86.21% +1.2%
=======================================
Files 23 25 +2
Lines 507 573 +66
Branches 96 151 +55
=======================================
+ Hits 431 494 +63
- Misses 61 62 +1
- Partials 15 17 +2
Continue to review full report at Codecov.
|
Running beta.21, this doesn't seem to be the case. Unless I wrap the async component with |
@joshjg - so two questions:
import {setConfig} from 'react-hot-loader';
setConfig({debug: true}); And the check the console output. Something should be inside. When you |
And webpack handles the rest.
|
During hot replacement RHL will not trigger |
Correct, I have the root component on the top level wrapped with |
That's mean that React-Hot-Loader is not working for something between top-level component and loader.
|
The loader component is the one that unmounts. None of its ancestors unmount. |
So, @joshjg, could you share some code. There must a reason(or a bug) to unmount. |
class ModuleLoader extends React.Component {
static propTypes = {
moduleId: PropTypes.string.isRequired,
moduleName: PropTypes.string.isRequired
};
state = { Component: null };
componentDidMount() {
this.mounted = true;
import(
/* webpackChunkName: "[request]" */
`modules/${this.props.moduleName}/src`
).then(({ default: Component }) => {
if (this.mounted) {
this.setState(() => ({ Component }));
}
});
}
componentWillUnmount() {
this.mounted = false;
}
render() {
const { Component } = this.state;
if (Component) {
return <Component {...this.props}/>;
}
return <Placeholder/>;
}
} |
Normal class 🤷♂️
|
FYI - beta 22 did not fix this issue |
@joshjg, in this case, I'll ask for some example to reproduce. |
@theKashey Couple things
Which is this line: https://github.com/gaearon/react-hot-loader/blob/next/src/reconciler/hotReplacementRender.js#L125 |
I've got the idea, easy to fix, but lets double check.
Do you have such code? |
Yes, I use that pattern all over. |
Ok, let me write red tests first. |
This implements idea behind #806 - each Component become a AppContainer.
How - just via pre-render hook it will pre-hot-render tree as AppContainer can do.
Difference - it will do it on Component
render
, and force-update afterwards. AppContainer is still needed(preferred) to force sync update.Solves:
hot
- they are all hotAnyway - this feature brings stability, and could solve close to any render quiz, we can get. I am not touching hot-render here, but it could be heavy simplified due to multiple "reconcile" points.