mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[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:
committed by
Samuel Degueldre
parent
5c324fa075
commit
0b4b7899f6
@@ -409,6 +409,45 @@ exports[`Portal portal's parent's env is not polluted 2`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Portal simple catchError with portal 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><block-child-0/><block-child-1/></div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b2,b3;
|
||||
if (ctx['error']) {
|
||||
b2 = text(\`Error\`);
|
||||
} else {
|
||||
b3 = component(\`Boom\`, {}, key + \`__1\`, node, ctx);
|
||||
}
|
||||
return block1([], [b2, b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Portal simple catchError with portal 2`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><span>1</span><block-child-0/></div>\`);
|
||||
let block2 = createBlock(\`<p><block-text-0/></p>\`);
|
||||
|
||||
function slot1(ctx, node, key = \\"\\") {
|
||||
let txt1 = ctx['a'].b.c;
|
||||
return block2([txt1]);
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let b3 = component(\`Portal\`, {target: '#outside',slots: {'default': {__render: slot1, __ctx: ctx}}}, key + \`__1\`, node, ctx);
|
||||
return block1([], [b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Portal with target in template (after portal) 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user