[FIX] portal: properly handle errors

Before this commit, Portal overrode the _render function for its
component node, which means it bypassed the error handling mechanism
that was implemented in that method.  It could have been fixed by
duplicating the error handling code as well, but a better solution in my
opinion is to simply override the renderFn function.  This is closer to
the actual intent of the portal implementation: wrap the result of the
rendering in a VPortal vnode.
This commit is contained in:
Géry Debongnie
2022-01-11 09:39:26 +01:00
committed by Samuel Degueldre
parent 5c324fa075
commit 0b4b7899f6
3 changed files with 81 additions and 9 deletions
+37
View File
@@ -68,6 +68,43 @@ describe("Portal", () => {
expect(fixture.innerHTML).toBe('<div id="outside"><p>2</p></div><div><span>1</span></div>');
});
test("simple catchError with portal", async () => {
class Boom extends Component {
static components = { Portal };
static template = xml`
<div>
<span>1</span>
<Portal target="'#outside'">
<p><t t-esc="a.b.c"/></p>
</Portal>
</div>`;
}
class Parent extends Component {
static template = xml`
<div>
<t t-if="error">Error</t>
<t t-else="">
<Boom />
</t>
</div>`;
static components = { Boom };
error: any = false;
setup() {
onError((err) => {
this.error = err;
this.render();
});
}
}
addOutsideDiv(fixture);
await mount(Parent, fixture);
expect(fixture.innerHTML).toBe('<div id="outside"></div><div>Error</div>');
});
test("basic use of portal in dev mode", async () => {
class Parent extends Component {
static components = { Portal };