Page MenuHomePhabricator

Table of contents: Strange behaviour when heading is part of a hidden element
Closed, ResolvedPublic2 Estimated Story Points

Description

On this page: https://meta.wikimedia.org/wiki/Talk:Terms_of_use?useskin=vector-2022 the "Quotations" section, which is hidden in a collapsed block generated by {{Collapse top}}/{{Collapse bottom}} templates, is always marked as active in the TOC, no matter where you scroll.

image.png (3,454×2,020 px, 601 KB)

image.png (3,454×2,020 px, 568 KB)

Even after clicking on a different section in the TOC, the page jumps there and the TOC momentarily marks the clicked section as active, but upon scrolling "Quotations" becomes active again (and the TOC scrolls to it, which hinders page navigation).

The issue disappears after uncollapsing the hidden content using the "Expand" button or by clicking on the "Quotations" section title in the TOC.

image.png (3,454×2,020 px, 524 KB)

image.png (3,454×2,020 px, 521 KB)

Event Timeline

Jdlrobson renamed this task from Section hidden in a {{Collapse}} template is stuck marked as active in TOC to Table of contents: Strange behaviour when heading is part of a hidden element.Feb 27 2023, 7:38 PM
Jdlrobson subscribed.

It's also confusing it that clicking the link doesn't auto-expand the section.

On legacy Vector this is a bit of a confusing process too: https://meta.wikimedia.org/wiki/Talk:Terms_of_use?useskin=vector#Quotations doesn't do anything.

Personally I don't think these should be included in the table of contents at all. In mobile web, we do not collapse headings that are not direct children of the parser output element so perhaps we should do something similar here. There's also an argument to be made that collapsed content shouldn't use headings.

It's also confusing it that clicking the link doesn't auto-expand the section.

On legacy Vector this is a bit of a confusing process too: https://meta.wikimedia.org/wiki/Talk:Terms_of_use?useskin=vector#Quotations doesn't do anything.

It does for me, on old and new Vector alike: clicking a link to the section, in the TOC or an external link like yours, expands it. If this doesn't work for you, please try debugging it, the code implementing it is here: https://gerrit.wikimedia.org/g/mediawiki/core/+/130ceaf3a07c56b2b1605b51b65de6fb42430a0d/resources/src/jquery/jquery.makeCollapsible.js#165

Personally I don't think these should be included in the table of contents at all. In mobile web, we do not collapse headings that are not direct children of the parser output element so perhaps we should do something similar here. There's also an argument to be made that collapsed content shouldn't use headings.

I think it'd be a mistake to redesign the table of contents completely again in response to this edge case. I think that it should be easy to handle the section being invisible in the code detecting the currently visible section.

I wouldn't consider this bug to be a part of Local-Wiki-Template-And-Gadget-Issues, since the collapsing code is provided by MediaWiki core and intended to be used on pages exactly in this manner. It's only slightly unusual that a heading is collapsed.

ovasileva moved this task from Incoming to Groomed on the Web-Team-Backlog-Archived board.

Per the web team's quarterly grooming, these tasks are being removed from the team's backlog.

Change #1166217 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/skins/Vector@master] sectionObserver: Handle hidden headings

https://gerrit.wikimedia.org/r/1166217

The page where I originally reported the problem has been archived, but it's still reproducible on the example pages from T343906.

This issue is also reported on Chinese Wikipedia (link). The affected page is https://zh.wikipedia.org/wiki/%E6%9E%97%E5%A4%95 (林夕). The "填詞作品列表" section (<h2>) contains multiple <h3> that are hidden (display: none) by default. The reporter uploaded a screen recording of the issue at https://streamable.com/g9xcbs.

When scrolling, the active section in TOC oscillates between that <h2> and the correct position. Setting DOM breakpoint on attribute modification reveals the relevant script to be resources/skins.vector.js/sectionObserver.js. Specifically, the logic inside IntersectionObserver chooses a hidden <h3> to be the closestNegativeEntry. That element has its boundingClientRect to be all zero due to its ancestor having display: none.

I am not sure how to narrow this down further or create a simpler test case.

Change #1166217 merged by jenkins-bot:

[mediawiki/skins/Vector@master] sectionObserver: Handle hidden headings

https://gerrit.wikimedia.org/r/1166217

Etonkovidova subscribed.

Checked on meta wiki wmf.4 - the following pages with TOC (with {{Collapse top}}/{{Collapse bottom}})

work as expected, i.e.

  • navigating on a page with collapsed/uncollapased TOC sections matches the position on a page
  • selecting a point from TOC lands a user on a selected section and highlights the TOC item (displaying it in bold).