[REF] fiber: small cleanups

This commit is contained in:
Géry Debongnie
2019-10-26 20:59:51 +02:00
committed by Aaron Bohy
parent 9cee12d7b4
commit 9779cd196c
2 changed files with 12 additions and 13 deletions
+4 -10
View File
@@ -148,7 +148,6 @@ export class Fiber {
}; };
this._walk(doWork); this._walk(doWork);
let component: Component<any, any> = this.component; let component: Component<any, any> = this.component;
this.shouldPatch = false;
const patchLen = patchQueue.length; const patchLen = patchQueue.length;
try { try {
for (let i = 0; i < patchLen; i++) { for (let i = 0; i < patchLen; i++) {
@@ -161,14 +160,10 @@ export class Fiber {
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
try { for (let i = 0; i < patchLen; i++) {
for (let i = 0; i < patchLen; i++) { const fiber = patchQueue[i];
const fiber = patchQueue[i]; component = fiber.component;
component = fiber.component; component.__patch(fiber.vnode);
component.__patch(fiber.vnode);
}
} catch (e) {
this.handleError(e);
} }
try { try {
for (let i = patchLen - 1; i >= 0; i--) { for (let i = patchLen - 1; i >= 0; i--) {
@@ -181,7 +176,6 @@ export class Fiber {
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
this.shouldPatch = true;
} }
/** /**
+8 -3
View File
@@ -4365,7 +4365,7 @@ describe("component error handling (catchError)", () => {
}); });
test("no component catching error lead to full app destruction", async () => { test("no component catching error lead to full app destruction", async () => {
expect.assertions(6) expect.assertions(6);
const handler = jest.fn(); const handler = jest.fn();
env.qweb.on("error", null, handler); env.qweb.on("error", null, handler);
const consoleError = console.error; const consoleError = console.error;
@@ -4562,6 +4562,8 @@ describe("component error handling (catchError)", () => {
test.skip("can catch an error in the willPatch call", async () => { test.skip("can catch an error in the willPatch call", async () => {
// we do not catch error in willPatch anymore // we do not catch error in willPatch anymore
const consoleError = console.error;
console.error = jest.fn();
class ErrorComponent extends Widget { class ErrorComponent extends Widget {
static template = xml`<div><t t-esc="props.message"/></div>`; static template = xml`<div><t t-esc="props.message"/></div>`;
willPatch() { willPatch() {
@@ -4583,6 +4585,7 @@ describe("component error handling (catchError)", () => {
class App extends Widget { class App extends Widget {
static template = xml` static template = xml`
<div> <div>
<span><t t-esc="state.message"/></span>
<ErrorBoundary><ErrorComponent message="state.message" /></ErrorBoundary> <ErrorBoundary><ErrorComponent message="state.message" /></ErrorBoundary>
</div>`; </div>`;
state = useState({ message: "abc" }); state = useState({ message: "abc" });
@@ -4590,12 +4593,14 @@ describe("component error handling (catchError)", () => {
} }
const app = new App(env); const app = new App(env);
await app.mount(fixture); await app.mount(fixture);
expect(fixture.innerHTML).toBe("<div><div><div>abc</div></div></div>"); expect(fixture.innerHTML).toBe("<div><span>abc</span><div><div>abc</div></div></div>");
app.state.message = "def"; app.state.message = "def";
await nextTick(); await nextTick();
await nextTick(); await nextTick();
await nextTick(); await nextTick();
expect(fixture.innerHTML).toBe("<div><div>Error handled</div></div>"); expect(fixture.innerHTML).toBe("<div><span>def</span><div>Error handled</div></div>");
expect(console.error).toHaveBeenCalledTimes(1);
console.error = consoleError;
}); });
test("a rendering error will reject the mount promise", async () => { test("a rendering error will reject the mount promise", async () => {