document.readyState === "interactive" 是在自定义元素实例化之前触发的吗?

Is document.readyState === "interactive" fired before custom element gets instantiated?

询问是因为我们似乎遇到了问题。 MDN 并没有真正回答这个问题:https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState#values

这取决于您的 JavaScript 是如何加载的。

如果您的脚本是模块或内联脚本或具有 defer,则脚本将在文档被解析后执行。在这种情况下,readyState 将在自定义元素的构造函数和 connectedCallback 中 interactive

defer

This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing DOMContentLoaded.

Scripts with the defer attribute will prevent the DOMContentLoaded event from firing until the script has loaded and finished evaluating.

否则,脚本将在文档被解析之前立即执行。在这种情况下,readyState 将在自定义元素的构造函数和 connectedCallback 中 loading

Scripts without async , defer or type="module" attributes, as well as inline scripts, are fetched and executed immediately, before the browser continues to parse the page.

来源