Skip to content

Commit

Permalink
Fix race condition caused by calling clear immediately after `annou…
Browse files Browse the repository at this point in the history
…nce` (#141)

* add failing test

* reset pending on clear

* dont need delay to reproduce

* Create silent-beds-suffer.md
  • Loading branch information
siddharthkp authored Sep 20, 2024
1 parent 4fbab15 commit 273ddb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-beds-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/live-region-element": patch
---

Fix race condition caused by calling `clear` immediately after `announce`
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,13 @@ describe('live-region-element', () => {
).toBe(Ordering.Less)
})
})

test('announce() after clear()', async () => {
liveRegion.announce('test1')
expect(liveRegion.getMessage('polite')).toBe('test1')

liveRegion.clear()
liveRegion.announce('test2')
expect(liveRegion.getMessage('polite')).toBe('test2')
})
})
1 change: 1 addition & 0 deletions packages/live-region-element/src/live-region-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class LiveRegionElement extends HTMLElement {
clearTimeout(this.#timeoutId)
this.#timeoutId = null
}
this.#pending = false
this.#queue.clear()
}
}
Expand Down

0 comments on commit 273ddb9

Please sign in to comment.