Fix demo race condition
Concurrently highlighting and searching is not safe because it will
modify the nodes during iteration.
diff --git a/demo/index.js b/demo/index.js
index 47fbe1d..290ba69 100644
--- a/demo/index.js
+++ b/demo/index.js
@@ -37,7 +37,16 @@
try {
const { selector } = parseFragment(identifier);
- for await (const range of search(corpus, selector)) mark(range);
+ const ranges = [];
+
+ for await (const range of search(corpus, selector)) {
+ ranges.push(range);
+ }
+
+ for (const range of ranges) {
+ mark(range);
+ }
+
debug.classList.remove('error');
debug.innerText = JSON.stringify(selector, null, 2);
} catch (e) {