[Pagination] v5 usePagination requires @emotion
See original GitHub issueWhen simply using the usePagination
hook provided by MaterialUI, @emotion/styled
and @emotion/react
are mandatory dependencies, otherwise it will throw a Webpack build error:
Failed to compile.
./node_modules/@material-ui/styled-engine/index.js
Module not found: Can't resolve '@emotion/react' in '/Users/username/Documents/project/node_modules/@material-ui/styled-engine'
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
Does not compile unless @emotion
packages are installed
Expected Behavior 🤔
I would expect to be able to compile without an exception since no styles are actually used or needed when using the hook.
Steps to Reproduce 🕹
Codesandbox to reproduce the isse https://codesandbox.io/s/fluentui-use-paginate-7czwv?file=/src/components/Paginate/index.tsx
Steps:
- Remove the
@emotion
packages - Compilation exception
Context 🔦
We’re trying to use the new headless components (hooks) provided by MaterialUI, but without any styling requirements.
Your Environment 🌎
`npx @material-ui/envinfo`
System:
OS: macOS 11.4
Binaries:
Node: 16.4.2 - ~/.n/bin/node
Yarn: 1.22.10 - ~/.n/bin/yarn
npm: 7.18.1 - ~/.n/bin/npm
Browsers:
Chrome: 91.0.4472.114
Edge: Not Found
Firefox: Not Found
Safari: 14.1.1
npmPackages:
@material-ui/core: ^5.0.0-beta.0 => 5.0.0-beta.0
@material-ui/private-theming: 5.0.0-beta.0
@material-ui/styled-engine: 5.0.0-beta.0
@material-ui/system: 5.0.0-beta.0
@material-ui/types: 6.0.1
@material-ui/unstyled: 5.0.0-alpha.39
@material-ui/utils: 5.0.0-beta.0
@types/react: ^16.9.0 => 16.14.11
react: ^16.13.1 => 16.14.0
react-dom: ^16.13.1 => 16.14.0
typescript: ^4.1.2 => 4.3.5
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
[Pagination] v5 usePagination requires @emotion #27282
We're trying to use the new headless components (hooks) provided by MaterialUI, but without any styling requirements. Your Environment. `npx ...
Read more >React+ Hooks + Material-UI Pagination Example
@chakra-ui/core. 0.8.0 · @emotion/core. 10.0.17 · @emotion/styled. 10.0.17 · @material-ui/core. 4.11.0 · @material-ui/lab. 4.0.0-alpha.56 (4.0.0-alpha.56) · @reach/ ...
Read more >Breaking changes in v5, part two: core components
As the core components use Emotion as their style engine, the props used by ... -import { usePagination } from '@mui/lab/Pagination'; +import Pagination...
Read more >Pagination · Bootstrap v5.0
Documentation and examples for showing pagination to indicate a series of related content exists across multiple pages.
Read more >Examples: Row Selection With Pagination - React Table
tannerlinsley/react-table: row-selection-and-pagination ... \u003Cbody\u003E\n \u003Cnoscript\u003EYou need to enable JavaScript to run this app.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure, seems like a pretty low hanging fruit. There is a few more components that could simply be moved to unstyled. I’ll focus on these before taking on the next “big” one.
@mnajdova While I agree with all you said, I would like to raise a quick-win opportunity.
AFAIK the main issue of @MichielDeMey is that tree shaking is disabled in dev mode, usePagination imports core/utils, that imports SvgIcon, that imports system, that import styled, that imports emotion => his codesandbox break. So we force him to install emotion, and he might think that emotion will be bundled in production (it won’t, tree shaking kicks in prod mode).
Now, we could force the treeshaking in dev mode and call it a day 😁:
emotion is an optional peer dependency, nothing to install, no warnings.
Then fix the problem at the root (not the surface) with the unstyled package (to remove any fear that the developers might have, for social proof, etc.) in #27170.