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

Force developers to use async imports on key rendering APIs #75079

Closed
joshdover opened this issue Aug 14, 2020 · 7 comments
Closed

Force developers to use async imports on key rendering APIs #75079

joshdover opened this issue Aug 14, 2020 · 7 comments
Labels
Feature:New Platform impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. loe:small Small Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team

Comments

@joshdover
Copy link
Contributor

In order to keep Kibana's frontend lean, we may want to consider changing some of the APIs we have for rendering in order to force applications to use async imports in the spots where plugins most often import more code than they should.

For example, it'd be great to be able to support something like:

core.application.register({
  id: 'myApp',
  renderModule: './application/render',
})

The challenge with this will be figuring out how to make this work with Webpack's async chunk feature. Currently, it will only create an async chunk if there is an import('./application/render') call and using import() with dynamic values leads to Webpack trying to build bundles out of all the possible modules that could be referenced.

I haven't investigated how we could make this work, but I suspect there may be a way using Webpack's "magic comments" and some require.resolve magic.

If we do find a way to make this work, we should also apply it to APIs much as Embeddables so that we can be sure that embeddables can be registered without importing very much code into a plugin's primary bundle.

@joshdover joshdover added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team Feature:New Platform labels Aug 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@elasticmachine
Copy link
Contributor

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

@spalger
Copy link
Contributor

spalger commented Aug 14, 2020

I think we probably need to rely on eslint here.

I don't think we'll be able to use magic comments to accomplish this. require.resolveWeak() could be used to get the module id for the remote module, but we can't know the chunk name/id without explicitly defining it somewhere with a import(/* webpackChunkName: "app" */ './application').

It seems like it would be a lot easier to validate that render functions use import(), maybe more.

@joshdover
Copy link
Contributor Author

@restrry to investigate how many plugins are violating this now to determine impact & whether or not this is worth the effort right now

@tylersmalley tylersmalley added 1 and removed 1 labels Oct 11, 2021
@tylersmalley
Copy link
Contributor

Checking to see if there is something we see as actionable here or if we want to close it. At the end of the day, I think teams need to own their async logic and not require us to do anything magical. cc @pauldotpower @stacey-gammon

@exalate-issue-sync exalate-issue-sync bot added impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. loe:small Small Level of Effort labels Feb 16, 2022
@stacey-gammon
Copy link
Contributor

I think we could close this. I think the time would be better spent focusing on page load time metrics, plus education regarding async imports, in order to give teams the motivation and knowledge to leverage them. We'll never be able to catch and prevent all of these sync imports that should actually be async.

@pgayvallet
Copy link
Contributor

I'll go ahead and close, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform impact:needs-assessment Product and/or Engineering needs to evaluate the impact of the change. loe:small Small Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

6 participants