odoo / owl

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

New props in a component that propagate to all extensions #1628

Open manuelregidor opened 1 month ago

manuelregidor commented 1 month ago

I am trying to add some new props to the Many2XAutocomplete component in a new module. I am doing the following:

Many2XAutocomplete.props = {
    ...Many2XAutocomplete.props,
    nodeOptions: {type: Object, optional: true},
};

I need this new prop to be available in all the components that extend the Many2XAutocomplete component. However, it doesn't seem to propagate. For instance, the module partner_autocomplete also extends the Many2XAutocomplete component with component PartnerMany2XAutocomplete, but I get the props validation error (Invalid props for component 'PartnerMany2XAutocomplete': unknown key 'nodeOptions') when I try to use the values added in the nodeOptions prop in my module.

I could individually add this new prop definition to the PartnerMany2XAutocomplete component, but that would generate a dependency on the module partner_autocomplete that I would like to avoid.

Is there any way to add new props definitions to a component and make them available in all the components that extend it so those props can be used and the validation error does not occurr?

Thank you

sdegueldre commented 1 month ago

This is unrelated to Owl itself, in the future you should ask these kinds of questions on the odoo forums (or maybe on the odoo/documentation repo).

Because of the way that component extensions extend props, there is no great way to do what you're trying to achieve, something that can work is to "prepend" your patch in the assets bundle, this will cause it to be loaded right after all its dependencies are fulfilled and likely before all extensions of the base component. Not super robust but will work in a pinch. Generally, modifying the public API of a component in place is not a great idea though.