Page MenuHomePhabricator

When opening a link to an anchor in Vector 2022, the target is partly hidden behind the sticky header
Closed, ResolvedPublic2 Estimated Story PointsBUG REPORT

Assigned To
Authored By
jhsoby
Oct 1 2025, 11:28 AM
Referenced Files
F66726837: second-b.png
Oct 4 2025, 7:47 AM
F66726835: second-a.png
Oct 4 2025, 7:47 AM
F66726833: one-b.png
Oct 4 2025, 7:47 AM
F66726831: one-a.png
Oct 4 2025, 7:47 AM
F66717871: Screenshot 2025-10-02 at 00.05.19.png
Oct 1 2025, 10:08 PM
F66716965: CleanShot 2025-10-01 at [email protected]
Oct 1 2025, 2:27 PM
F66716651: Screenshot_20251001_132743.png
Oct 1 2025, 11:28 AM
F66716640: Screenshot_20251001_132619.png
Oct 1 2025, 11:28 AM

Description

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

What happens?:
The highlighted target section is almost completely obscured by Vector-2022's sticky header:

Screenshot_20251001_132619.png (318×1 px, 91 KB)

What should have happened instead?:
The top of the target section should be below the sticky header, like this:

Screenshot_20251001_132743.png (442×1 px, 119 KB)

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

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

Event Timeline

jhsoby renamed this task from In Vector-2022, the comment you visit is partly hidden behind the sticky header to When going directly to a comment in Vector-2022, the comment is partly hidden behind the sticky header.Oct 1 2025, 11:29 AM

I believe scroll-padding-top is what makes this work, but in Vector-2022 the sticky header seemingly isn't ready when the DT code runs. If you focus the address bar and press enter you'll notice it works the second time.

I also can't reproduce it locally, so feels like a race condition.

Seems the issue could be the Special:GoToComment link? If you use the link on the timestamp of the comment [https://no.wikipedia.org/wiki/Wikipedia:Torget/Arkiv/2024/august#c-Znuddel-20240731074400-%C3%85rstall], that takes you to the exact spot you're wanting. I wonder why Special:GoToComment doesn't target that same spot, seems it targets something different because I'm finding it impossible to generate or go to my example below's Special:GoToComment link on nowiki??? It's so unintuitive... There's no instructions, it's not the right click Copy link address one, it's not the click the timestamp and it copies to clickboard one....

For example to link to Wikipedia-diskusjon:Portal#Kommentarer til oversikten i forrige seksjon:

Seems the issue could be the Special:GoToComment link? If you use the link on the timestamp of the comment [https://no.wikipedia.org/wiki/Wikipedia:Torget/Arkiv/2024/august#c-Znuddel-20240731074400-%C3%85rstall], that takes you to the exact spot you're wanting.

No, for me it happens with the fragment (#) URL too, but only when I load the page fresh with that link, like @Esanders says (i.e.: copy the URL with the fragment link and open it in a new tab). When the page (and thus the sticky header) has already loaded, it works as expected.

It's somewhat viewer-dependent. For me (Chrome on macOS) it looks just right:

CleanShot 2025-10-01 at 09.26.47@2x.png (454×1 px, 181 KB)

It happens in Chrome on Ubuntu too for me (I normally use Firefox), FWIW.

I found a hook in Vector that might be useful here, but haven't found a logical place in the DiscussionTools code to place it. The hook is marked as internal though, which might be an issue.

mw.hook( 'vector.page_title_scroll' ).add( ( a ) => {
	if ( a.context === 'scrolled-below-page-title' ) {
		// Do scrolling here somehow
	}
} );

DT doesn't actually do scrolling for the hash-linked comments, it's done natively. We could do a delayed non-native scroll after the vector hook runs to fixup the problem.

I just noticed that the same happens in Wikidata too when I visit something like https://www.wikidata.org/wiki/Q42#P26 . So this should be fixed in Vector-2022 and not DiscussionTools.

jhsoby renamed this task from When going directly to a comment in Vector-2022, the comment is partly hidden behind the sticky header to When opening a link with a link fragment in Vector-2022, the target is partly hidden behind the sticky header.Oct 1 2025, 7:29 PM
jhsoby updated the task description. (Show Details)

I just noticed that the same happens in Wikidata too when I visit something like https://www.wikidata.org/wiki/Q42#P26 . So this should be fixed in Vector-2022 and not DiscussionTools.

Oh yes does that to me too Chrome on macOS +- 2-3em below, and Safari is erratic but mostly faaar off.

Screenshot 2025-10-02 at 00.05.19.png (444×2 px, 67 KB)

Change #1192980 had a related patch set uploaded (by Jon Harald Søby; author: Jon Harald Søby):

[mediawiki/skins/Vector@master] Make link targets obscured by sticky header scroll into view

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

I've done some experimenting, and I think I know what's happening (@Esanders already mentioned it: race condition). There is LESS code in https://gerrit.wikimedia.org/g/mediawiki/skins/Vector/+/f2e2939816d6d150240b46d4307294c4ee109abb/resources/skins.vector.js/stickyHeader.less#123 that is intended to avoid this problem. However, it seems to me that that LESS code takes a few milliseconds to actually be loaded into the browser, which is enough time for the browser to already have scrolled to the element indicated in the URL fragment. I tested this by adding --background-color-base: red; in that LESS file just below the scroll-padding-top declaration, and there was a teeny tiny delay before that background color took effect, meaning the same happens to the scroll-padding-top.

So the solution I came up with (the patch just above) was to add a check in stickyHeader.js's initStickyHeader() function, that checks whether the top of the target element is (or would be) obscured by the sticky header. If yes, run .scrollIntoView() on the element, and the now-loaded stickyHeader.less file makes it scroll with the correct scroll padding.

I'm running into the same thing in Firefox, with any logged-in account using the default Vector 22 skin. (It notable does not affect legacy Vector, or logged-out Vector 22; as neither of those have a sticky header by default.)

The Mobile domain sunsetting talk page on mediawiki.org has a good mix of heading lengths and comment lengths, in case its content-dependent around line-wrapping or something.

Example: Opening singe-line comment, under a single-line heading, short page title, in short and wide viewport. In this the entire comment is obscured.

Actual
one-a.png (520×2 px, 100 KB)
Expected
one-b.png (520×2 px, 92 KB)

Example: Longer reply, under a longer opening comment, under a mulit-line heading, in a taller viewport.

ActualExpected
second-a.png (1×2 px, 274 KB)
second-b.png (1×2 px, 281 KB)

@Krinkle Could we allow the skin to specify a default scroll-padding-top and then render that really early (e.g. an inline <style> tag in the <head>)?

@Krinkle Could we allow the skin to specify a default scroll-padding-top and then render that really early (e.g. an inline <style> tag in the <head>)?

According to https://www.mediawiki.org/wiki/Manual:How_to_make_a_MediaWiki_skin#Preparation , skins are "restricted from editing anything inside the HEAD", so I'm not sure how feasible that is? Would adding a non-zero scroll-padding-top that early affect scrolling in contexts where the sticky header is not shown too? I'm not opposed to that (I like there to be a bit of room above the element I'm scrolling to), just asking. :-)

Jdlrobson-WMF set the point value for this task to 2.Oct 21 2025, 5:21 PM
FaviFake renamed this task from When opening a link with a link fragment in Vector-2022, the target is partly hidden behind the sticky header to When opening a link to an anchor in Vector 2022, the target is partly hidden behind the sticky header.Oct 29 2025, 8:13 PM

@Krinkle Could we allow the skin to specify a default scroll-padding-top and then render that really early (e.g. an inline <style> tag in the <head>)?

According to https://www.mediawiki.org/wiki/Manual:How_to_make_a_MediaWiki_skin#Preparation , skins are "restricted from editing anything inside the HEAD", so I'm not sure how feasible that is?

It would probably need to be a core feature that the skin could override for just setting scroll-padding-top, not just allowing the skin to add arbitrary head tags.

Would adding a non-zero scroll-padding-top that early affect scrolling in contexts where the sticky header is not shown too? I'm not opposed to that (I like there to be a bit of room above the element I'm scrolling to), just asking. :-)

Probably in some edge cases, but as you say, scrolling a little too far is much better than not scrolling far enough.

Change #1217591 had a related patch set uploaded (by Esanders; author: Esanders):

[mediawiki/skins/Vector@master] Move scroll-padding-top to render-blocking CSS

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

Change #1192980 abandoned by Esanders:

[mediawiki/skins/Vector@master] Make link targets obscured by sticky header scroll into view

Reason:

See I2f4a476bb474906c05ace1a389ecabea8ab8594f

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

Turns out the scroll-padding-top CSS was only getting added by a JS-loaded module, so moving to the core styles will make it load early enough.

The bug is easily reproduceable by loading a page with network caching disabled in the developer tools (and some bandwidth throttling if necessary).

In the above PatchDemo that is fixed (login is required to enable the sticky header).

Change #1217591 merged by jenkins-bot:

[mediawiki/skins/Vector@master] Move scroll-padding-top to render-blocking CSS

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

DLynch assigned this task to Esanders.