-
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
[React Hooks] Incompatibility with react-hot-loader #1088
Comments
Partially related |
Yes I've just seen the same. I tried removing my |
Yes. RHL is 100% not compatible with hooks. There is just a few reasons behind it:
I am going to draft a PR, to mitigate both problems. It will work, but not today. |
N.B. Does not currently work in Gatsby development mode due to incompatibilities with react-hot-loader. See RHL issue 1088. gaearon/react-hot-loader#1088 (comment)
This could be a workaround gatsbyjs/gatsby#9489 (comment) |
Next version of RHL, with 16.6 support will add
|
There is a more proper fix, which would work my better and ever after - cold API You may disable RHL for any custom type. import { cold } from 'react-hot-loader';
cold(MyComponent); or just search for "useState/useEffect" inside component source code, and ❄️it. import { setConfig, cold } from 'react-hot-loader'
setConfig({
onComponentRegister: (type, name, file) =>
(String(type).indexOf('useState') > 0 || String(type).indexOf('useEffect') > 0) && cold(type),
}) |
Meanwhile, everything depends on this - reactjs/rfcs#74 |
N.B. Does not currently work in Gatsby development mode due to incompatibilities with react-hot-loader. See RHL issue 1088. gaearon/react-hot-loader#1088 (comment)
I just set setConfig({ pureSFC: true }) |
Using index.js:1452 React-hot-loader: reconciliation failed could not dive into [ ƒ children(props) {
var child = _children(item, state, i);
return child ? child(props) : null;
} ] while some elements are still present in the tree. |
Probably
So - just don't use "hidden" components (ie not exported as a top level variables) - and that would be ok. |
PS: While we found a way to handle hooks, React.memo and lazy is not yet supported |
Who's gonna write the Babel plugin which auto adds this if it detects a hook import? 😘 |
Probably me. I already was used to introduce per-component settings to support React.memo, and the same would work for hooks. |
Styled-components v4 also reported not to work. One more thing to manage. |
N.B. Does not currently work in Gatsby development mode due to incompatibilities with react-hot-loader. See RHL issue 1088. gaearon/react-hot-loader#1088 (comment)
N.B. Does not currently work in Gatsby development mode due to incompatibilities with react-hot-loader. See RHL issue 1088. gaearon/react-hot-loader#1088 (comment)
N.B. Does not currently work in Gatsby development mode due to incompatibilities with react-hot-loader. See RHL issue 1088. gaearon/react-hot-loader#1088 (comment)
N.B. Does not currently work in Gatsby development mode due to incompatibilities with react-hot-loader. See RHL issue 1088. gaearon/react-hot-loader#1088 (comment)
v4.5.0(next) solves most of 16.6/16.7 issues and could handle anything if you will got your node_modules processed by our webpack-loader. |
import { hot } from 'react-hot-loader/root';
import { setConfig } from 'react-hot-loader';
setConfig({ pureSFC: true });
export default hot(withRouter(App), { errorBoundary: false }); Is this how I'm supposed to do it now? I also have webpack alias for the dom thing, and using the babel plugin. |
You might consider adding #1088 (comment) to the docs. |
@theKashey well i have hotreloading working perfectly without yarn link, but it is still giving that error even after doing setConfig. https://github.com/ntucker/anansi/tree/master/examples/typescript is the project. the yarn link is for rest-hooks |
Didn't see this anywhere in the comments here or other issues. I'm getting this when I change hooks in a component:
Is this a current known issue or limitation or due to an improper config? |
@natew - try changing the configuration. RHL is trying to re-render updated application, and that "custom" render is not hooks compatible. It was just failing with alpha versions, but it was not a big deal. I didn't test 16.8, and something may change. setConfig({
disableHotRenderer: true
}) |
I write a babel plugin for react hooks hot load, it wrap react hooks component with react component, https://github.com/yoution/babel-plugin-react-hooks-hot-load |
@yoution so this basically helps hooks HMR without the errors you see if you change them? |
@yoution - so you are wrapping every hooked-component with
I am thinking about proxy-regeneration - if an error is detected inside hooked-component (could be detected during hot-renderer, if it is enabled) - react-hot-loader will fail the comparison between the old and the new component, causing remount. "remount", and "reset" are proven fixtures |
@theKashey in my way, I use babel-plugin-react-transform other then react-hot-loader for hmr, but babel-plugin-react-transform does not support babel7, so I use metro-babel7-plugin-react-transform which is used by react-native hrm;as for forwarding refs, if you use refs in hook component, that may make no difference , if you want to use hooks from parent components, maybe I should add React.forwardRef in component which wrapping the hooks |
@natew in my project , it works well, what do you mean? |
|
Any updates on this? |
|
Description
The new react hooks API does not work with react-hot-loader. Using the example in my app with
export default hot(module)(App);
at the bottom of app.js, the following error occurs:Expected behavior
Should work.
Actual behavior
Reproducible Demo
Dunno of a demo is needed, just ping me if you need one.
The text was updated successfully, but these errors were encountered: