Skip to content

[FIX] owl-core, owl-blockdom: handle String objects - #2018

Open
seb-odoo wants to merge 2 commits into
odoo:masterfrom
seb-odoo:master-string-types--seb
Open

seb-odoo wants to merge 2 commits into
odoo:masterfrom
seb-odoo:master-string-types--seb

Conversation

@seb-odoo

Copy link
Copy Markdown
Contributor

Two fixes for String objects, which owl already accepts at runtime: a Markup, or a string subclass such as a lazily translated term.

The first commit types markup(value) and .optional(default) for them. The second one makes VText, VHtml and the compiled-block text slot compare the values as text when patching, so a String built again on every render no longer rewrites or re-parses unchanged content.

Details in each commit message.

@seb-odoo

Copy link
Copy Markdown
Contributor Author

Note: somewhat related Odoo PR: odoo/odoo#284440

@seb-odoo

Copy link
Copy Markdown
Contributor Author

Rebased

@alexkuhn alexkuhn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@seb-odoo
seb-odoo force-pushed the master-string-types--seb branch from 80c2340 to 134e741 Compare October 23, 2026 15:33

@seb-odoo seb-odoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes since the last push:

  • A comment of types_defaults.ts now says that only the type of the prop stays string: at runtime the reader gets the String object.

Some notes on the choices made in this PR, to answer the questions before they come.


Disclaimer: these notes are AI-assisted, I read each one before sending it. As usual, feel free to challenge any of them.

@@ -49,7 +49,7 @@ class VHtml {
return;
}
const html2 = other.html;
if (this.html !== html2) {
if (this.html !== html2 && String(this.html) !== String(html2)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html() stays typed string, even if safeOutput gives it a Markup: typing it string | String would need String() at both innerHTML writes and in safeOutput, which this fix does not need. So the new tests cast markup(...) as any, as the existing ones already do.

@zel-odoo zel-odoo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Before this commit, `markup(value)` and the default value of a string
type are typed as a `string`, so `markup(html)` and
`t.string().optional(term)` do not compile with a `String` object,
which both accept at runtime.

This happens because only the vdom types both: `text()` takes a
`string | String`, while these two take the primitive only.
`stringType` tests `instanceof String` to validate a value, and
`markup` passes its value to `new Markup()`, which converts it.

This commit types both for a `String` object, so a `Markup` or a
lazily translated term can be passed. `StringLike<T>` only applies to
a plain string type, so the default of a selection or of a number
stays the same.
Before this commit, `VText.patch`, `VHtml.patch` and the text slot of a
compiled block compare the new value with `!==`, so two `String`
objects holding the same text count as a change: a `Markup` built again
on every render makes the html block re-parse its content and replace
its nodes, losing the selection inside, and a text node has its data
written again.

This happens because an object only matches itself, and all three take
a `String` object: `text()` is typed `string | String`, and
`safeOutput` sends every `Markup` to `html()`.

This commit compares the two values as text, which is what the DOM
receives in the end. The same value keeps its fast path, and the
conversion only runs for two values that are not the same object.
`toText` also returns a string for a `String` object, as its signature
says.
@seb-odoo
seb-odoo force-pushed the master-string-types--seb branch from 134e741 to 858cc39 Compare November 27, 2026 12:37
@seb-odoo seb-odoo changed the title [FIX] owl-core, owl-runtime: handle String objects [FIX] owl-core, owl-blockdom: handle String objects Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants