diff --git a/packages/s2-core/src/common/icons/gui-icon.ts b/packages/s2-core/src/common/icons/gui-icon.ts index c04c23cfa2..5429ee6b15 100644 --- a/packages/s2-core/src/common/icons/gui-icon.ts +++ b/packages/s2-core/src/common/icons/gui-icon.ts @@ -1,8 +1,9 @@ /** - * @Description: 请严格要求 svg 的 viewBox,若设计产出的 svg 不是此规格,请叫其修改为 '0 0 1024 1024' + * @description: 请严格要求 svg 的 viewBox,若设计产出的 svg 不是此规格,请叫其修改为 '0 0 1024 1024' */ import { Group, Shape, type ShapeAttrs } from '@antv/g-canvas'; import { omit, clone } from 'lodash'; +import { DebuggerUtil, type S2CellType } from '..'; import { getIcon } from './factory'; const STYLE_PLACEHOLDER = ' { - // 加载完成后,当前 Cell 可能已经销毁了 - if (this.destroyed) { + // 异步加载完成后,当前 Cell 可能已经销毁了 + const canvas = (this.getParent() as S2CellType)?.getMeta?.() + .spreadsheet?.container; + + // G 底层 refreshElements 默认是个数组, 销毁时获取不到, 没有兜底 https://github.com/antvis/S2/issues/2435 + if (this.destroyed || (canvas && !canvas.get('refreshElements'))) { + DebuggerUtil.getInstance().logger(`GuiIcon ${name} destroyed.`); return; } + image.attr('img', value); this.addShape('image', image); }) - .catch((event: Event) => { + .catch((event: string | Event) => { + // 如果是 TypeError, 则是 G 底层渲染有问题, 其他场景才报加载异常的错误 + if (event instanceof TypeError) { + // eslint-disable-next-line no-console + console.warn(`GuiIcon ${name} destroyed:`, event); + return; + } // eslint-disable-next-line no-console - console.error(`GuiIcon ${name} load failed`, event); + console.error(`GuiIcon ${name} load failed:`, event); }); } }