-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Introduce UI PluginsService #32672
Introduce UI PluginsService #32672
Conversation
b8cdc6f
to
30b4931
Compare
8d65ffb
to
772e6e7
Compare
772e6e7
to
3377535
Compare
src/optimize/index.js
Outdated
@@ -66,6 +66,7 @@ export default async (kbnServer, server, config) => { | |||
const optimizer = new FsOptimizer({ | |||
logWithMetadata: (tags, message, metadata) => server.logWithMetadata(tags, message, metadata), | |||
uiBundles, | |||
discoveredPlugins: newPlatform.start.plugins.uiPlugins.internal, |
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.
This will be updated to newPlatform.setup
once #33708 is merged.
src/optimize/watch/optmzr_role.js
Outdated
@@ -30,6 +30,7 @@ export default async (kbnServer, kibanaHapiServer, config) => { | |||
const watchOptimizer = new WatchOptimizer({ | |||
logWithMetadata, | |||
uiBundles: kbnServer.uiBundles, | |||
discoveredPlugins: kbnServer.newPlatform.start.plugins.uiPlugins.internal, |
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.
This will be updated to newPlatform.setup
once #33708 is merged.
9d29795
to
e31d95f
Compare
💔 Build Failed |
💔 Build Failed |
💚 Build Succeeded |
💚 Build Succeeded |
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.
LGTM
💔 Build Failed |
💔 Build Failed |
💚 Build Succeeded |
Waiting on getting in the backport for #34421 before backporting this as they conflict with one another. |
This commit introduces two changes: - Adds new platform plugins as a new bundles to the optimizer - A PluginsService in the UI that loads plugin bundles, initializes plugins, and manages the lifecycle of plugins.
💔 Build Failed |
💔 Build Failed |
Summary
Closes #18874
This PR introduces two changes:
For testing locally, here are two plugins you can download and extract into
src/plugins
to see real plugins loading in the browser and interacting. Use these to hack around with if you'd like.Building plugin bundles
To create immutable bundles for new platform plugins, I've updated the BaseOptimizer to add new entry points, one for each UI plugin discovered by Core's plugin discovery process. I've also updated our Webpack output to include these new options:
This directs Webpack to assign the exported
plugin
value from each entry point (if present) to a global object that it sets up, where the key of the object is the name of the entry point. Since all plugin entry points are configured with the nameplugin/${pluginName}
this global object looks like this once these entry points are loaded on the page:Since all bundles are affected by this output setting, the entry points for the legacy system will also attach their exported
plugin
values to the the global__kbnBundles__
object. Since these entry points do not export anyplugin
values, this will be undefined and unused.I've also verified that our
splitChunks
configuration correctly deduplicates dependencies from these plugin bundles. For example, importing React in a plugin does not result in a copy of the React module being included in the plugin's bundle. It will continue to use the common React module from our DLLs.PluginsService
The structure of the new
PluginsService
is largely the same as the server side, with the discovery process replaced with a bundle loading step.Each
Plugin
instance (a thin wrapper that manages a plugin's construction and lifecycle) has aload
function that loads the bundle into the browser and grabs the exportedplugin
function fromwindow.__kbnBundles__
.In order to decrease startup time, all of these bundles are loaded in parallel. This step happens after the page loads, but before the legacy platform is started. This is one area of this PR that could be optimized further if needed, but I suspect will be fast for most users because these plugin bundles should be cached in the browser after the first load. Options for making this faster:
Once bundles are loaded, the PluginsService proceeds almost identically to the backend service to manage the lifecycle of the plugins and wire up dependencies.
Dev Docs
Introduce UI PluginsService
The experimental new platform now supports plugins in the browser. The API for defining plugins mirrors the interface for server-side plugins. New platform plugins can enable a client-side plugin by defining an entry point
my_plugin/public/index.ts
and adding the"ui": true
flag in theirmy_plugin/kibana.json
file.The entry point for the plugin should export a single
plugin
function that returns an initialized plugin with the requiredsetup
,start
, andstop
functions:Any value returned by your plugin's
setup
andstart
functions will be provided as dependencies for any plugins that depend on your plugin via therequiredPlugins
andoptionalPlugins
options in a plugin'skibana.json
file.