owl icon indicating copy to clipboard operation
owl copied to clipboard

Props validation fails for type 'Object' on prototype-less objects

Open jum-odoo opened this issue 8 months ago • 0 comments

Scenario

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

class Child extends Component {
    static template = xml`<span t-esc="props.object.value" />`;
    static props = {
        object: {
            type: Object,
            shape: {
                value: String,
            },
        },
    };
}

// Main root component
class Root extends Component {
    static components = { Child };
    static template = xml`Hello <Child object="object" />`;

    setup() {
        this.object = Object.create(null);
        this.object.value = "World";
    }
}

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

Issue

Props validation fails, while the given object prop is indeed an object with the correct shape, although not having the "Object" prototype. While this object does not meet the "instanceof" check, I think it should still be validated as an object.

Cause

Object validation is made via <x> instanceof <Class>, which fails for objects without a prototype (i.e. Object.create(null)).

jum-odoo avatar Apr 17 '25 08:04 jum-odoo