mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] error_handling: onError works if handling happens between culprit and root
Have a component implementing onError that calls a callback from one of its parent. That parent should not be the original source of the rendering (a parent above is). Make the callback handle the error and trigger an render() Before this commit, the parent did not see it was handling a subtree in error, and did not have a chance to revert that error state in its rendering stack. After this commit, this flow works.
This commit is contained in:
committed by
Géry Debongnie
parent
5187f01c44
commit
fb7d25ba0e
@@ -233,6 +233,44 @@ function(app, bdom, helpers) {
|
||||
expect(mockConsoleError).toBeCalledTimes(0);
|
||||
expect(mockConsoleWarn).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
test("render from above on error -- handler is not a Root or MountFiber", async () => {
|
||||
class Boom extends Component {
|
||||
static template = xml`<div t-esc="a.b.c"/>`;
|
||||
setup() {
|
||||
onError((err) => {
|
||||
this.props.onError(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`
|
||||
<div>
|
||||
<t t-if="error">Error</t>
|
||||
<t t-else="">
|
||||
<Boom onError.bind="handleError"/>
|
||||
</t>
|
||||
</div>`;
|
||||
static components = { Boom };
|
||||
|
||||
error: any = false;
|
||||
|
||||
handleError(err: Error) {
|
||||
this.error = err;
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
class GrandParent extends Component {
|
||||
static template: string = xml`<Parent />`;
|
||||
static components = { Parent };
|
||||
}
|
||||
await mount(GrandParent, fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>Error</div>");
|
||||
expect(mockConsoleError).toBeCalledTimes(0);
|
||||
expect(mockConsoleWarn).toBeCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors and promises", () => {
|
||||
|
||||
Reference in New Issue
Block a user