You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I decided to remove withStyles instead of repurposing it. Two reasons:
passing cssFile: require('fundamental-styles/dist/button.css) to withStyles will cause the css to always be loaded and not respect disableStyles prop.
passing cssFile: 'fundamental-styles/dist/button.css' and then calling it like require(cssFile) in withStyles 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 components useEffect.
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.
jbadan
changed the title
feat: replace withStyles wrapper with useEffect - reduce bundle size
feat: replace withStyles wrapper with useEffect and remove customStyles property
Feb 17, 2020
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 this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.