Skip to content

Commit

Permalink
Do not dispatch popstate or hashchange when hasRef changes.
Browse files Browse the repository at this point in the history
This behavior was already agreed upon in
<whatwg/html#7386>, but bug 1544428 was an
implementation edge case needing to be fixed.

An exception is when the fragment contains a directive, in which case a
difference in `hasRef` is sufficient, to retain existing behavior WRT
directives.

Although bug 1544428 is about popstate, hashchange was erroneously being
dispatched, as well, which this patch fixes.

Some tests that depended on the old behavior are updated.

Differential Revision: https://phabricator.services.mozilla.com/D225567

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1544428
gecko-commit: 80bb463edec5a6e91258e1d507196255c60070f4
gecko-reviewers: jjaschke, dom-core, sessionstore-reviewers, dao, farre
  • Loading branch information
zrhoffman authored and moz-wptsync-bot committed Oct 23, 2024
1 parent 2d74d64 commit 12d1c8c
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<meta charset="utf8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help"
href="https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-location-interface:concept-url-fragment-4">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1544428">
<link rel="author" title="Zach Hoffman" href="mailto:zach@zrhoffman.net">
<script>
let popstateTriggered = false;
window.addEventListener("popstate", () => popstateTriggered = true);

let hashchangeTriggered = false;
window.addEventListener("hashchange", () => hashchangeTriggered = true);

test(() => {
assert_equals(location.href.indexOf("#"), -1)
}, "URL has no hash")

location.hash = "";

test(() => {
assert_false(popstateTriggered);
}, "changing the hash from an empty string to an empty string does not trigger a popstate event")

promise_test(async () => {
// hashchange is fired async
await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
assert_false(hashchangeTriggered);
}, "changing the hash from an empty string to an empty string does not trigger a hashchange event")
</script>

0 comments on commit 12d1c8c

Please sign in to comment.