odoo/owl

Cannot add 'EffectContainer' in the registry: it already exists

chrisb-c01 opened this issue · 6 comments

Hi there,

opening this issue as a follow-up of this question, since it was closed already.

I'm getting into a loop of console errors after running startServices() in my effort of trying to get translations to work serving OWL components via an Odoo controller.

Mounting the component:

if (document.querySelector('#some-div')) {
    await whenReady();
    const env = makeEnv();
    await startServices(env);
    mount(
        ExampleComponent,
        document.querySelector("#some-div"),
        {
            env, templates, translateFn: _t, dev: true }
    );
}

The error (it gets into an infinite loop):

Error: Cannot add 'EffectContainer' in the registry: it already exists
Error: Cannot add 'DialogContainer' in the registry: it already exists
Error: Cannot add '...' in the registry: it already exists
TypeError: Cannot redefine property: userContext
OwlError: Cannot make the given value reactive
TypeError: env.services.dialog.add is not a function
Error: UI service not initialized!

I tried to mount an App instance instead of the component itself as per the example you suggested (POS self order), however that did not solve it:

import { Component, whenReady, App } from "@odoo/owl";
const app = new App(ExampleComponent, {
        templates,
        env,
        dev: env.debug,
        translateFn: _t,
        translatableAttributes: [],
    });
app.mount(document.querySelector("#some-id");

I would be grateful if anyone can be of assistance in fixing this. Documentation on the use of Owl within an Odoo context is a bit lacking in these areas...

Hm, looks like the services are already started because you're using the assets frontend. If you're trying to write a controller that renders an owl application you should use a custom assets bundle. That or you should use a public component instead of mounting the application yourself, you can search for <owl-component in the Odoo code base.

Although again, this has nothing to do with owl itself, please submit issues with Odoo on the odoo repo or the documentation repo if you believe that it's just poorly documented.

@chrisb-c01 I've written a page in the Odoo docs to explain how to create a standalone application, let me know what you think: https://www.odoo.com/documentation/master/developer/howtos/standalone_owl_application.html

@sdegueldre that is brilliant and will definitely help a lot of people. In Section 2 it is mentioned that services should be started, however the example code does not display this. Is that correct?

I realized mid-way that it was error-prone to do the application setup by hand every time, so I extracted the logic into the mountComponent function and merged that in parallel. Good catch, I'll submit a revision to the documentation page. Long story short, if you're using mountComponent you won't need to start the services or create the env by hand.

@sdegueldre you're the man! Should make all our lives easier :-) Is this also available in 16.0 or would we need to explicitly init the services still?

You'd need to start the services by hand in 16.0, basically what the util is doing now. Since 17.0 is super fresh it wasn't a very risky change but the tradeoff isn't as straightforward for an older stable version