From 0c69b10d846c682a53842d5133649b3954bf9a21 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Mon, 2 Aug 2021 15:31:20 +0200 Subject: [PATCH] [data][bfetch] Avoid using `Buffer` in client code (#107278) --- packages/kbn-optimizer/limits.yml | 2 +- src/plugins/bfetch/public/streaming/inflate_response.ts | 3 ++- src/plugins/data/common/field_formats/converters/string.ts | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 7edca22dcad2f..5a0b376c4cbc5 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -13,7 +13,7 @@ pageLoadAssetSize: dashboard: 374194 dashboardEnhanced: 65646 dashboardMode: 22716 - data: 943821 + data: 900000 dataEnhanced: 50420 devTools: 38637 discover: 99999 diff --git a/src/plugins/bfetch/public/streaming/inflate_response.ts b/src/plugins/bfetch/public/streaming/inflate_response.ts index 73cb52285987c..860b77016cd00 100644 --- a/src/plugins/bfetch/public/streaming/inflate_response.ts +++ b/src/plugins/bfetch/public/streaming/inflate_response.ts @@ -7,9 +7,10 @@ */ import { unzlibSync, strFromU8 } from 'fflate'; +import { toByteArray } from 'base64-js'; export function inflateResponse(response: string) { - const buff = Buffer.from(response, 'base64'); + const buff = toByteArray(response); const unzip = unzlibSync(buff); return strFromU8(unzip); } diff --git a/src/plugins/data/common/field_formats/converters/string.ts b/src/plugins/data/common/field_formats/converters/string.ts index 816754a2a9298..c6aba38cf376d 100644 --- a/src/plugins/data/common/field_formats/converters/string.ts +++ b/src/plugins/data/common/field_formats/converters/string.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import escape from 'lodash/escape'; +import { escape } from 'lodash'; import { i18n } from '@kbn/i18n'; import { KBN_FIELD_TYPES } from '@kbn/field-types'; import { asPrettyString, getHighlightHtml } from '../utils'; @@ -95,7 +95,9 @@ export class StringFormat extends FieldFormat { private base64Decode(val: string) { try { - 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'); } catch (e) { return asPrettyString(val); }