I have a <div>
set up that I want to add/remove using a Firestore listener. All my documents in my collection have a unique Firestore-generated ID.
The user can press the X button on the element to remove that element from the database whilst also removing it from the frontend.
Everything works, HOWEVER whilst testing I noticed that SOMETIMES
Uncaught DOMException: Failed to execute 'querySelector' on 'Element': '[data-id = 9NrmaFNNBX1DrH940osh]' is not a valid selector.
It works perfectly fine but just randomly (or so I feel since it works half the time but out of the blue just throws me that error).
The code associated with that error message is this:
if (book.type ==="removed") {
let removedCard = mainContent.querySelector(`[data-id = ${uniqueID}]`);
mainContent.removeChild(removedCard);
}
When I refresh, it works perfectly fine on the same element. But especially after deleting multiple elements in a row it happens almost 100%.