web: try a limited number of times defining a custom element

This commit is contained in:
Chris Midgley 2021-03-25 22:20:09 +00:00 committed by Mike Welsh
parent 20480ef6d8
commit 2e42942058
1 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,8 @@
/**
* Number of times to try defining a custom element.
*/
const MAX_TRIES = 999;
/** /**
* A mapping between internal element IDs and DOM element IDs. * A mapping between internal element IDs and DOM element IDs.
*/ */
@ -70,7 +75,7 @@ export function registerElement(
let tries = 0; let tries = 0;
while (true) { while (tries < MAX_TRIES) {
let externalName = elementName; let externalName = elementName;
if (tries > 0) { if (tries > 0) {
externalName = externalName + "-" + tries; externalName = externalName + "-" + tries;
@ -96,4 +101,6 @@ export function registerElement(
return externalName; return externalName;
} }
throw new Error("Failed to assign custom element " + elementName);
} }