Skip to content

Commit

Permalink
[core] fix(EditableText): optimize updateInputDimensions (#4723)
Browse files Browse the repository at this point in the history
Call updateInputDimensions only when the props/state which it depends on are changed.
  • Loading branch information
SatishGandham authored May 19, 2021
1 parent 7d41080 commit 0de3a76
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/core/src/components/editable-text/editableText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,18 @@ export class EditableText extends AbstractPureComponent2<EditableTextProps, IEdi
if (this.state.isEditing && !prevState.isEditing) {
this.props.onEdit?.(this.state.value);
}
this.updateInputDimensions();
// updateInputDimensions is an expensive method. Call it only when the props
// it depends on change
if (
this.state.value !== prevState.value ||
this.props.alwaysRenderInput !== prevProps.alwaysRenderInput ||
this.props.maxLines !== prevProps.maxLines ||
this.props.minLines !== prevProps.minLines ||
this.props.minWidth !== prevProps.minWidth ||
this.props.multiline !== prevProps.multiline
) {
this.updateInputDimensions();
}
}

public cancelEditing = () => {
Expand Down

1 comment on commit 0de3a76

@blueprint-bot
Copy link

Choose a reason for hiding this comment

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

[core] fix(EditableText): optimize updateInputDimensions (#4723)

Previews: documentation | landing | table

Please sign in to comment.