Skip to content
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

Improve lazy-loading of Monaco editor #532

Merged
merged 1 commit into from Mar 20, 2024
Merged

Conversation

martin-fleck-at
Copy link
Collaborator

  • Use more dynamic imports for Monaco editor
    -- Expose dynamically imported
    -- Use type imports where possible to avoid full resolution
  • Expose as much options for outside configuration as possible
  • Avoid unnecessary boolean return type
  • Avoid loading Monaco editor only for key codes
  • Align react-query versions with process-editor-client

- Use more dynamic imports for Monaco editor
-- Expose dynamically imported
-- Use type imports where possible to avoid full resolution
- Expose as much options for outside configuration as possible
- Avoid unnecessary boolean return type
- Avoid loading Monaco editor only for key codes
- Align react-query versions with process-editor-client

Co-authored-by: Olaf Lessenich <olessenich@eclipsesource.com>
Copy link
Member

@ivy-lli ivy-lli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. But maybe a quick explanation would be great.
More and more I think we need a separate package with all this monaco stuff in it:

  • Setup monaco environment
  • Setup lsp connection
  • Provide react monaco component
  • ...

@@ -1,14 +1,14 @@
import { createWebSocketConnection, type Connection } from '@axonivy/jsonrpc';

export namespace IvyScriptLanguage {
export async function startWebSocketClient(url: string, isMonacoReady: Promise<boolean>): Promise<any> {
export async function startWebSocketClient(url: string, isMonacoReady: Promise<any>): Promise<any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not Promise?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not Promise?

I'm not sure I fully understand but the return type that we typically use here is of monacoEditorReact.Monaco but since we are not actually awaiting the result in this function, I typed it any (instead of void or boolean previously) mainly to ease changes and avoid conversions like MonacoEditorUtil.getInstance().then(() => {}) but also highlight the fact that we do not care about the return type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry not everything was posted...
I wanted to write Why not Promise<void>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does my post above answer the question? Basically we want to avoid unnecessary conversions.

@martin-fleck-at
Copy link
Collaborator Author

Looks good. But maybe a quick explanation would be great. More and more I think we need a separate package with all this monaco stuff in it:

  • Setup monaco environment
  • Setup lsp connection
  • Provide react monaco component
  • ...

I agree that in the long run that might make things easier. However, some things are little bit more intertwined as they manipulate the global MonacoEnvironment, e.g., @monaco-editor/react provides a loader to setup the overall monaco and only then we can properly setup the workers in the environment. The good thing is, we get errors and warnings fast if something is not done correctly ;-) So do you think we should do this as part of this PR or could this be a follow-up? I know the setup is important but it would be great to see if the lazy loading actually brings that much benefit.

I'm happy to provide additional explanation: Documentation, code comments, etc.? I tried to separate out things into dedicated functions as much as possible and add comments here and there. But the basic steps are: initialize the monaco API, configure the language client ("VS Code API") connection with the monaco API, add worker creation to the MonacoEnvironment, and register our own languages and themes against the monaco API. With that, the monaco namespace is ready to be used and a React MonacoEditor can be created.

As for the lazy loading: The goal is to async all the heavy imports into promises so they are not loaded when the script is parsed initially but only once we actually trigger the loading function.

@ivy-lli
Copy link
Member

ivy-lli commented Mar 20, 2024

Yes, I think, I understood the changes.

Yes, can definitely be in a later PR.

@ivy-lli
Copy link
Member

ivy-lli commented Mar 20, 2024

I will merge this now, ok? @martin-fleck-at

@martin-fleck-at
Copy link
Collaborator Author

@ivy-lli Yes, thank you!

@martin-fleck-at
Copy link
Collaborator Author

@ivy-lli Do you know how long it usually takes for the new version to be available so it can be consumed in the process editor?

@ivy-lli ivy-lli merged commit cc6e9c2 into master Mar 20, 2024
7 checks passed
@ivy-lli ivy-lli deleted the features/lazy-loading branch March 20, 2024 10:06
@ivy-lli
Copy link
Member

ivy-lli commented Mar 20, 2024

image
ca 4-5min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants