Skip to content
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

Question RE: adding/removing hooks... #4

Closed
drather19 opened this issue Dec 5, 2019 · 7 comments · Fixed by #26
Closed

Question RE: adding/removing hooks... #4

drather19 opened this issue Dec 5, 2019 · 7 comments · Fixed by #26

Comments

@drather19
Copy link

I've been trying this plugin out on a few CRA-based projects (based on steps mentioned here). So far, things work well in terms of preserving state during development as I edit my components and hooks.

Question: Anytime I add or remove hooks, I get the an error stating that the number of hooks has changed between renders. The component is not re-mounted. I have to force a subsequent reload to recover. Is this the expected behavior at the moment?

Expectation: Similar to the behavior when using Dan's old wonky-scripts experiment, adding/removing hooks should gracefully force a remount of the component if necessary rather than just bubbling the error all the way up.

I see the same behavior if I eject the CRA app and manually edit the webpack config per the README as well as if I use the feature branch version that hasn't yet been merged back to master.

Thanks for the work being put into bringing such a great React feature to web setups!

@pmmmwh
Copy link
Owner

pmmmwh commented Dec 6, 2019

Hey! Thanks for the issue.

I just shipped v0.1.0 (on npm) - I tested with the latest master and I wasn't able to reproduce what you're mentioning. Can you try it out and see if it works?

@drather19
Copy link
Author

I tried again with the latest released version and on master (nice overlay!), but do still see things error out when I add/remove hooks. Sorry for not adding a simple test, but simply adding/remove the following from a React.FC triggers the error overlay:

const callback = React.useCallback(() => {}, []);

It's not a big deal at this point (just an extra reload I can trigger by making more edits). I was mainly curious about whether this is the expected normal behavior.

Thanks!

@pmmmwh
Copy link
Owner

pmmmwh commented Dec 6, 2019

I tried again with the latest released version and on master (nice overlay!), but do still see things error out when I add/remove hooks. Sorry for not adding a simple test, but simply adding/remove the following from a React.FC triggers the error overlay:

const callback = React.useCallback(() => {}, []);

It's not a big deal at this point (just an extra reload I can trigger by making more edits). I was mainly curious about whether this is the expected normal behavior.

Thanks!

I'll have to check if I did something wrong. I am pretty sure state/reducer/refs work, let me check.

@gaearon
Copy link

gaearon commented Dec 6, 2019

I was mainly curious about whether this is the expected normal behavior.

No

@pmmmwh
Copy link
Owner

pmmmwh commented Dec 7, 2019

I tried again with the latest released version and on master (nice overlay!), but do still see things error out when I add/remove hooks. Sorry for not adding a simple test, but simply adding/remove the following from a React.FC triggers the error overlay:

const callback = React.useCallback(() => {}, []);

It's not a big deal at this point (just an extra reload I can trigger by making more edits). I was mainly curious about whether this is the expected normal behavior.

Thanks!

I couldn't reproduce this in a normal webpack app. I guess it might have something to do with integration between this and CRA. #7

@drather19
Copy link
Author

As mentioned in #25, I can resolve this in my CRA app by setting webpackConfig.optimization.runtimeChunk = false; via craco. Now everything seems to be working like a charm!

@pmmmwh
Copy link
Owner

pmmmwh commented Dec 19, 2019

Fixed in v0.1.3 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants