From 677adea2aad696d20d73e061d3248f5f461922c4 Mon Sep 17 00:00:00 2001 From: "Sun P.M" <35005831+sunpm@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:39:36 +0800 Subject: [PATCH] fix(core): fix potential NPE when reading default init options from global object in dev environment (#19217) * fix: '__ECHARTS__DEFAULT__RENDERER__' of undefined * fix: Reduce converted code size * fix: Remove ternary operations --- src/core/echarts.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/echarts.ts b/src/core/echarts.ts index 1c342ce413..7757dd22fc 100644 --- a/src/core/echarts.ts +++ b/src/core/echarts.ts @@ -412,20 +412,19 @@ class ECharts extends Eventful { let defaultRenderer = 'canvas'; let defaultCoarsePointer: 'auto' | boolean = 'auto'; let defaultUseDirtyRect = false; + if (__DEV__) { const root = ( /* eslint-disable-next-line */ env.hasGlobalWindow ? window : global ) as any; - defaultRenderer = root.__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer; - - defaultCoarsePointer = retrieve2(root.__ECHARTS__DEFAULT__COARSE_POINTER, defaultCoarsePointer); + if (root) { + defaultRenderer = retrieve2(root.__ECHARTS__DEFAULT__RENDERER__, defaultRenderer); + defaultCoarsePointer = retrieve2(root.__ECHARTS__DEFAULT__COARSE_POINTER, defaultCoarsePointer); + defaultUseDirtyRect = retrieve2(root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__, defaultUseDirtyRect); + } - const devUseDirtyRect = root.__ECHARTS__DEFAULT__USE_DIRTY_RECT__; - defaultUseDirtyRect = devUseDirtyRect == null - ? defaultUseDirtyRect - : devUseDirtyRect; } const zr = this._zr = zrender.init(dom, {