Skip to content

Commit 64919b9

Browse files
authored
[core] fix(InputGroup): prevent infinite setState in componentDidUpdate (#3813)
1 parent e98ee03 commit 64919b9

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

packages/core/src/components/forms/inputGroup.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ export class InputGroup extends AbstractPureComponent2<IInputGroupProps & HTMLIn
129129
}
130130

131131
public componentDidMount() {
132-
this.updateInputWidth();
133-
}
134-
135-
public componentDidUpdate() {
136-
this.updateInputWidth();
132+
if (this.rightElement != null) {
133+
const { clientWidth } = this.rightElement;
134+
// small threshold to prevent infinite loops
135+
if (Math.abs(clientWidth - this.state.rightElementWidth) > 2) {
136+
this.setState({ rightElementWidth: clientWidth });
137+
}
138+
}
137139
}
138140

139141
private maybeRenderRightElement() {
@@ -147,16 +149,4 @@ export class InputGroup extends AbstractPureComponent2<IInputGroupProps & HTMLIn
147149
</span>
148150
);
149151
}
150-
151-
private updateInputWidth() {
152-
if (this.rightElement != null) {
153-
const { clientWidth } = this.rightElement;
154-
// small threshold to prevent infinite loops
155-
if (Math.abs(clientWidth - this.state.rightElementWidth) > 2) {
156-
this.setState({ rightElementWidth: clientWidth });
157-
}
158-
} else {
159-
this.setState({ rightElementWidth: DEFAULT_RIGHT_ELEMENT_WIDTH });
160-
}
161-
}
162152
}

0 commit comments

Comments
 (0)