odoo / owl

OWL: A web framework for structured, dynamic and maintainable applications
https://odoo.github.io/owl/
Other
1.14k stars 344 forks source link

order of patched/mounted across renderings may not be what we want #1445

Open ged-odoo opened 1 year ago

ged-odoo commented 1 year ago

Owl guarantees that in a render:

The idea is that we may want to measure stuff in onWillPatch before the dom is changed, so it should be called before. Also, once it's done, we want to call the onMounted and onPatched in the opposite order, so a parent is guaranteed that all its children are ready.

This works fine, as far as I can tell. However, what if we have multiple renderings?

For example, imagine that we have two components: Parent and Child, with no props, so the Child can be updated independently. Now, we update Parent, and a few micro ticks later, we update Child. See playground

So, if you look at it, you will see that clicking on the update button logs the following:

parent:onWillPatch
parent:onPatched
child:onWillPatch
child:onPatched

This is because we have two distincts renderings, and they are independent. So, even though they complete in the same animation frame, they are not properly coordinated.

This means that the parent onPatched hook is called before the child, which may be an issue (this is why I was notified of this problem).

We can probably easily reorder the fibers before applying them, but then we would have the following:

child:onWillPatch
child:onPatched
parent:onWillPatch
parent:onPatched

The onPatched hook are correct, but then the parent onWillPatch is called after patching its child, so it seems wrong also.

It feels like we actually want this:

parent:onWillPatch
child:onWillPatch
child:onPatched
parent:onPatched

But this would interleave actions taken from two different renderings, which is a big change.

ged-odoo commented 1 year ago

Note that the problem was always present, but may be more pressing now if we use the fine grained reactivity, because there are now many more situations where we have small independent renderings