-
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
Use target_web
to ensure browser compatibility
#130874
Use target_web
to ensure browser compatibility
#130874
Conversation
The page load increase triggered an investigation about how |
88770df
to
9484183
Compare
@@ -14,4 +14,4 @@ export * from './node'; | |||
export * from './limits'; | |||
export * from './cli'; | |||
export * from './report_optimizer_timings'; | |||
export * from './babel_runtime_helpers'; | |||
export * from './audit_bundle_dependencies'; |
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 😇
@@ -52,6 +52,13 @@ jsts_transpiler( | |||
build_pkg_name = package_name(), | |||
) | |||
|
|||
jsts_transpiler( | |||
name = "target_web", | |||
srcs = SRCS, |
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';
)
@@ -6,8 +6,6 @@ | |||
*/ | |||
import { schema as rt, TypeOf } from '@kbn/config-schema'; | |||
|
|||
export const cspRuleAssetSavedObjectType = 'csp_rule'; |
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
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!
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 ourbrowserlist
compatibility 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 ourbrowserlist
compatibility 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.
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: |
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_node
build risks introducing compatibility issues as onlytarget_web
applies thebrowserlist
compatibility-matrix necessary polyfills.This PR adds the script
node scripts/find_target_node_imports_in_bundles
to list all packages imported in the UI with the defaulttarget_node
build.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-repository
could leak@kbn/config-schema
if 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_posture
It was accidentally importing
@kbn/config-schema
to the UI because it imported a constant from the same file a validation schema was defined.@kbn/optimizer
andkbn-ui-shared-deps-npm
After the changes, running the script still brings 2 uses of
target_node
that I was not able to remove:@kbn/optimizer
is found in all the bundles because of theentry_point_creator.js
injected 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_node
builds in our bundles?For maintainers