-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
refactor(ui): code-split gigantic Monaco Editor dep #12150
Merged
terrytangyuan
merged 4 commits into
argoproj:master
from
agilgur5:refactor-ui-code-split-monaco
Nov 20, 2023
Merged
refactor(ui): code-split gigantic Monaco Editor dep #12150
terrytangyuan
merged 4 commits into
argoproj:master
from
agilgur5:refactor-ui-code-split-monaco
Nov 20, 2023
Conversation
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
- shave off 7.72MB / 3MB minifed / 762KB gzipped from main bundle - main bundle itself is now only 5.11MB / 2.81MB minified / 553KB gzipped - i.e. the entire main bundle is smaller than the Monaco bundle 😮 😬 - wrap `react-monaco-editor` into a lazy loaded component - with some tiny gimmicks to it per in-line comments - in `ObjectEditor`, asynchronously import `languages` as well in one of its effects - otherwise all of `monaco-editor` gets imported, per in-line comment - also rewrite that effect to use modern async/await instead of promise chains - which ends up a good bit simpler than what it would be with a promise chain with the new async import on top of the async fetch etc - and invert a conditional as well to reduce nesting / code complexity - also refactor `ObjectEditor` a bit to correctly use `useRef` instead of `createRef` - the former is for legacy class-based components, the latter is for hooks-based functional components Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
- my editor defaults to 2 space, oops - some of the code I copy+pasted (from previous code I wrote) was 4 space though, so ended up with mixed indentation 😕 - weirdly didn't pop up when I ran `yarn lint` locally 🤔, possibly b/c I hadn't staged it yet? Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
- to make the bundle names a bit clearer - although pieces that got code split out of the dynamic imported bundles (e.g. `Chart.js` for instance) still have randomized names - that might require some fancy function to produce a cleaner `output.chunkName`, not sure Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
agilgur5
commented
Nov 5, 2023
toyamagu-2021
approved these changes
Nov 5, 2023
terrytangyuan
approved these changes
Nov 20, 2023
shuangkun
pushed a commit
to shuangkun/argo-workflows
that referenced
this pull request
Nov 21, 2023
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
terrytangyuan
pushed a commit
that referenced
this pull request
Nov 27, 2023
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Partial fix for #12059 -- this is the largest improvement by a wide margin, though still a little bit left to do
Partial fix for #11740
Motivation
Modifications
wrap
react-monaco-editor
into a lazy loaded componentin
ObjectEditor
, asynchronously importlanguages
as well in one of its effectsmonaco-editor
gets imported, per in-line commentalso refactor
ObjectEditor
a bit to correctly useuseRef
instead ofcreateRef
createRef
is for legacy class-based components, whileuseRef
is for hooks-based functional componentsadd
webpackChunkName
magic comment for clearer names for all of the dynamic importsChart.js
, which is a chunk ofreports
) can't be directly namedoutput.chunkFilename
is how it's typically configured, but you can't access the unresolved import name in that[name]
is equivalent to[id]
in this case; I triedVerification
Tested locally, editor seems to work fine in the UI:
Bundle verification
Full bundle,
monaco-editor
now split out:Size of remaining main bundle: