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

Hooks are not working with webpack dll plugin #15447

Closed
yevhey opened this issue Apr 18, 2019 · 11 comments
Closed

Hooks are not working with webpack dll plugin #15447

yevhey opened this issue Apr 18, 2019 · 11 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@yevhey
Copy link

yevhey commented Apr 18, 2019

Do you want to request a feature or report a bug?
bug

What is the current behavior?
It compiles, but doesn't work.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
I created a repo with simple example and description of the problem:
https://github.com/yevhey/hooks-problem

What is the expected behavior?
It compiles the code and works as usual with webpack.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React/React dom – 16.8.6
browser – chrome 73
os – MacOS Mojave 10.14.4

in React 16.8.0 doesn't work as well.

@leeseean
Copy link

why you not show your code in this issue?

@yevhey
Copy link
Author

yevhey commented Apr 19, 2019

@leeseean no problem:

const Input = () => {
  useEffect(() => {
    console.log('Doesn\'t get here');
  }, []);

  return <input />;
};

Such basic hook doesn't work when exposed via webpack dll plugin.
Error is:

Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
  1. Versions are the same
  2. Rules of hooks are not breaking.
  3. App is compiled with one React from the outer folder.

@leeseean
Copy link

Only Call Hooks at the Top Level
Don’t call Hooks inside loops, conditions, or nested functions. Instead, always use Hooks at the top level of your React function. By following this rule, you ensure that Hooks are called in the same order each time a component renders. That’s what allows React to correctly preserve the state of Hooks between multiple useState and useEffect calls. (If you’re curious, we’ll explain this in depth below.)

Only Call Hooks from React Functions
Don’t call Hooks from regular JavaScript functions. Instead, you can:

✅ Call Hooks from React function components.
✅ Call Hooks from custom Hooks (we’ll learn about them on the next page).
https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

@yevhey
Copy link
Author

yevhey commented Apr 19, 2019

@leeseean I am doing the same.

@o-alexandrov
Copy link

o-alexandrov commented May 6, 2019

cc @mui-org

Please be informed that the issue definitely exists.
I stumbled upon it when trying out the latest 4.0.1 beta version of Material UI.

You can use the example project of Material UI to reproduce the issue.

If you add following packages as part of your DLL for development, then these two packages would stop working as React Hooks are broken when prebundled:

  • "@material-ui/styles"
  • "@material-ui/core"

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 17, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Jan 17, 2020
@o-alexandrov
Copy link

Not stale. The issue could save tremendous bundling time as mostly 80% of a typical list of dependencies on the frontend of a react developer are related to this issue.

Since hooks break on prebundling, the developers have to avoid prebundling on react related dependencies.

Please be clear, if you plan to support it.

@wibed
Copy link

wibed commented Nov 30, 2020

is there any activity, news on this issue?

this implies it works out of the box:
gaearon/react-hot-loader#1088 (comment)

@leo-bo
Copy link

leo-bo commented Apr 6, 2021

Came here from an issue in material-ui.
Stumbled upon it too. I wonder if there' any activity or news on it.

@ravihamsa
Copy link

any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

6 participants