`bootstrap` should run immediately if `document.readyState === "interactive"`
analogrelay opened this issue · comments
The bootstrap
method has some logic to defer loading until readyState === "complete"
:
aspnet-client-validation/src/index.ts
Lines 938 to 949 in 2276f03
However, this can cause problems if bootstrap
is called from within the DOMContentLoaded
event. There are three readyState
values:
loading
- The document is loadinginteractive
- The document has finished loading and the document has been parsed but sub-resources such as scripts, images, stylesheets and frames are still loading.complete
- The document and all sub-resources have finished loading. The state indicates that the load event is about to fire.
When DOMContentLoaded
fires, the current document.readyState
is interactive
(at least in Chromium-based Edge). Calling bootstrap
here causes it to no-op because readyState !== "complete"
AND DOMContentLoaded
has already fired, so the handler it attaches will never be raised.
The simplest fix is probably to allow document.readyState === "interactive"
to trigger an immediate scan
. Also, it might be useful to make scan
public. If it were public, I could just call that in my own DOMContentLoaded
handler, since there's no reason for the defensive logic in bootstrap
.
I would accept a PR with both the proposed changes. 😊
Yeah, but it's Friday and I am le tired 🤣
Fair. How about you review my PR then when you're well rested. 😄 #22
Deal. Although, we could probably rewrite the scanning to use MutationObserver so it just works automatically 🤔.
You have my attention.