Skip to content

Commit f4d5acd

Browse files
committed
fix: Avoid potential custom element naming conflicts by appending a unique identifier
1 parent 2b217fa commit f4d5acd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ariaNotify-polyfill.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
if (!("ariaNotify" in Element.prototype)) {
2+
let uniqueId = Date.now();
3+
try {
4+
uniqueId = crypto.randomUUID();
5+
} catch {}
6+
const liveRegionCustomElementName = `live-region-${uniqueId}`;
7+
28
class MessageEvent extends Event {
39
constructor(type, { message, ...options }) {
410
super(type, options);
@@ -60,7 +66,7 @@ if (!("ariaNotify" in Element.prototype)) {
6066
}
6167

6268
customElements.define(
63-
"live-region",
69+
liveRegionCustomElementName,
6470
class extends HTMLElement {
6571
#queue = new MessageQueue(this);
6672

@@ -103,11 +109,11 @@ if (!("ariaNotify" in Element.prototype)) {
103109
{ priority = "none", interrupt = "none" } = {}
104110
) {
105111
// Re-use 'live-region', if it already exists
106-
let liveRegion = document.querySelector("live-region");
112+
let liveRegion = document.querySelector(liveRegionCustomElementName);
107113

108114
// Create 'live-region', if it doesn’t exist
109115
if (!liveRegion) {
110-
liveRegion = document.createElement("live-region");
116+
liveRegion = document.createElement(liveRegionCustomElementName);
111117
document.body.appendChild(liveRegion);
112118
}
113119

0 commit comments

Comments
 (0)