Fix UploadModal DOM initialization for robust testing

Explicitly find the #uploadModal element within the parsed template wrapper using querySelector instead of relying on firstElementChild. This prevents null pointer exceptions in JSDOM environments where leading whitespace in the template string creates a text node as the first child.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-27 20:55:22 +00:00
1 parent c3c8bd587d
commit 5420163135
1 file changed
+5 -5
+5 -5
View File
@@ -160,11 +160,11 @@ export class UploadModal {
wrapper.innerHTML = html;
this.removeTrackingScripts(wrapper);
targetContainer.appendChild(wrapper.firstElementChild);
this.root = targetContainer.querySelector("#uploadModal");
if (!this.root && targetContainer.lastElementChild && targetContainer.lastElementChild.id === "uploadModal") {
this.root = targetContainer.lastElementChild;
}
const modalRoot = wrapper.querySelector("#uploadModal");
if (!modalRoot) throw new Error("UploadModal template must contain #uploadModal element");
targetContainer.appendChild(modalRoot);
this.root = modalRoot;
this.container = targetContainer;
this.cacheElements();