Page MenuHomePhabricator

DiscussionTools inserts comment anchors into invisible firstChild nodes
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue:

What happens?:

Example input:

== Test ==
<span style="display: none;">hidden text</span>comment--[[User:Example|Example]] 10:46, 31 October 2025 (UTC)

Output:

<div class="mw-heading mw-heading2 ext-discussiontools-init-section">
<h2 id="Test" data-mw-thread-id="h-Test-20251031104600"><span data-mw-comment-start="" id="h-Test-20251031104600"></span>Test<span data-mw-comment-end="h-Test-20251031104600"></span></h2>
<div class="ext-discussiontools-init-section-bar"><div class="ext-discussiontools-init-section-metadata"></div><div class="ext-discussiontools-init-section-actions"></div></div>
</div>
<p>
<span style="display: none;"><span data-mw-comment-start="" id="c-Example-20251031104600-Test"></span>hidden text</span>comment--<span data-mw-comment-sig="c-Example-20251031104600-Test"></span><a href="/wiki/User:Example" title="User:Example">Example</a> <a href="#c-Example-20251031104600-Test" class="ext-discussiontools-init-timestamplink" title="9 hours ago">10:46, 31 October 2025 (UTC)</a><span class="ext-discussiontools-init-replylink-buttons" data-mw-thread-id="c-Example-20251031104600-Test"></span><span data-mw-comment-end="c-Example-20251031104600-Test"></span>
</p>

The comment is not visibly highlighted, because DiscussionTools puts the comment's range start marker inside the invisible element. For the same reason, the comment is not scrolled into view when the link is opened in a new tab.

What should have happened instead?:

DiscussionTools should not insert markers related to comment anchor or highlighting into invisible elements.

Software version: 1.45.0-wmf.25

Other information:
The issue stems from the implementation of zh:Template:Hidden ping, which puts user page links inside <span style="display: none;">. Comment permalinks thus fail when the template is at the beginning of the comment.

Event Timeline

SunAfterRain updated the task description. (Show Details)
SunAfterRain subscribed.
Bewfip renamed this task from DiscussionTools inserts highlight into invisible elements to DiscussionTools inserts comment anchors into invisible firstChild nodes.Oct 31 2025, 8:53 PM
Bewfip updated the task description. (Show Details)
Bewfip subscribed.

During the on-wiki discussion, hacky methods have been proposed by @PHING to circuvment this issue:

  1. Wrap the hidden element with class="mw-notalk". I prefer this solution, however there are concerns that it may lead to unintended side effects in the future.
<span class="mw-notalk" style="display: none;">hidden text</span>abc...
-- output --
<span class="mw-notalk" style="display: none;">hidden text</span><span data-mw-comment-start="" id="c-Example-20251031104600-Test"></span>abc...

(As explained in the next comment, this method was discovered by SunAfterRain for another template's use case.)

  1. Make an NO_ELEMENT_CHILDREN_ELEMENT_TYPES element be the first child of the hidden element. It surprisingly pushes out the anchor element too. It depends on a weird workaround added for T301427: Discussion tools not working on some pages with videos when using "New video player" beta feature (Uncaught TypeError: startMarker is null).
<span style="display: none;"><wbr>hidden text</span>abc...
<!-- <wbr>, <hr>, <br> are those allowed in wikitext -->
-- output --
<span data-mw-comment-start="" id="c-Example-20251031104600-Test"></span><span style="display: none;"><wbr>hidden text</span>abc...

During the on-wiki discussion, hacky methods have been proposed by @PHING to circuvment this issue:

Let me briefly explain: this issue does not actually originate from Template:Hidden ping, but rather from the edit request template zh:Template:Editprotected. That template also uses a technique similar to Hidden ping at the beginning of its code in an attempt to draw the attention of users with edit permissions. The mw-notalk modification was a fix I applied to that template, and later @PHING submitted an edit request attempting to port it over to Hidden ping.