intake: guard hoisted step scripts against absent DOM

Astro hoists multiple step scripts from Wizard even when the step is not
rendered on the current order page. Several steps bound DOM elements at load
time with no presence check, causing null addEventListener errors on unrelated
order pages.

Add step-presence guards to the obvious offenders used by the shared wizard:
IccImportStep, Block6CertStep, WirelessStep, BundledServiceStep, CPNIStep,
and LNPARegionStep.
This commit is contained in:
justin 2026-06-02 13:12:40 -05:00
parent 219507ce74
commit 0fe8ce53ac
6 changed files with 12 additions and 0 deletions

View file

@ -110,6 +110,7 @@ import DeMinimisChoiceExplainer from "../DeMinimisChoiceExplainer.astro";
<script>
import { NONDISCLOSURE_CERT_TEXT } from "../../../lib/fcc_constants";
if (document.querySelector('[data-slug="block6_cert"], [data-step="block6_cert"]')) {
const exUsf = document.getElementById("pw-ex-usf") as HTMLInputElement;
const exTrs = document.getElementById("pw-ex-trs") as HTMLInputElement;
const exNanpa = document.getElementById("pw-ex-nanpa") as HTMLInputElement;
@ -239,4 +240,5 @@ import DeMinimisChoiceExplainer from "../DeMinimisChoiceExplainer.astro";
waive_deminimis_reason: election === "regular" ? (waiveReason.value.trim() || null) : null,
});
});
}
</script>

View file

@ -47,6 +47,7 @@
</style>
<script>
if (document.querySelector('[data-slug="bundled_service"], [data-step="bundled_service"]')) {
const hasBundle = document.getElementById("pw-bs-has-bundle") as HTMLInputElement;
const details = document.getElementById("pw-bs-details") as HTMLElement;
const bundleRev = document.getElementById("pw-bs-bundle-rev") as HTMLInputElement;
@ -95,4 +96,5 @@
} : { has_bundle: false },
});
});
}
</script>

View file

@ -96,6 +96,7 @@
</style>
<script>
if (document.querySelector('[data-slug="cpni_questions"], [data-step="cpni_questions"]')) {
const yearEl = document.getElementById("pw-cpni-year")!;
const reportingYear = new Date().getFullYear() - 1;
yearEl.textContent = String(reportingYear);
@ -165,4 +166,5 @@
});
}
});
}
</script>

View file

@ -72,6 +72,7 @@
</style>
<script>
if (document.querySelector('[data-slug="icc_import"], [data-step="icc_import"]')) {
const drop = document.getElementById("pw-icc-drop") as HTMLElement;
const fileInput = document.getElementById("pw-icc-file") as HTMLInputElement;
const browse = document.getElementById("pw-icc-browse") as HTMLButtonElement;
@ -194,4 +195,5 @@
icc_revenue_source: confirmCb.checked ? "imported" : null,
});
});
}
</script>

View file

@ -61,6 +61,7 @@ import { LNPA_REGIONS } from "../../../lib/lnpa_regions_catalog";
<script>
import { LNPA_REGIONS } from "../../../lib/lnpa_regions_catalog";
if (document.querySelector('[data-slug="lnpa_region"], [data-step="lnpa_region"]')) {
const body = document.getElementById("pw-lnpa-body")!;
const b3Sum = document.getElementById("pw-lnpa-b3-sum")!;
const b4Sum = document.getElementById("pw-lnpa-b4-sum")!;
@ -173,4 +174,5 @@ import { LNPA_REGIONS } from "../../../lib/lnpa_regions_catalog";
}).catch(() => {});
}
});
}
</script>

View file

@ -62,6 +62,7 @@
</style>
<script>
if (document.querySelector('[data-slug="wireless"], [data-step="wireless"]')) {
const infra = document.getElementById("pw-wl-infra") as HTMLSelectElement;
const mvnoWrap = document.getElementById("pw-wl-mvno-wrap") as HTMLElement;
const facWrap = document.getElementById("pw-wl-fac-wrap") as HTMLElement;
@ -109,4 +110,5 @@
};
PW.patchIntakeData({ wireless_meta: meta });
});
}
</script>