aspnet-client-validation
aspnet-client-validation copied to clipboard
`bootstrap` should run immediately if `document.readyState === "interactive"`
The bootstrap method has some logic to defer loading until readyState === "complete":
https://github.com/haacked/aspnet-client-validation/blob/2276f038cd97393b524582a412d08499c80e7d88/src/index.ts#L938-L949
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. 😄 https://github.com/haacked/aspnet-client-validation/pull/22
Deal. Although, we could probably rewrite the scanning to use MutationObserver so it just works automatically 🤔.
You have my attention.