Open Bug 1733797 Opened 4 years ago Updated 2 months ago

Location's hash setter might need to no-op when set to the same value, null, or empty string fragments

Categories

(Core :: DOM: Window and Location, defect, P3)

Firefox 92
Unspecified
All
defect

Tracking

()

Tracking Status
firefox-esr91 --- affected
firefox94 --- wontfix
firefox95 --- affected
firefox96 --- affected

People

(Reporter: bug-str, Assigned: edgar)

References

Details

(Keywords: parity-chrome, webcompat:platform-bug)

Attachments

(3 files, 2 obsolete files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0

Steps to reproduce:

If I open this link:
https://lithic.com/legal#terms
or
https://lithic.com/legal
scrolling of the page does not work.

Actual results:

There is a scroll bar, but it doesn't not move.

Opening a link with any other #portion, e.g. https://lithic.com/legal#privacy-policy
(or clicking on such a link at the top left portion of the page) clears the scrolling problem.
However if after that, I scroll all the way up, the scrolling is again stuck.

Expected results:

I should be able to scroll the page even if it has some defect in its script, especially since it works in other browsers.

The Bugbug bot thinks this bug should belong to the 'Core::Panning and Zooming' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → Panning and Zooming
Product: Firefox → Core

The page has a scroll event handler which repeatedly sets window.location.hash to the anchor of the section that's currently in view (so, for example, if https://lithic.com/legal#terms is loaded and you scroll down, the terms section is still in view so it performs window.location.hash = "#terms".

It looks like, in Firefox, assigning to window.location.hash a value which matches the current anchor, causes the anchor location to be scrolled into view (i.e. we scroll back to the top of the section), whereas in Chrome it does not.

I'm not sure which behaviour is correct. Moving to DOM: Navigation for further comment.

Component: Panning and Zooming → DOM: Navigation
Component: DOM: Navigation → DOM: Window and Location

Thanks Botond for debugging!

Per the setter description at https://html.spec.whatwg.org/#dom-location-hash Firefox is correct. However, given that Chrome and Safari appear to have an early return, the simplest way forward would probably be changing Firefox and the standard.

Anny, is this something that would interest you?

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(agakhokidze)

We should probably investigate if this applies to other setters as well. And maybe also how this works with <a> and such for good measure.

Summary: Broken scrolling on a specific lithic.com page → Location's hash setter might need to no-op when set to the same value

Not sure if I have time in the near future to work on this, but I'll add it to my list of bugs I could work on if im looking for more tasks.

Flags: needinfo?(agakhokidze)
Severity: -- → S2
Keywords: parity-chrome

@ Anny, do you mind filing the spec issue?

Nika says this bug will be easy to fix, but we should get the ball rolling on the spec change. We'll also want to write a WPT for the new scroll behavior.

If this bug won't get fixed soon, we can file a webcompat.com issue and ask the Webcompat team to reach out to lithic.com's web developers.

Nika shared this link to Chrome's early return when the new window.location.hash value which matches the current anchor:

https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/frame/location.cc;l=203-204;drc=984c3018ecb2ff818e900fdb7c743fc00caf7efe

Flags: needinfo?(agakhokidze)
Priority: -- → P3

Clearing needinfo because Anny is working on some more urgent bugs.

Severity: S2 → S3
Flags: needinfo?(agakhokidze)
Assignee: nobody → cpeterson
Status: NEW → ASSIGNED
OS: Unspecified → All

These tests will be updated in the next changeset when Firefox is fixed to match the behavior of Chrome and Safari.

hash is a UTF-8 string, so we don't need to cast chars to char16_t.

Depends on D132546

I filed an HTML spec issue asking what should happen when setting location.hash = location.hash:

https://github.com/whatwg/html/issues/7386

Thanks Chris!

There is another merge request open in the HTML spec in this area, see: https://github.com/whatwg/html/pull/11245 and the impacted WPT test https://github.com/web-platform-tests/wpt/pull/52085

Shannon, thanks for the heads up! I'll expand this bug to include null and empty string fragments.

That said, I don't know when I will have a chance to address my code review feedback and handle the null and empty string fragments. If expedient, I could spin out those cases into separate bugs.

Summary: Location's hash setter might need to no-op when set to the same value → Location's hash setter might need to no-op when set to the same value, null, or empty string fragments

Shannon shared more details on GitHub:

The difference with Firefox is if you navigate to a URL without a fragment and then set it to the empty string. As an example:

  1. Load https://en.wikipedia.org/wiki/HTML (without a # fragment).
  2. Set location.hash = "" in dev tools console.'
  3. The URL in Firefox changes to https://en.wikipedia.org/wiki/HTML# instead of what Chrome and WebKit do of skipping the navigation entirely, and leaving the URL as: https://en.wikipedia.org/wiki/HTML

The behavior is tested by this WPT test: https://wpt.live/html/browsers/history/the-location-interface/location_hash_set_empty_string.html

Attachment #9253159 - Attachment is obsolete: true
Blocks: 1957657

Hi Chris, we recently identified a web compatibility issue caused by differences in how browsers handle setting location.hash to the same value, see https://bugzilla.mozilla.org/show_bug.cgi?id=1957657#c9.
Would it be possible to address the behavior of setting the same hash value first? Perhaps we could split the remaining cases into separate follow-up bugs? Thanks!

Flags: needinfo?(cpeterson)

(In reply to Edgar Chen [:edgar] from comment #17)

Would it be possible to address the behavior of setting the same hash value first? Perhaps we could split the remaining cases into separate follow-up bugs?

Hi Edgar, unfortunately, I don't know when I might have time to resume working on this bug. (I was only working on this bug in my spare time and I'll be going on PTO for the next few weeks.)

I attached a WIP patch four years ago. I didn't land the patch then, IIRC, smaug had asked me to change how the URL and hash are normalized before testing whether the new hash is the same as the current hash. But I just looked at the Phabricator reviews and I don't see such a comment from smaug. So I don't recall what the issue was at the time.

We should probably to rebase the WIP patches and test on try again.

Assignee: cpeterson → nobody
Status: ASSIGNED → NEW
Flags: needinfo?(cpeterson) → needinfo?(echen)

Thanks for your work and the update!

Assignee: nobody → echen
Flags: needinfo?(echen)

Edgar, I have a rebased WIP patch I can attach, if you're going to pick up this bug: https://phabricator.services.mozilla.com/D262061

The patch still needs to address smaug's "compare fragments post-canonicalization" feedback:

https://phabricator.services.mozilla.com/D132546#inline-730945

I think that's necessary to handle URL-encoded fragments such as:

location.hash = "#te<st";
console.assert(location.hash === "#te%3Cst");

in this test:

https://searchfox.org/firefox-main/rev/60308bc3792ef201b82377682de068a5a1c72575/testing/web-platform/tests/html/browsers/history/the-location-interface/same-hash.html#14,36,56

Flags: needinfo?(echen)

Firefox currently fails that WPT:

https://searchfox.org/firefox-main/rev/60308bc3792ef201b82377682de068a5a1c72575/testing/web-platform/meta/html/browsers/history/the-location-interface/same-hash.html.ini#5,8,11,14

In that case, perhaps landing my WIP patch to fix the webcompat issue for non-URL-encoded fragments won't make make things worse? And then URL-encoded fragments can be fixed in a follow-up bug.

Attachment #9253158 - Attachment is obsolete: true

Thank you for the rebased patch! The site reported in bug 1957657 has changed and no longer hit this bug, so I think we could try to address the URL-encoded fragment here.

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

Attachment

General

Created:
Updated:
Size: