Skip to content

Fix preservation of fragments #41807

Open

Description

@TimvdLippe

Make incremental improvements to eventually make tests/wpt/tests/fetch/redirect-navigate/preserve-fragment.html pass. It does load all the iframes correctly, but it doesn't navigate to the fragment. That should have been working because of https://html.spec.whatwg.org/multipage/browsing-the-web.html#updating-the-document:event-hashchange but that's not implemented per spec so likely we are missing a case.

To fix it, we need to look at the following pieces of code:

  1. The location implementation (https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate)
  2. The fetch redirect implementation (https://fetch.spec.whatwg.org/#http-redirect-fetch)
  3. Navigate to a fragment (https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate-fragid)

Activity

  1. added
    A-content/script
    on Jan 9, 2026
  2. TimvdLippe commented on Jan 13, 2026

    @TimvdLippe
    ContributorAuthor

    @mrobinson with #41834 the test now correctly scrolls to the target. However, the window.scrollY is still 0. I briefly looked into it, but got quickly overwhelmed with all the layout stuff.

    Do you know why window.scrollY isn't updated if we do scrollIntoView? See the implementation in #41834 for the updates scroll algorithm for navigation fragments. It doesn't use window.scrollTo since the spec doesn't do so either.

  3. mrobinson commented on Jan 16, 2026

    @mrobinson
    Member

    @mrobinson with #41834 the test now correctly scrolls to the target. However, the window.scrollY is still 0. I briefly looked into it, but got quickly overwhelmed with all the layout stuff.

    Do you know why window.scrollY isn't updated if we do scrollIntoView? See the implementation in #41834 for the updates scroll algorithm for navigation fragments. It doesn't use window.scrollTo since the spec doesn't do so either.

    Sorry for the delay in replying. I took at look at this test and after a bit of minimization it seems that the issue is that the load event is fired before the call to scrollIntoView. I was able to see this by:

    1. Minimizing the test to a single redirect and fragment navigation.
    2. Putting println! right before the call to the fragment-related Element::scroll_into_view_with_options.
    3. Putting a println! in the implementation of ScrollY.

    The ScrollY println! printed before the call to scroll_into_view_with_options. In addition, changing the onload handler to be a setTimeout that fired after 3 seconds caused the test to pass. I suspect that you need to delay the load event when dealing with fragment navigation.

  4. added
    A-navigation
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/scriptA-navigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions