mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] component: error handling: rendering with sub components
Closes #425
This commit is contained in:
@@ -4,7 +4,7 @@ import { h, patch, VNode } from "../vdom/index";
|
|||||||
import "./directive";
|
import "./directive";
|
||||||
import { Fiber } from "./fiber";
|
import { Fiber } from "./fiber";
|
||||||
import "./props_validation";
|
import "./props_validation";
|
||||||
import { Scheduler } from "./scheduler";
|
import { scheduler } from "./scheduler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owl Component System
|
* Owl Component System
|
||||||
@@ -20,8 +20,6 @@ import { Scheduler } from "./scheduler";
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Types/helpers
|
// Types/helpers
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
const raf = window.requestAnimationFrame.bind(window);
|
|
||||||
export const scheduler = new Scheduler(raf);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Env (environment) is an object that will be (mostly) shared between all
|
* An Env (environment) is an object that will be (mostly) shared between all
|
||||||
@@ -296,13 +294,8 @@ export class Component<T extends Env, Props extends {}> {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fiber = new Fiber(null, this, this.props, undefined, undefined, false);
|
|
||||||
if (!__owl__.vnode) {
|
|
||||||
this.__prepareAndRender(fiber);
|
|
||||||
} else {
|
|
||||||
this.__render(fiber);
|
|
||||||
}
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const fiber = new Fiber(null, this, this.props, undefined, undefined, false);
|
||||||
scheduler.addFiber(fiber, err => {
|
scheduler.addFiber(fiber, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -317,6 +310,11 @@ export class Component<T extends Env, Props extends {}> {
|
|||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
if (!__owl__.vnode) {
|
||||||
|
this.__prepareAndRender(fiber);
|
||||||
|
} else {
|
||||||
|
this.__render(fiber);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,9 +346,8 @@ export class Component<T extends Env, Props extends {}> {
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fiber = new Fiber(null, this, this.props, undefined, undefined, force);
|
|
||||||
this.__render(fiber);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const fiber = new Fiber(null, this, this.props, undefined, undefined, force);
|
||||||
scheduler.addFiber(fiber.root, err => {
|
scheduler.addFiber(fiber.root, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -361,6 +358,7 @@ export class Component<T extends Env, Props extends {}> {
|
|||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
this.__render(fiber);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { VNode } from "../vdom/index";
|
import { VNode } from "../vdom/index";
|
||||||
import { Component } from "./component";
|
import { Component } from "./component";
|
||||||
|
import { scheduler } from "./scheduler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owl Fiber Class
|
* Owl Fiber Class
|
||||||
@@ -216,7 +217,11 @@ export class Fiber {
|
|||||||
component.catchError!(error);
|
component.catchError!(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
// the 3 next lines aim to mark the root fiber as being in error, and
|
||||||
|
// to force it to end, without waiting for its children
|
||||||
|
this.root.counter = 0;
|
||||||
this.root.error = error;
|
this.root.error = error;
|
||||||
|
scheduler.flush();
|
||||||
root.destroy();
|
root.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,3 +65,6 @@ export class Scheduler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const raf = window.requestAnimationFrame.bind(window);
|
||||||
|
export const scheduler = new Scheduler(raf);
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import { Component, scheduler } from "./component/component";
|
import { Component } from "./component/component";
|
||||||
|
import { scheduler } from "./component/scheduler";
|
||||||
import { EventBus } from "./core/event_bus";
|
import { EventBus } from "./core/event_bus";
|
||||||
import { Observer } from "./core/observer";
|
import { Observer } from "./core/observer";
|
||||||
import { onWillUnmount } from "./hooks";
|
import { onWillUnmount } from "./hooks";
|
||||||
|
|||||||
@@ -4739,6 +4739,26 @@ describe("component error handling (catchError)", () => {
|
|||||||
expect(console.error).toBeCalledTimes(0);
|
expect(console.error).toBeCalledTimes(0);
|
||||||
console.error = consoleError;
|
console.error = consoleError;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("a rendering error will reject the render promise (with sub components)", async () => {
|
||||||
|
class Child extends Component<any, any> {
|
||||||
|
static template = xml`<span></span>`;
|
||||||
|
}
|
||||||
|
class Parent extends Component<any, any> {
|
||||||
|
static template = xml`<div><Child/><t t-esc="x.y"/></div>`;
|
||||||
|
static components = { Child };
|
||||||
|
}
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const parent = new Parent(env);
|
||||||
|
await parent.mount(fixture);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
expect(error.message).toBe("Cannot read property 'y' of undefined");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("top level sub widgets", () => {
|
describe("top level sub widgets", () => {
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import { Env, scheduler } from "../src/component/component";
|
import { Env } from "../src/component/component";
|
||||||
|
import { scheduler } from "../src/component/scheduler";
|
||||||
import { EvalContext, QWeb } from "../src/qweb/qweb";
|
import { EvalContext, QWeb } from "../src/qweb/qweb";
|
||||||
import { patch } from "../src/vdom";
|
import { patch } from "../src/vdom";
|
||||||
import "../src/qweb/base_directives";
|
import "../src/qweb/base_directives";
|
||||||
|
|||||||
Reference in New Issue
Block a user