-
Notifications
You must be signed in to change notification settings - Fork 78
feat: replace withStyles wrapper with useEffect and remove customStyles property #873
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
Conversation
Deploy preview for fundamental-react ready! Built with commit 25ae8ff |
@@ -23,6 +22,12 @@ class DatePicker extends Component { | |||
this.calendarRef = React.createRef(); | |||
} | |||
|
|||
componentDidMount() { | |||
if (!this.props.disableStyles) { | |||
require('fundamental-styles/dist/popover.css'); |
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.
This whole section can be removed if #858 is merged first. That rebuilds this with a popover so we get those styles from popover component.
@@ -498,6 +503,4 @@ Shellbar.propDescriptions = { | |||
subtitle: 'Displays an application context. Should be used rarely.' | |||
}; | |||
|
|||
export { Shellbar as __Shellbar }; | |||
|
|||
export default withStyles(Shellbar, { cssFile: ['shellbar', 'product-switch'], fonts: true }); |
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.
should this file also require('fundamental-styles/dist/fonts.css');
since fonts was true?
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.
Nope - there's a bunch of other components imported into this component that already require fonts. That was an oversight to include them in the first place with withStyles
.add('custom styles', () => ( | ||
<Image | ||
customStyles={require('../../utils/WithStyles/customStylesTest.css')} | ||
photo='https://content.fortune.com/wp-content/uploads/2019/07/hippocorn.jpg' |
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.
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 this looks good. 🚢
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.
LGTM
Description
By removing dynamic requires, consumers will not be bringing in all of fundamental-styles with each component.
"...This means dynamic requires are supported but will cause all matching modules to be included in the bundle." https://webpack.js.org/guides/dependency-management/#require-with-expression
I decided to remove
withStyles
instead of repurposing it. Two reasons:cssFile: require('fundamental-styles/dist/button.css)
towithStyles
will cause the css to always be loaded and not respectdisableStyles
prop.cssFile: 'fundamental-styles/dist/button.css'
and then calling it likerequire(cssFile)
inwithStyles
does not work because of the following:"Fully dynamic statements, such as import(foo), will fail because webpack requires at least some file location information.The import() must contain at least some information about where the module is located, so bundling can be limited to a specific directory or set of files.
Just in case someone wonders, the same rule applies for dynamic require statements"
https://stackoverflow.com/questions/44166393/uncaught-error-cannot-find-module-when-using-dynamic-import-for-javascript
On the remaining class components (which we need to convert at some point), I used
componentDidMount
and on functional componentsuseEffect
.I also removed
customStyles
prop. Because we are not using a hoc anymore, we can just import our custom styles in our wrapper inside nui-widgets.