-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[data][bfetch] Avoid using Buffer in client code
#107278
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
Conversation
| */ | ||
|
|
||
| import { unzlibSync, strFromU8 } from 'fflate'; | ||
| import { toByteArray } from 'base64-js'; |
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 is an existing dependency and it's a dependency of Buffer polyfill. So using it directly here doesn't make it worse. It costs less than the whole Buffer
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import escape from 'lodash/escape'; |
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.
Fixing wrong import. Should be better now, because lodash is included in shared deps
| return Buffer.from(val, 'base64').toString('utf8'); | ||
| if (window && window.atob) return window.atob(val); | ||
| // referencing from `global` tricks webpack to not include `Buffer` polyfill into this bundle | ||
| return global.Buffer.from(val, 'base64').toString('utf8'); |
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 seems to be tricking webpack to not bundle a polyfill for Buffer
|
@elasticmachine merge upstream |
Buffer in client code
|
Pinging @elastic/kibana-app-services (Team:AppServices) |
lizozom
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.
Beautiful changes. Thank you!
…a-bundle # Conflicts: # packages/kbn-optimizer/limits.yml
💚 Build SucceededMetrics [docs]Module Count
Page load bundle
History
To update your PR or re-run it, just comment with: |
mistic
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
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
Summary
Partially addresses #107280:
Do not use
Bufferin client-sidedataandbfetchcode to reduce bundle sizeAlso, fix a single
lodashimport indataAlternatively, this
Bufferpolyfill should be shared across bundles since it is anyway used incore