Repository navigation
Conversation
Contributor
Author
|
Note: somewhat related Odoo PR: odoo/odoo#284440 |
seb-odoo
force-pushed
the
master-string-types--seb
branch
from
September 23, 2026 11:16
8340a11 to
80c2340
Compare
Contributor
Author
|
Rebased |
seb-odoo
force-pushed
the
master-string-types--seb
branch
from
October 23, 2026 15:33
80c2340 to
134e741
Compare
seb-odoo
commented
Oct 23, 2026
seb-odoo
left a comment
Contributor
Author
There was a problem hiding this comment.
Changes since the last push:
- A comment of
types_defaults.tsnow says that only the type of the prop staysstring: at runtime the reader gets theStringobject.
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)) { | |||
Contributor
Author
There was a problem hiding this comment.
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.
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
force-pushed
the
master-string-types--seb
branch
from
November 27, 2026 12:37
134e741 to
858cc39
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes for
Stringobjects, which owl already accepts at runtime: aMarkup, or a string subclass such as a lazily translated term.The first commit types
markup(value)and.optional(default)for them. The second one makesVText,VHtmland the compiled-block text slot compare the values as text when patching, so aStringbuilt again on every render no longer rewrites or re-parses unchanged content.Details in each commit message.