Skip to content

signal.Set "has" observes too much #1902

@seb-odoo

Description

@seb-odoo
  • Set created with data = signal.Set(new Set());
  • Using data().has(...) on a template.
  • Adding another element in the set data().add(...) (not the one observed)
  • The templare re-renders anyway.
import { Component, mount, xml, signal, onPatched } from "@odoo/owl";

class Root extends Component {
    static template = xml`<div>Hello Owl! <t t-out="this.data().has(1)"/></div>`;
    data = signal.Set(new Set());

    setup() {
        onPatched(() => console.log("patched"));
        setTimeout(() => this.data().add(2), 100);
    }
}

mount(Root, document.body, { templates: TEMPLATES, dev: true });

The bug is not present if using data = proxy(new Set()); instead (and removing () from callers)

import { Component, mount, xml, signal, onPatched, proxy } from "@odoo/owl";

class Root extends Component {
    static template = xml`<div>Hello Owl! <t t-out="this.data.has(1)"/></div>`;
    data = proxy(new Set());

    setup() {
        onPatched(() => console.log("patched"));
        setTimeout(() => this.data.add(2), 100);
    }
}

mount(Root, document.body, { templates: TEMPLATES, dev: true });

signal.Set is supposed to be more efficient as it is shallow (?), but in practice proxy performs better.

Is it a bug or do I miss something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions