-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Use target_web to ensure browser compatibility
#130874
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
Use target_web to ensure browser compatibility
#130874
Conversation
|
The page load increase triggered an investigation about how |
88770df to
9484183
Compare
packages/kbn-optimizer/src/index.ts
Outdated
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.
rename the dir because it no-longer contained only the logic for babel_runtime_helpers 😇
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.
I wonder if a potential improvement could be to only include in this version the formatRequest helper to avoid the split imports in the plugins.
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.
I went ahead and added only the needed files because jest complained that it couldn't reach the dependency ./parse_endpoint because it was from outside the module (from the import import { formatRequest } from '@kbn/server-route-repository/target_web/format_request';)
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.
Moved to constants because importing this constant from here was also importing the bundle @kbn/config-schema.
9753ccb to
f957144
Compare
f957144 to
1ef7722
Compare
|
Pinging @elastic/apm-ui (Team:apm) |
target_web to improve bundle size and performancetarget_web to improve browser compatibility
target_web to improve browser compatibilitytarget_web to ensure browser compatibility
dgieselaar
left a comment
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.
Thanks, page load bundle improvements look pretty good!
nreese
left a comment
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.
maps changes LGTM
code review
| build_pkg_name = package_name(), | ||
| ) | ||
|
|
||
| jsts_transpiler( |
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.
looks like this was repeated.
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.
@mattkime we are intentionally transpiling twice with different names and Babel presets:
target_node- optimized for Node.js environmenttarget_web- optimized for running in browsers (mind the additional parameterweb = True). Among other things, it applies the necessary transpilation and polyfills to support ourbrowserlistcompatibility matrix.
If your package only runs on the UI and you think target_node is not necessary, we can discuss with @elastic/kibana-operations if it's ok to remove it or if target_node must always exist.
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.
ah, not duplicate!
| @@ -0,0 +1,21 @@ | |||
| /* | |||
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 file is a different entry point exporting the web-only APIs.
| build_pkg_name = package_name(), | ||
| ) | ||
|
|
||
| jsts_transpiler( |
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.
@mattkime we are intentionally transpiling twice with different names and Babel presets:
target_node- optimized for Node.js environmenttarget_web- optimized for running in browsers (mind the additional parameterweb = True). Among other things, it applies the necessary transpilation and polyfills to support ourbrowserlistcompatibility matrix.
If your package only runs on the UI and you think target_node is not necessary, we can discuss with @elastic/kibana-operations if it's ok to remove it or if target_node must always exist.
shahzad31
left a comment
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.
Uptime changes LGTM !!
…e-bundle-improvements-target_web
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
gchaps
left a comment
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 from docs
Summary
Because of how our bundle process works, any
@kbn/*package used in the UI should build a web-optimized versiontarget_web. Using thetarget_nodebuild risks introducing compatibility issues as onlytarget_webapplies thebrowserlistcompatibility-matrix necessary polyfills.This PR adds the script
node scripts/find_target_node_imports_in_bundlesto list all packages imported in the UI with the defaulttarget_nodebuild.It also attempts to fix all the packages found in the script or removes the UI dependency on that package.
Related to #88678.
Highlights
@kbn/server-route-repository@kbn/server-route-repositorycould leak@kbn/config-schemaif imported from the UI. Plugins used a workaround to only import the method they used and enrich the typing with a 2nd import + type casting:kibana/x-pack/plugins/apm/public/services/rest/create_call_apm_api.ts
Lines 9 to 20 in 50bd2cc
This PR creates a new browser-specific entry point to the package that only exports the utilities that are meant to be used in the UI. Thanks to these changes, the package can be imported from the UI without the risk of leaking server-side code.
Plugin
cloud_security_postureIt was accidentally importing
@kbn/config-schemato the UI because it imported a constant from the same file a validation schema was defined.@kbn/optimizerandkbn-ui-shared-deps-npmAfter the changes, running the script still brings 2 uses of
target_nodethat I was not able to remove:@kbn/optimizeris found in all the bundles because of theentry_point_creator.jsinjected via its webpack config.kbn-ui-shared-deps-npm: I'm not entirely sure what is bringing this one in. Especially, that it's not@kbn/ui-shared-deps-npm.@elastic/kibana-operations can you help me out with these? 🙏
Open question
target_nodebuilds in our bundles?For maintainers