Open Bug 1856655 Opened 2 years ago Updated 1 year ago

Scroll position unexpectedly resets

Categories

(Core :: Layout: Scrolling and Overflow, defect, P3)

Firefox 118
defect

Tracking

()

People

(Reporter: sorvell, Unassigned)

References

(Depends on 2 open bugs)

Details

Attachments

(1 file)

Steps to reproduce:

In the following reproduction:

  1. scroll the orange container to the bottom.
  2. click the Click my to update DOM button.

https://jsfiddle.net/hrbc26a4/8/

Actual results:

The scroll position in the orange container resets to the top.

Expected results:

The scroll position in the orange container should not change.

The Bugbug bot thinks this bug should belong to the 'Core::Layout: Scrolling and Overflow' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Layout: Scrolling and Overflow
Product: Firefox → Core
Attached file Standalone test-case.

So, fwiw, this is because my-main is an inline element. If you give it display: block then you shouldn't see the issue.

This is just because with inline/block-splits, we sometimes reconstruct the whole containing block on some DOM changes, and in this case the scroll position is lost.

I guess the other potential issue is that the scroller is in shadow DOM and this code is probably not accounting for that correctly.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Ok, so we don't restore the scroll position because we use a different state key when removing and when reconstructing, because the removal is what triggers the reconstruct, and the extra children cause our index (and thus state key) to be different.

So there are three issues:

  • The fact that <my-main> is an inline and has blocks causing us to reconstruct the whole containing block.
  • The fact that our state restoration code doesn't deal well with shadow DOM, or dynamic DOM mutations.

I filed dependent bugs for all those things. The more trivial workaround tho is to just make my-main display: block. That prevents hitting the slow path that causes those other bugs to kick in :)

Curious if you found this in a real page, and if so whether the workaround helps or not. That'd help with prioritization.

Thanks for the excellent reduced test-case too, that helps diagnose immensely :)

Flags: needinfo?(sorvell)
See Also: → 1856571

This issue occurred with a real world page using web components.
This has been simplified to check wether the issue came from the framework or from the browser.

Another workaround is to wrap the header in a <section> or any other block element; as using block style on the my-main element may cause trouble with the other CSS.

Thanks for your answer.

Severity: -- → S3
Priority: -- → P3

Clear a needinfo that is pending on an inactive user.

Inactive users most likely will not respond; if the missing information is essential and cannot be collected another way, the bug maybe should be closed as INCOMPLETE.

For more information, please visit BugBot documentation.

Flags: needinfo?(sorvell)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: