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

Closed

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 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. The target is not connected anymore so it was assumed we would always need to reset the containers, but the target didn't really change, it was simply replaced to change its tag. So this allows going through the checks to see if updating the containers is needed before triggering the listeners. Since in this case it isn't, they won't be and the iframe will remain intact.

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.

@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.

@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch from 2ab5b63 to 3c9840c Compare May 26, 2025 08:40
@ged-odoo ged-odoo force-pushed the master-mysterious-egg-next branch from 2e9b9d5 to 8c5e439 Compare May 26, 2025 09:15
@ged-odoo ged-odoo force-pushed the master-mysterious-egg-next branch from 8c5e439 to 2e0c6b5 Compare May 26, 2025 09:23
@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch 2 times, most recently from 5d804da to 6264308 Compare May 26, 2025 09:40
@Zynton
Copy link
Author

Zynton commented May 26, 2025

@robinlej So I applied that fix, and I added a test for safety (passes with the fix, doesn't otherwise). I tested manually, with many (nested) snippets and didn't notice any obvious performance cost.

Edit: one test failed ("useDomState callback shouldn't be called when the editingElement is removed") and revealed a special case so instead of removing the lines I put them in an if so they're only executed if the target is still not found in the DOM.

This commit contains multiple changes squashed together, coming from
various pull requests on master-mysterious-egg. These changes includes:

- No image in colorpicker and working gradient editor for preset background
- Clean carousel related tests, remove repeated ones and merge/rename files
- Fix logo adding/removing option
- Use only "color" tabs in countdown color picker options
- Add support for compact hex colors (e.g. #fff)
- Fix color styling
- Fix setExtraStep
- Auto-optimize image upon replace media
- Adapt extra product image to also rely on openMediaDialog
- Use correct mimetype fields from dataset
- Adapt tests
- Refresh Dynamic Snippet Carousel when scrolling mode is changed

Co-authored-by: Alessandro Lupo <[email protected]>
Co-authored-by: Benoit Socias <[email protected]>
Co-authored-by: divy-odoo <[email protected]>
Co-authored-by: emge-odoo <[email protected]>
Co-authored-by: FrancoisGe <[email protected]>
Co-authored-by: Jinjiu Liu <[email protected]>
Co-authored-by: Keval Bhatt <[email protected]>
Co-authored-by: Serhii Rubanskyi - seru <[email protected]>
@ged-odoo ged-odoo force-pushed the master-mysterious-egg-next branch from 2e0c6b5 to 8478118 Compare May 26, 2025 09:50
@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch from 6264308 to b6689f5 Compare May 26, 2025 10:23
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. The target is
not connected anymore so it was assumed we would always need to reset
the containers, but the target didn't really change, it was simply
replaced to change its tag. So this allows going through the checks to
see if updating the containers is needed before triggering the
listeners. Since in this case it isn't, they won't be and the iframe
will remain intact.
@Zynton Zynton force-pushed the mysterious-egg-next-headerfontsize-age branch from b6689f5 to 983a9d1 Compare May 26, 2025 10:27
@ged-odoo ged-odoo force-pushed the master-mysterious-egg-next branch 4 times, most recently from 7b6e21e to 921bf70 Compare May 27, 2025 06:36
@Zynton
Copy link
Author

Zynton commented May 27, 2025

Closed in favor of odoo#211807

@Zynton Zynton closed this May 27, 2025
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.

10 participants