[IMP] component: error when mounted on invalid target

This commit is contained in:
Géry Debongnie
2019-11-02 19:45:28 +01:00
committed by aab-odoo
parent bd3c1265d3
commit 8d1dd06340
3 changed files with 24 additions and 2 deletions
+6 -1
View File
@@ -117,7 +117,7 @@ export class Component<T extends Env, Props extends {}> {
let constr = this.constructor as any;
const defaultProps = constr.defaultProps;
if (defaultProps) {
props = props || {} as Props;
props = props || ({} as Props);
this.__applyDefaultProps(props, defaultProps);
}
this.props = <Props>props;
@@ -286,6 +286,11 @@ export class Component<T extends Env, Props extends {}> {
}
return;
}
if (!(target instanceof HTMLElement)) {
let message = `Component '${this.constructor.name}' cannot be mounted: the target is not a valid DOM node.`;
message += `\nMaybe the DOM is not ready yet? (in that case, you can use owl.utils.whenReady)`;
throw new Error(message);
}
return new Promise((resolve, reject) => {
const fiber = new Fiber(null, this, undefined, undefined, false);
scheduler.addFiber(fiber, err => {