odoo / owl

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

Reactivity: only subscribe components during rendering #1574

Open sdegueldre opened 6 months ago

sdegueldre commented 6 months ago

It's pretty common to have event handlers that mutate the state, and in doing so, need to read the current state.

Currently, this subscribes the component and immediately re-renders it, even though in practice the DOM of the component does not depend on the value that was written

Playground example

One workaround for this is to wrap the reactive object that we're about to modify in a fresh reactive with no callback, but this is not ergonomic and unintuitive

Playground example

Ideally, reactives bound to components should only subscribe to keys that are read during rendering or a rendering-adjacent activity (willRender/rendered/willPatch/patched)