Skip to content
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

Fix: Custom color formatter may end up "bouncing" #20612

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/format-library/src/text-color/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export function getActiveColor( formatName, formatValue, colors ) {
}
}

const ColorPopoverAtLink = ( { isActive, addingColor, value, ...props } ) => {
const ColorPopoverAtLink = ( { addingColor, ...props } ) => {
// There is no way to open a text formatter popover when another one is mounted.
// The first popover will always be dismounted when a click outside happens, so we can store the
// anchor Rect during the lifetime of the component.
const anchorRect = useMemo( () => {
const selection = window.getSelection();
const range =
Expand All @@ -65,7 +68,7 @@ const ColorPopoverAtLink = ( { isActive, addingColor, value, ...props } ) => {
if ( closest ) {
return closest.getBoundingClientRect();
}
}, [ isActive, addingColor, value.start, value.end ] );
}, [] );
Comment on lines -68 to +71
Copy link
Member

Choose a reason for hiding this comment

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

Which of these is changing to cause the cache to be bust and recompute the anchor?

Copy link
Member

Choose a reason for hiding this comment

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

Kinda seems like the anchor calculation should be testing whether it's within the popover, and aborting if so.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like these values shouldn't be changing in the first place, which is something we should be addressing higher up than in this component itself. Notably, I observe that value.start and value.end each change to undefined at some points, which I don't think would ever be expected while this component is mounted.


if ( ! anchorRect ) {
return null;
Expand Down