mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
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
fb66423d4b
commit
39b668d050
@ -51,13 +51,13 @@ 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 contentElem = React.Children.only(this.props.children) as React.ReactElement<React.HTMLProps<HTMLElement>>;
|
const { disabled, className } = this.props;
|
||||||
if (disabled) {
|
|
||||||
return contentElem;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
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 (isValidContentElem) {
|
if (isValidContentElem) {
|
||||||
const contentElemProps: React.HTMLProps<HTMLElement> = {
|
const contentElemProps: React.HTMLProps<HTMLElement> = {
|
||||||
@ -72,8 +72,8 @@ 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 contentElem;
|
return this.props.children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user