Skip to content

Improve tooltips behavior#9668

Merged
fregante merged 14 commits into
mainfrom
fix/tooltip
Jun 3, 2026
Merged

Improve tooltips behavior#9668
fregante merged 14 commits into
mainfrom
fix/tooltip

Conversation

@kidonng

@kidonng kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member

Fix #9666

Test URLs

Here

Screenshot

Screen.Recording.2026-06-01.at.9.20.58.PM.mov

@kidonng kidonng added the bug label Jun 1, 2026
Comment thread source/helpers/tooltip.tsx Outdated
Comment on lines +69 to +72
observe('.rgh-tooltip', tooltip => {
tooltip.style.display = '';
tooltipContainer!.append(tooltip);
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reason to #9482 (comment) seems to be that tooltip need to be attached to the DOM after the target element. Hence this dance. I also tried custom elements but that need to be in MAIN world.

@kidonng

kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

😬 Code is not the prettiest but should be most correct

@fregante

fregante commented Jun 1, 2026

Copy link
Copy Markdown
Member

So what you're saying is that it works if you append it near the element, and then move it away after the custom element activates?

If so, you can just use a timeout and skip the observer, e.g.

tip = <tool-tip>
el.after(tip)
await delay(0)
ajax.append(tip)

@kidonng

kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

"After" in time, not in location. Timeout does nothing since at this time neither the tooltip nor the target is attached to DOM.

@fregante

fregante commented Jun 1, 2026

Copy link
Copy Markdown
Member

What you said contradicts itself. If "after in time", how can "timeout do nothing"? That's what timeout does. If not 0ms then 100ms will do.

I think that in all cases we generate and immediately append the elements, I don't think there's any scenario in which we create the tooltip and append it to the dom at a later time.

@fregante

fregante commented Jun 1, 2026

Copy link
Copy Markdown
Member

Actually according to chat you should be able to append them together to the body to "warm them up" and then remove them.

document.body.append(el, tooltip);
el.remove();
tooltip.remove()

at this point you can just add tooltip to the ajaxed container and proceed with the regular element insertion.

@kidonng

kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

Sorry, let me rephrase it more clearly. The tooltip works if attached to the DOM at the same time as the target, or after. It does not work it attached if before target (so we can't container.append(tooltip) then return element).

It may work if we setTimeout(appendTooltip, some_time) and return element, but that leaves entirely to call site whether the target element is appended to DOM immediately after (so tooltip can find its target).

@kidonng

kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

Oh wait it seems to work. I'm still not sure it works all the time though.

@kidonng kidonng requested a review from fregante June 1, 2026 14:50

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks ok as a quick fix

Comment thread source/helpers/tooltip.tsx Outdated
const tooltip = createTooltipFor(element, content);
element.append(tooltip);

// #9668

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since linkify-code is broken I stopped using this type of comment unless there's a proper comment (and even then). So a full URL is preferred

margin-left: var(--base-size-6, 0.375rem);
overflow: visible;
/* eslint-disable-next-line css/font-family-fallbacks */
font-family: inherit;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know what's up with this. If Eslint passes with or without this, something must be broken. Restoring...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

npm run fix keeps auto-fixing this one. I added it in since it's kinda related...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah it's been annoying. Sorry yeah let's remove it again 😅 and then I'll look into why that's the case separately.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Different plugin, same issue:

I'm seeing the error in my IDE as a warning (it should be an error) but $ eslint doesn't even mention it as a warning. So it's not us

@fregante

fregante commented Jun 1, 2026

Copy link
Copy Markdown
Member

Does anything from #9508 need to be undone thanks to this fix? I'm thinking the new p- and m- classes added are no longer needed. If you can clean it up in this PR (without affecting sizing/spacing) that'd be great.

@fregante fregante changed the title Fix tooltipped behavior Fix tooltips behavior Jun 1, 2026
@kidonng

kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

unread-anywhere should be unrelated since it uses addToolTip, not tooltipped

@fregante

fregante commented Jun 1, 2026

Copy link
Copy Markdown
Member

#9666 shows this bug on unread-anywhere specifically, so it would be great to target both functions since the issue is the same and this PR wouldn't otherwise close it

Comment thread source/helpers/tooltip.tsx Outdated

@fregante fregante Jun 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the solution is even easier since element is already attached to the document

	const tooltip = createTooltipFor(element, content);
	element.after(tooltip); // triggers connectedCallback()
	appendToPjaxContainer(tooltip);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't need element.append(tooltip), I kept it in case there's issue appending tooltip to container - a not so perfect tooltip is better than none

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I get what you meant earlier now

@kidonng

kidonng commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

Right, I fixed addToolTip. But I checked the button styles are still unrelated (and thus needed).

);

// Occasionally this button appears before "Reviewers", so let's wait a bit longer
await delay(300);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It turns out that there was one instance in which we waited after generating the element, but this was not necessarily desired behavior.

@fregante fregante changed the title Fix tooltips behavior Improve tooltips behavior Jun 3, 2026
@fregante fregante merged commit 6796c84 into main Jun 3, 2026
12 checks passed
@fregante fregante deleted the fix/tooltip branch June 3, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

RGH tooltip behavior doesn't match native

2 participants