Skip to content
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

fix(tooltip): fix potential NPE when setting option with notMerge strategy #20435

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/component/tooltip/TooltipHTMLContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,15 @@ class TooltipHTMLContent {

getSize() {
const el = this.el;
return [el.offsetWidth, el.offsetHeight];
return el ? [el.offsetWidth, el.offsetHeight] : [0, 0];
}

moveTo(zrX: number, zrY: number) {
const styleCoord = this._styleCoord;
makeStyleCoord(styleCoord, this._zr, this._container, zrX, zrY);

if (styleCoord[0] != null && styleCoord[1] != null) {
const style = this.el.style;
const style: any = this.el ? (this.el.style || {}) : {};
Copy link
Member

Choose a reason for hiding this comment

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

Falling el.style back to {} makes no sense. It just circumvents those errors and causes unnecessary invoking. I would suggest:

moveTo(zrX: number, zrY: number) {
  if (!this.el) {
    return;
  }
  // ...
}

const transforms = assembleTransform(styleCoord[0], styleCoord[1]) as string[][];
each(transforms, (transform) => {
style[transform[0] as any] = transform[1];
Expand Down