Skip to content

Commit

Permalink
fix: 区分 GuiIcon 报错类型 close #2345 (#2451)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Dec 6, 2023
1 parent 87202f5 commit 02f0b3b
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/s2-core/src/common/icons/gui-icon.ts
Original file line number Diff line number Diff line change
@@ -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 = '<svg';
Expand Down Expand Up @@ -118,16 +119,28 @@ export class GuiIcon extends Group {
} else {
this.getImage(name, cacheKey, fill)
.then((value: HTMLImageElement) => {
// 加载完成后,当前 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);
});
}
}
Expand Down

1 comment on commit 02f0b3b

@vercel
Copy link

@vercel vercel bot commented on 02f0b3b Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.