mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
b8d09e523d
This commit fixes two issues with subroots: 1. creating a subroot create a new component node synchronously. This would causes issues if the creation was done in the setup of a component, since in that case, owl would reset the current component to null right after, which would cause all calls to hooks to fail. This is fixed by restoring the previous component node right after creating a root. 2. the destroy method for roots calls the scheduler processTasks. However, the processTasks method was not safe to reentrant calls, which would in some cases crashes owl. For example, if a destroy is done while a new component is mounted, the mount method would be called twice. This is fixed by ignoring the processTasks if we are currently processing tasks. It works because the "for ... of" loop will still process all new tasks in the current iteration.
211 lines
5.4 KiB
Plaintext
211 lines
5.4 KiB
Plaintext
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
exports[`destroy a subroot while another component is mounted in main app 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
const comp1 = app.createComponent(\`ChildB\`, true, false, false, []);
|
|
const comp2 = app.createComponent(\`ChildA\`, true, false, false, []);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
let b2, b3;
|
|
if (ctx['state'].flag) {
|
|
b2 = comp1({}, key + \`__1\`, node, this, null);
|
|
} else {
|
|
b3 = comp2({}, key + \`__2\`, node, this, null);
|
|
}
|
|
return multi([b2, b3]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`destroy a subroot while another component is mounted in main app 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block3 = createBlock(\`<div block-ref=\\"0\\"/>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
const b2 = text(\`a\`);
|
|
let ref1 = (el) => this.__owl__.setRef((\`elem\`), el);
|
|
const b3 = block3([ref1]);
|
|
return multi([b2, b3]);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`destroy a subroot while another component is mounted in main app 3`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return text(\`c\`);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`destroy a subroot while another component is mounted in main app 4`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return text(\`b\`);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot by default, env is the same in sub root 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>main app</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot by default, env is the same in sub root 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>sub root</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot can create a root in a setup function, then use a hook 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return text(\`a\`);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot can create a root in a setup function, then use a hook 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return text(\`c\`);
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot can mount subroot 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>main app</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot can mount subroot 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>sub root</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot can mount subroot inside own dom 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>main app</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot can mount subroot inside own dom 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>sub root</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot env can be specified for sub roots 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>main app</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot env can be specified for sub roots 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>sub root</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot subcomponents can be destroyed, and it properly cleanup the subroots 1`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>main app</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|
|
|
|
exports[`subroot subcomponents can be destroyed, and it properly cleanup the subroots 2`] = `
|
|
"function anonymous(app, bdom, helpers
|
|
) {
|
|
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
|
|
|
|
let block1 = createBlock(\`<div>sub root</div>\`);
|
|
|
|
return function template(ctx, node, key = \\"\\") {
|
|
return block1();
|
|
}
|
|
}"
|
|
`;
|