Does the ResizeObserver fire first when the page loads?
P粉7432884362024-03-25 20:48:53
0
1
410
It seems that when I pass the node to ResizeObserver.observe() on the DOMContentLoaded event, it is called immediately. Is this considered normal behavior?
Yes, this behavior complies with the specification. They do have this comment: p>
So, in your case, either the element isn't in the DOM yet and case 1 will make it fire, or the element is already there and case 5 will (although in "DOMContentLoaded" it should be 5 ;).
But according to the actual specification, observation should be triggered first no matter what. We can note that Chrome did change its behavior recently in CRBUG 1128016 as before this change they were not initially firing on hidden elements.
Yes, this behavior complies with the specification. They do have this comment: p>
So, in your case, either the element isn't in the DOM yet and case 1 will make it fire, or the element is already there and case 5 will (although in "DOMContentLoaded" it should be 5 ;).
But according to the actual specification, observation should be triggered first no matter what. We can note that Chrome did change its behavior recently in CRBUG 1128016 as before this change they were not initially firing on hidden elements.