Skip to content

Conversation

@spalger
Copy link
Contributor

@spalger spalger commented Feb 20, 2020

Once we merged the @kbn/optimizer we broke the syntax highlighting in canvas because the monaco editor is a stateful module that we weren't sharing via @kbn/ui-shared-deps. This moves it into the shared deps package so that all bundles/plugins can use it and so that it is bundled once.

To use the monaco editor code should now use:

import { monaco } from '@kbn/ui-shared-deps/monaco';

This monaco instance is the one populated with features by packages/kbn-ui-shared-deps/monaco.ts and is used everywhere. The monaco-editor/esm/vs/editor/editor.api is still enabled for react-monaco-editor but should not be used by applications.

The interface of the <CodeEditor /> from kibana-react was also tweaked as to not expose the monaco editor instance to handlers. The argument should always be the same instance accessible via the import, so that is now asserted whenever possible and consumers that need access to the monaco instance should import it instead. (this change was primarily to deal with typeof monaco instances that made less sense now that we're standardized on the monaco vs monacoEditor naming everywhere)

Comment on lines +149 to +151
if (__monaco !== monaco) {
throw new Error('react-monaco-editor is using a different version of monaco');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the only reason to expose the monaco instance to handlers like editorDidMount() is so consumers can get access to the version of monaco being used by react-monaco-editor. In our case this version should always be the same as the version imported from @kbn/ui-shared-deps/monaco, so I updated this and the signature for these handlers to ensure we keep a single source of truth.

Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent, yeah this makes sense to me

Copy link
Contributor

@poffdeluxe poffdeluxe left a comment

Choose a reason for hiding this comment

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

Changes look good -- I think one thing we might have to check, however, is if there's any further work that needs to be done to get the jest tests all working. We tell jest to transform the monaco editor so the imports work correctly: https://github.com/elastic/kibana/blob/master/src/dev/jest/config.js#L90

@spalger
Copy link
Contributor Author

spalger commented Feb 20, 2020

I think one thing we might have to check, however, is if there's any further work that needs to be done to get the jest tests all working

Jest should still work because the import of @kbn/ui-shared-deps/monaco still imports from node_modules/monaco-editor which is when that transform kicks in.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@spalger spalger marked this pull request as ready for review February 20, 2020 17:45
@spalger spalger requested review from a team as code owners February 20, 2020 17:45
@spalger spalger added release_note:skip Skip the PR/issue when compiling release notes Team:Operations Kibana-Operations Team v7.7.0 v8.0.0 labels Feb 20, 2020
@spalger spalger requested a review from poffdeluxe February 20, 2020 17:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

Copy link
Contributor

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

AppArch code changes LGTM

});

// Register the theme
monaco.editor.defineTheme('euiColors', this.props.useDarkTheme ? DARK_THEME : LIGHT_THEME);
Copy link
Member

@tylersmalley tylersmalley Feb 20, 2020

Choose a reason for hiding this comment

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

Should this be set on the default package? Or do we still want to leave it up to the implementation to import the colors?

Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker to this PR since this is the current implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should avoid putting any code into the @kbn/ui-shared-deps that isn't directly from npm as that module is only built on bootstrap. So I'm going to say we should leave it here.

@spalger spalger merged commit 4aedf2b into elastic:master Feb 20, 2020
spalger pushed a commit to spalger/kibana that referenced this pull request Feb 20, 2020
…ses (elastic#58075)

* add monaco to kbn/ui-shared-deps and load required features for all uses

* forgot to save a change

* remove unused imports

* include a cache buster to counteract issue elastic#58077

* include monaco.ts in ts project
spalger pushed a commit that referenced this pull request Feb 20, 2020
… all uses (#58075) (#58167)

* add monaco to kbn/ui-shared-deps and load required features for all uses (#58075)

* add monaco to kbn/ui-shared-deps and load required features for all uses

* forgot to save a change

* remove unused imports

* include a cache buster to counteract issue #58077

* include monaco.ts in ts project

* update yarn.lock
@spalger
Copy link
Contributor Author

spalger commented Feb 20, 2020

7.x/7.7: 23e3ce7

@spalger spalger deleted the fix/canvas-editor-syntax-highlighting branch February 20, 2020 23:51
jloleysens added a commit to jloleysens/kibana that referenced this pull request Feb 21, 2020
…-out-of-legacy

* 'master' of github.com:elastic/kibana: (109 commits)
  document difference between log record formats (elastic#57798)
  Expose elasticsearch config schema (elastic#57655)
  [ui/agg_response/tabify] update types for search/expressions/build_tabular_inspector_data.ts (elastic#58130)
  [SIEM] Cleans Cypress tests code (elastic#58134)
  fix: 🐛 make dev server Storybook builds work again (elastic#58188)
  Prevent core savedObjects plugin from being overridden (elastic#58193)
  Expose serverBasePath on client-side (elastic#58070)
  Fix legend sizing on area charts (elastic#58083)
  Drilldown plugin (elastic#58097)
  [skip-ci] Fix broken links to saved objects APIs in MIGRATION.md (elastic#58033)
  [ML] New Platform server shim: update datafeed routes (elastic#57739)
  Add flag for building static storybook site (elastic#58050)
  add monaco to kbn/ui-shared-deps and load required features for all uses (elastic#58075)
  [SIEM] Let us try out code owners for a little while and see what happens
  Add throttle param to Alerting readme (elastic#57609)
  [NP] Move ui/saved_objects to NP (elastic#57452)
  [Logs UI]  Fix column reordering in settings page (elastic#58104)
  Fix browser date format (elastic#57714)
  Add filter for ILM phase to Index Management (revert elastic#45486) (elastic#57402)
  Clarify Precision function in Timelion Kibana (elastic#58031)
  ...

# Conflicts:
#	x-pack/.i18nrc.json
@sulemanof
Copy link
Contributor

Hey @spalger
Seems this broke up the existing behavior:

this is how it looks in the Timelion editor:

broken editor

canvas:

image

I did yarn kbn clean & yarn kbn bootstrap before starting kibana.

@spalger
Copy link
Contributor Author

spalger commented Feb 26, 2020

Fixed the bug you mentioned in #58520, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes Team:Operations Kibana-Operations Team v7.7.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants