Page MenuHomePhabricator

Section wrapping not working on page on pages with unbalanced templates
Open, HighPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:

References section is expanded by default and cannot be collapsed.
The section has the attribute data-mw-section-id="-2" which seems odd.

What should have happened instead?:

Should be collapsed.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

Jdlrobson-WMF renamed this task from Section wrapping not working on page to Section wrapping not working on page on pages with unbalanced tempaltes.Feb 5 2026, 12:08 AM
Jdlrobson-WMF added a subscriber: cscott.

Fixed with https://en.wikipedia.org/w/index.php?title=3rd_Royal_Lancashire_Militia_(The_Duke_of_Lancaster%27s_Own)&diff=prev&oldid=1336652226
This was an unbalanced template.

@cscott can we detect on render when a page has unbalanced templates and disable section wrapping for those pages?

Section wrapping (invisible <section> elements) or section *collapsing*?

I think you're asking for all section collapsing to be disabled if there is a single uncollapsible ("pseudo") section in the article?

Alternatively, perhaps to suppress section collapsing if a section is followed by a pseudo-section (section-id = -2) so that you don't get "partial" collapsing?

(This bug is perhaps related to T414734: MobileFrontend + Parsoid has different collapsible-section HTML on en.wp main page.)

@cscott asked me for some guidance on a preferred fix here. I think ideally if we can easily do so we want to Suppress all section collapsing on the page if there are any broken sections in the article in the case of unbalanced templates... if that's possible and not a huge lift.

There are two motivations for fixing this:

  1. In legacy parser we disabled all special formatting on the page (lazy loaded images, section collapsing) when we encountered invalid HTML. This was much more obvious to end users that something was broken and they needed to fix it. I worry that if most of the page is working that may be less detectable.
  2. This adds noise to our visual diffs that is not easy to supress.

Alternatively, perhaps to suppress section collapsing if a section is followed by a pseudo-section (section-id = -2) so that you don't get "partial" collapsing?

This is not possible. To avoid cumulative layout shifts we need to know if section collapsing is enabled or not. We currently deduce this based on section elements. We can't easily detect pseudo sections without performance drawbacks.

If we can't fix it, we will just have to manually sift through diffs that fail due to unbalanced templates.

Hope that make sense?

Well, ::querySelector('[data-section-id="-1"],[data-section-id="-2"]') is an easy and relatively-cheap way to determine if there are any broken sections on a given page, so it would be straight-forward to skip the collapsible-contents wrapper if that query returns something other than the empty set. Is that sufficient, though? Can you distinguish a collapsible section wrapper from a <div> that comes from wikitext, eg:

=== Heading ===
<div>
I made this wrapper myself!
</div>
<div>
== But then... ===
</div>
I broke this wrapper.

We would skip section wrapping on this page, but <div>I made this wrapper myself!</div> might still confuse the section wrapping code into thinking there was a legit wrapper there.

What you are describing is not possible. We can't use JS for the initial render. We need to use CSS. We use CSS to collapse sections when we see them as present. We can't use CSS to detect the existence of pseudo sections and then alter the rendering because of it without re-rendering the whole page once JavaScript has loaded.

I'd be happy to walk you through the complex rendering hoops we jump through to support section collapsing on mobile if it would be helpful.

Jdlrobson-WMF renamed this task from Section wrapping not working on page on pages with unbalanced tempaltes to Section wrapping not working on page on pages with unbalanced templates.Feb 12 2026, 10:15 PM
MSantos added a subscriber: JasKaur2004.