mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix: Unhandled exception for <DropFileInput disabled={true}/> (#1512)
* fix: invalid handling disabled={false} causing app crash
Signed-off-by: Roman <ixrock@gmail.com>
* re-fix: put React.Children.only() validation inside try-catch to avoid crash as well
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
8753b2b17c
commit
4474d87ed2
@ -51,12 +51,15 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { disabled, className } = this.props;
|
|
||||||
const { onDragEnter, onDragLeave, onDragOver, onDrop } = this;
|
const { onDragEnter, onDragLeave, onDragOver, onDrop } = this;
|
||||||
|
const { disabled, className } = this.props;
|
||||||
try {
|
try {
|
||||||
const contentElem = React.Children.only(this.props.children) as React.ReactElement<React.HTMLProps<HTMLElement>>;
|
const contentElem = React.Children.only(this.props.children) as React.ReactElement<React.HTMLProps<HTMLElement>>;
|
||||||
|
if (disabled) {
|
||||||
|
return contentElem;
|
||||||
|
}
|
||||||
const isValidContentElem = React.isValidElement(contentElem);
|
const isValidContentElem = React.isValidElement(contentElem);
|
||||||
if (!disabled && isValidContentElem) {
|
if (isValidContentElem) {
|
||||||
const contentElemProps: React.HTMLProps<HTMLElement> = {
|
const contentElemProps: React.HTMLProps<HTMLElement> = {
|
||||||
className: cssNames("DropFileInput", className, {
|
className: cssNames("DropFileInput", className, {
|
||||||
droppable: this.dropAreaActive,
|
droppable: this.dropAreaActive,
|
||||||
@ -69,7 +72,7 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
|
|||||||
return React.cloneElement(contentElem, contentElemProps);
|
return React.cloneElement(contentElem, contentElemProps);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Invalid root content-element for DropFileInput", { err: String(err) });
|
logger.error(`Error: <DropFileInput/> must contain only single child element`);
|
||||||
return this.props.children;
|
return this.props.children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user