Skip to content

[FIX] html_editor: update font size selector on set tag in toolbar #4777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master-mysterious-egg-next
Choose a base branch
from

Conversation

Zynton
Copy link

@Zynton Zynton commented May 22, 2025

In website builder:

  1. Select text
  2. Change heading type in the toolbar

-> the font size selector in the toolbar is blank:

image

This is because the font size input is in an iframe, and a chain of events triggered by chaning the heading type leads to the iframe's document to be re-rendered. This only happens in the website builder because of a call to updateContainers as a step_added handler.

This commit fixes it by rendering the input in a useEffect hook instead of onMounted, and checking that the input is mounted before re-rendering it as well.

image

@robodoo
Copy link

robodoo commented May 22, 2025

This PR targets the un-managed branch odoo-dev/odoo:master-mysterious-egg-next, it needs to be retargeted before it can be merged.

@dmo-odoo
Copy link

@robodoo r+

@robodoo
Copy link

robodoo commented May 22, 2025

Branch master-mysterious-egg-next is not within my remit, imma just ignore it.

@dmo-odoo
Copy link

@robodoo r-

@robodoo
Copy link

robodoo commented May 22, 2025

Branch master-mysterious-egg-next is not within my remit, imma just ignore it.

@dmo-odoo
Copy link

Didn't realize it wasn't for master

@robinlej
Copy link

It looks good, I'll wait for the tests to go green.

One small issue:

  • Select some paragraph or header that is at the default font size for that style (so paragraph -> 16px, h2 -> 40px)
    (Alternatively: set some selection to header 2 and then double click on it to select it again)
  • Open the "Select font style" dropdown and select the current style
    => the font-size input is empty

@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch 5 times, most recently from 9c49b9e to 7d3fffc Compare May 23, 2025 14:21
Comment on lines +4 to +10
import {
removeClass,
removeStyle,
unwrapContents,
wrapInlinesInBlocks,
splitTextNode,
} from "../utils/dom";
Copy link
Author

Choose a reason for hiding this comment

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

This is just linting.

@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch 2 times, most recently from 37253b5 to a668b51 Compare May 23, 2025 14:24
@Zynton
Copy link
Author

Zynton commented May 23, 2025

@robinlej Thanks for reviewing.

I fixed the issue you raised and in doing so I changed approaches entirely (because it couldn't be solved with the other approach).

I added a note in the commit message on future work that might be needed because I lack proper context to know exactly what is or isn't expected in terms of re-rendering of Owl components in the context of html_builder.

Since it touches on some editor specific stuff, I thought it would be best for one of our own to review it too. @sébastien (sge) and I discussed it IRL, I made some more changes, and he approved the approach.

In website builder:

1. Select text
2. Change heading type in the toolbar

-> the font size selector in the toolbar is blank.

This is because the font size input is in an iframe, and a chain of
events triggered by changing the heading type (`setTag`) leads to the
iframe's document to be re-rendered. This only happens in the website
builder because of a call to `updateContainers` as a step_added handler
that triggers the `change_current_options_containers_listeners`.

These listeners are triggered because `setTag` replaced the block which
was the target of the `BuilderOptionsPlugin` with another.

We have a method for when such a reference has changed and it bears a
risk of breaking the selection: `preserveSelection`'s `remapNode.

This binds it to `BuilderOptionsPlugin` so it can update its target in
such a case. This way the target is not lost, the iframe is not
re-rendered, and the toolbar is intact.

Note: broader work might be needed to investigate whether it is normal
that the iframe gets re-rendered, and if so, to guarantee that the input
never gets lost in the process.
@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch from a668b51 to 2ab5b63 Compare May 23, 2025 14:30
@Zynton
Copy link
Author

Zynton commented May 23, 2025

@robinlej Do you know who wrote updateContainers or at least the following section:

if (!this.target || !this.target.isConnected) {
this.lastContainers = this.lastContainers.filter((c) => c.element.isConnected);
this.target = this.lastContainers.at(-1)?.element;
this.dependencies.history.setStepExtra("optionSelection", this.target);
this.dispatchTo("change_current_options_containers_listeners", this.lastContainers);
return;
}
?

If we were to remove return, setStepExtra and dispatchTo would be called anyway, unless we enter if (areSameOptions). Is there a specific reason for skipping these checks when we lost the target?

Removing

this.dependencies.history.setStepExtra("optionSelection", this.target);
this.dispatchTo("change_current_options_containers_listeners", this.lastContainers);
return;
so that the checks happen normally fixes the bug (because the option didn't change, only the reference to the element), so I could remove everything in this PR and simply remove these three lines instead.

So was there a reason for it or can these lines be removed?

cc @sebgeelen

@robinlej
Copy link

Many hands have been involved around updateContainers and many squashes happened in between, so hard to tell. That said, the basic logic around that (returning early if no target) seems to date back from the beginning of the refactoring. But it has moved a lot in the meantime.

From the look of it, it seems mainly there to avoid frequent computations while we can just rely on the last known containers. We could test to see if there's a performance cost to removing it.

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.

4 participants