-
-
Notifications
You must be signed in to change notification settings - Fork 686
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
Bundle optimization #5295
Merged
Merged
Bundle optimization #5295
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
de9dcbd
Added @loadable/component typings
pnicolli 661c130
wip: lazyload Form components and Diff view, still need to fix most t…
deodorhunter acb3477
Code split Contents, RelationsCP, UsersCP, RulesCP
pnicolli e4433cb
wip: common webpack bundle name for Form related stuff
deodorhunter 51000e4
wip: merge with base bundle optimizations
deodorhunter f925d01
Merge branch 'main' into bundle-optimization
pnicolli 34e6530
Merge branch 'main' into bundle-optimization
pnicolli 0b8a907
Merge branch 'main' into bundle-optimization
mamico 734dbcc
Code split all controlpanels, form components and widgets
pnicolli 35dd3cc
Merge branch 'main' into bundle-optimization
pnicolli 17b803e
added babel-plugin-transform-imports
pnicolli 48bbe90
Merge branch 'main' into bundle-optimization
pnicolli 2a3b8b7
Removed babel-plugin-transform-imports and readded imports in compone…
pnicolli b1f39f7
fix chunk name clash
pnicolli 779146f
Merge branch 'main' into bundle-optimization
pnicolli 5a0c0fc
reinstalled @types/loadable__component
pnicolli 5bd41bf
Merge branch 'main' into bundle-optimization
pnicolli 680d147
Merge branch 'main' into bundle-optimization
mamico ae658ed
Merge branch 'main' into bundle-optimization
mamico 8717f1e
fix(test): edit comment
mamico 0b12d9e
Merge branch 'main' into bundle-optimization
pnicolli 799348e
Cleanup and news item
pnicolli ce86356
Added volto-slate news item
pnicolli d221aad
fix: remove loadable where component is composed
mamico f48fb47
Revert "fix: remove loadable where component is composed"
pnicolli 0bc13f2
Removed useless compose
pnicolli 2e399a0
Fix some cypress tests
pnicolli fb08a8f
Merge branch 'main' into bundle-optimization
pnicolli f4fb67e
Merge branch 'main' into bundle-optimization
pnicolli d7540f7
Merge branch 'main' into bundle-optimization
pnicolli 2121682
restore new deps
pnicolli 8cd2b52
unit tests
pnicolli 1350ead
more tests fixes
pnicolli 8329b22
Merge branch 'main' into bundle-optimization
pnicolli 89e1cc9
wip on controlpanels
pnicolli 4d55d66
more test fixes, controlpanels view now works correctly
pnicolli 1aaecc5
added docs
pnicolli f2e54ab
Merge branch 'main' into bundle-optimization
pnicolli 2ec660b
fix slate cypress test
pnicolli 23c0365
Merge branch 'main' into bundle-optimization
pnicolli 713fd29
rename docs file
pnicolli cfbcac4
Add introduction and minor grammar, spelling, and style fixes
stevepiercy cc1714a
Revert editor changes
stevepiercy 34cfadc
Merge branch 'main' into bundle-optimization
stevepiercy 46af613
Merge branch 'main' into bundle-optimization
pnicolli 5343b27
fix more slate tests
pnicolli 9218817
Merge branch 'main' into bundle-optimization
sneridagh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
myst: | ||
html_meta: | ||
"description": "Bundle size optimization in Volto" | ||
"property=og:description": "Bundle size optimization in Volto" | ||
"property=og:title": "Bundle size optimization" | ||
"keywords": "Volto, Plone, frontend, React, Performance, guidelines" | ||
--- | ||
|
||
(bundle-size-optimization-label)= | ||
|
||
# Bundle size optimization | ||
|
||
This document describes how to optimize the bundle size of components through {term}`lazy loading` to improve page load times. | ||
Contributors to Volto core should follow the guidelines in this document. | ||
|
||
|
||
## Lazy loading in core | ||
|
||
Since Volto 18, several core components use lazy loading to keep the final build size under control. | ||
|
||
For example, the `Form` components are lazy loaded, which means that the code for the form components is only loaded when the user navigates to a page that contains a form. | ||
A new index file has been created at `packages/volto/src/components/manage/Form/index.tsx` that exports the form components with lazy loading. | ||
The `export`s in the main components index (`packages/volto/src/components/index.js`) have been updated to export components from the new specific index. | ||
The same goes for other components that have been lazy loaded, such as the control panels and widgets. | ||
|
||
Several `import` statements have been updated to use the new lazy loaded components. | ||
For example, the `Form` component is now imported from `@plone/volto/components/manage/Form` instead of `@plone/volto/components/manage/Form/Form`. | ||
You should keep this in mind, and always import components from the specific component index files when available, while avoiding importing components from the main components index file, if possible. | ||
This should also help to reduce circular dependencies, and help the overall build performance in the long run. | ||
|
||
|
||
### Unit test components that use lazy loaded components | ||
|
||
If you import a component from a lazy loaded index, you can have issues with rendering these in unit tests. | ||
Mocks are provided for lazy loaded components and are available for you to use. | ||
This can be done by using the `jest.mock` function to mock the specific component index. | ||
For example, to mock the `Form` component and all other components in the `Form`-specific index, you can use the following code in your test file: | ||
|
||
```javascript | ||
jest.mock('@plone/volto/components/manage/Form'); | ||
``` |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update imports to work with the new code split components in Volto. @pnicolli |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reduced JavaScript bundle size of the production build. Code split several internal modules: Controlpanels, Form, Widgets among other small ones. @pnicolli @deodorhunter |
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Renamed, but then not used? watch out
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.
@sneridagh You have a point here. I changed it because the way I understand this file, there's a name clash. The original version of the test is:
If I understand correctly there are two different calls intercepted with the alias
getSystemNeedsUpdate
and I doesn't feel right. On the other hand, if I change it where do I wait for the second one? Maybe after the click?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 tried adding an additional
wait
after the click, I am not sure it is needed at all, but the request is actually made to the backend so I think it is worth waiting for it to actually happen, at least in the current state of thingsThere 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 see, maybe we need to revisit this at some point.