Page MenuHomePhabricator

Section wrapping can break encapsulation continuity so that subsequent passes are confused
Open, Needs TriagePublic

Description

Consider,

<h3 id="123">Testing</h3>

{{1x|1=odd

<h3 id="456">Testing2</h3>

asdf

asfd}}

without section wrapping, the data-parsoid on the templated heading is discarded,

<h3 id="123" data-parsoid='{"stx":"html","dsr":[0,25,13,5],"reusedId":true}'>Testing</h3>

<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[27,79,0,0],"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"odd\n\n&lt;h3 id=\"456\">Testing2&lt;/h3>\n\nasdf\n\nasfd"}},"i":0}}]}'>odd</p><span about="#mwt1">

</span><h3 id="456" about="#mwt1">Testing2</h3><span about="#mwt1">

</span><p about="#mwt1">asdf</p><span about="#mwt1">

</span><p about="#mwt1">asfd</p>

however, once section wrapping is enabled, the traverser calls WTUtils::getAboutSiblings that doesn't cross the section boundaries, and therefore doesn't consider the rest of the about siblings as templated, keeping the data-parsoid,

<section data-mw-section-id="0" data-parsoid="{}"></section><section data-mw-section-id="-1" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,81,null,null],"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["&lt;h3 id=\"123\">Testing&lt;/h3>\n\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"odd\n\n&lt;h3 id=\"456\">Testing2&lt;/h3>\n\nasdf\n\nasfd"}},"i":0}},"\n\n"]}'><h3 id="123" data-parsoid='{"stx":"html","dsr":[0,25,13,5],"reusedId":true}'>Testing</h3>

<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[27,79,0,0],"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"odd\n\n&lt;h3 id=\"456\">Testing2&lt;/h3>\n\nasdf\n\nasfd"}},"i":0}}]}'>odd</p><span about="#mwt1">

</span></section><section data-mw-section-id="-1" about="#mwt2" data-parsoid="{}"><h3 id="456" about="#mwt1" data-parsoid='{"stx":"html","reusedId":true}'>Testing2</h3><span about="#mwt1" data-parsoid="{}">

</span><p about="#mwt1" data-parsoid="{}">asdf</p><span about="#mwt1" data-parsoid="{}">

</span><p about="#mwt1" data-parsoid='{"dsr":[null,79,0,0]}'>asfd</p>

</section>

Event Timeline

A pointer in case it's helpful in refreshing memories,

Encapsulation info on sections should not be used to
traverse with since it's designed to be dropped and
may have expanded ranges.

https://github.com/wikimedia/mediawiki-services-parsoid/blob/master/src/Utils/DOMTraverser.php#L170-L173

The fix to this bug is probably to move the section wrapping pass to the end, after we're done discarding data-parsoid. Section wrapping is supposed to be able to be discarded and should maybe be considered an external pass, working on output from the pipeline.

Talked to editing about this briefly today. They made a good argument that "sectionless" output still makes sense in cases of short output (messages, things where we currently strip a <p> wrapper) and that there is a lot of VE code which implicitly expects <p> tags to be at top level which would break if they preserved <section> wrappers.

However, as a slight counter-proposal to @Arlolra above, we could consider making encapsulation on <section> always "correct" within Parsoid, and moving the <section> stripping to a new OutputTransform post processing pass that does a slightly smarter removal and instead of simply dropping <section> wrappers, carefully moves it metadata, widens encapsulation regions, etc for VE. This would let most passes treat sections "normally" and (hopefully) isolate all of the complexity to a single "section stripping" transform.

Change #1311896 had a related patch set uploaded (by Subramanya Sastry; author: Subramanya Sastry):

[mediawiki/services/parsoid@master] Ensure continuity of template wrapping layer after TOC insertion

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

Change #1311896 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Ensure continuity of template wrapping layer after TOC insertion

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

Change #1318304 had a related patch set uploaded (by Subramanya Sastry; author: Subramanya Sastry):

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.24.0-a17

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

Change #1318304 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.24.0-a17

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

Change #1318746 had a related patch set uploaded (by Arlolra; author: Subramanya Sastry):

[mediawiki/vendor@wmf/1.47.0-wmf.13] Bump wikimedia/parsoid to 0.24.0-a17

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

Change #1318746 merged by jenkins-bot:

[mediawiki/vendor@wmf/1.47.0-wmf.13] Bump wikimedia/parsoid to 0.24.0-a17

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

Mentioned in SAL (#wikimedia-operations) [2026-07-28T20:50:11Z] <arlolra@deploy1003> Started scap sync-world: Backport for [[gerrit:1318746|Bump wikimedia/parsoid to 0.24.0-a17 (T19006 T234299 T360814 T385317 T432477 T433018)]], [[gerrit:1318747|Bump wikimedia/parsoid to 0.24.0-a17 (T433018)]]

Mentioned in SAL (#wikimedia-operations) [2026-07-28T20:52:10Z] <arlolra@deploy1003> arlolra: Backport for [[gerrit:1318746|Bump wikimedia/parsoid to 0.24.0-a17 (T19006 T234299 T360814 T385317 T432477 T433018)]], [[gerrit:1318747|Bump wikimedia/parsoid to 0.24.0-a17 (T433018)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-07-28T20:58:30Z] <arlolra@deploy1003> Finished scap sync-world: Backport for [[gerrit:1318746|Bump wikimedia/parsoid to 0.24.0-a17 (T19006 T234299 T360814 T385317 T432477 T433018)]], [[gerrit:1318747|Bump wikimedia/parsoid to 0.24.0-a17 (T433018)]] (duration: 08m 19s)