Skip to content

Commit 759c209

Browse files
committed
Fix busy wait in the UI
Don't make the UI wait for a metric to scroll to if the URL has no hash with a metric identifier. Fixes #12598.
1 parent bcc6ee7 commit 759c209

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

components/frontend/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/frontend/src/hooks/hash_fragment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function useHashFragment(trigger = true) {
1616
useEffect(() => {
1717
if (!trigger) return // Only scroll if trigger is true, e.g. after loading data has finished
1818
const { hash } = globalThis.location
19+
if (!hash) return // No hash to scroll to
1920
return waitForElementById(hash?.replace("#", ""), (element) => element.scrollIntoView(true))
2021
}, [trigger])
2122
}

components/frontend/src/hooks/hash_fragment.test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ afterEach(() => {
1313

1414
it("does not scroll if trigger is false", () => {
1515
globalThis.addEventListener = vi.fn()
16+
globalThis.location = { hash: "#d57aa11f-9bbb-4297-91e6-062e20c0a953" }
1617
const mockScrollIntoView = vi.fn()
1718
document.getElementById = () => {
1819
return { scrollIntoView: mockScrollIntoView }
@@ -22,8 +23,21 @@ it("does not scroll if trigger is false", () => {
2223
expect(mockScrollIntoView).not.toHaveBeenCalled()
2324
})
2425

25-
it("does not scroll if trigger is true but no element found", () => {
26+
it("does not scroll if trigger is true but no hash is present", () => {
2627
globalThis.addEventListener = vi.fn()
28+
globalThis.location = { hash: "" }
29+
const mockScrollIntoView = vi.fn()
30+
document.getElementById = () => {
31+
return { scrollIntoView: mockScrollIntoView }
32+
}
33+
renderHook(() => useHashFragment(true))
34+
expect(vi.getTimerCount()).toBe(0)
35+
expect(mockScrollIntoView).not.toHaveBeenCalled()
36+
})
37+
38+
it("does not scroll if trigger is true and hash is present, but element does not appear", () => {
39+
globalThis.addEventListener = vi.fn()
40+
globalThis.location = { hash: "#d57aa11f-9bbb-4297-91e6-062e20c0a954" }
2741
document.getElementById = () => {
2842
return null
2943
}
@@ -34,8 +48,9 @@ it("does not scroll if trigger is true but no element found", () => {
3448
expect(vi.getTimerCount()).toBe(0)
3549
})
3650

37-
it("does scroll if trigger is true and element found", () => {
51+
it("does scroll if trigger is true, hash is present, and element does appear", () => {
3852
globalThis.addEventListener = vi.fn()
53+
globalThis.location = { hash: "#d57aa11f-9bbb-4297-91e6-062e20c0a955" }
3954
const mockScrollIntoView = vi.fn()
4055
document.getElementById = () => {
4156
return { scrollIntoView: mockScrollIntoView }

docs/src/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ If your currently installed *Quality-time* version is not the penultimate versio
1515
### Fixed
1616

1717
- When using an LDAP server with a password hash scheme other than Argon2, Quality-time would not attempt an LDAP bind to verify the user. Fixes [#12595](https://github.com/ICTU/quality-time/issues/12595).
18+
- Don't make the UI wait for a metric to scroll to if the URL has no hash with a metric identifier. Fixes [#12598](https://github.com/ICTU/quality-time/issues/12598).
1819

1920
## v5.48.3 - 2026-01-29
2021

0 commit comments

Comments
 (0)