Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should post-connected steps be able to run multiple times during insertion? #1291

Open
domfarolino opened this issue May 31, 2024 · 0 comments

Comments

@domfarolino
Copy link
Member

What is the issue with the DOM Standard?

See #1261 (comment) for context. In short, after #1261, it is possible to run the post-connected steps multiple times/reentrantly for a single element during an insertion. Should that be allowed? Copied from the aforementioned comment:

Imagine a case where you insert two scripts at the same time, i.e., document.body.append(script1, script2). script2 has an invalid type and therefore is not executable upon insertion as-is. script1 does two things:

  1. Moves script2 around in the DOM (thus reentrantly invoking the DOM insertion algorithm, and running script2's post-connected steps for the first time)
  2. Removes script2's invalid type attribute, making it valid/executable (but not immediately executing it, because type attribute mutations do not trigger the script processing model).

At least in Chromium, when script2's post-connected steps run for the second time (as a result of the outermost document.body.append(script1, script2) call finally invoking script2's post-connected steps), script2 will finally execute. Here's the code snippet:

const script1 = document.createElement('script');
script1.innerText = `
  const div = document.querySelector('div');
  div.append(script2);
  script2.removeAttribute('type');
`;

const script2 = document.createElement('script');
script2.id = 'script2';
// Makes the script invalid so that it does not run upon insertion.
script2.type = 'foo';
script2.innerText = 'console.log("grazie");';

document.body.append(script1, script2);

Despite being generally structured like Blink here, WebKit does not run script2 in this scenario, which I think indicates that the post-connected steps do not run the second time for script2. I would love to know why / how WebKit does this, @rniwa do you know? And WDYT @smaug----?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant