Skip to content

Fix dialog closedby and requestClose() (take 2) #11326

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

keithamus
Copy link
Contributor

@keithamus keithamus commented May 21, 2025

This is a continuation of #10954 to update the dialog element to handle changes to the open attribute. It includes:

  1. New HTML Element insertion steps which:
    1. Run dialog setup if connected & open attribute is present
  2. new HTML element removal steps which:
    1. Run dialog cleanup if open attribute is present
  3. New dialog setup steps which:
    1. Creates the dialog's close watcher.
    2. Adds dialog to the document's open dialogs list.
  4. New dialog cleanup steps which:
    1. Removes dialog from the document's open dialogs list
    2. Destroy close watcher (if the dialog has no open attribute)
  5. Changes to requestClose which:
    1. Returns early if the document is not fully active.

Fixes #10953, #10982, #11259.

(See WHATWG Working Mode: Changes for more details.)


/interactive-elements.html ( diff )

lukewarlow and others added 17 commits May 21, 2025 09:25
When the dialogs open attribute is removed:

1. Remove dialog from the document's open dialogs list.
2. Destroy and nullify dialog's close watcher

This also adds an assertion to the start of
'set the dialog close watcher' that dialog's close watcher is null.
Dialog setup steps:

- Move set the dialog close watcher to step 1
- Add early return when dialog is not connected as a new step 2 (before adding to dialog light dismiss list).

Dialog cleanup steps:

- Remove assertion
- Remove disposing of close watcher.

Dialog attribute change steps:

- Remove connected check from steps 3 and 4.

Dialog insertion steps:

- Remove connected check added in previous commit.
@keithamus keithamus requested a review from zcorpan May 21, 2025 10:03
@keithamus
Copy link
Contributor Author

keithamus commented May 21, 2025

@mfreed7 would you kindly check through this - I believe this closely aligns to the Chrome behaviour, but it would be great if you could confirm.

@annevk you also might want to take a look as we've discussed this in #11230 & #11278.

Additionally @domenic you might want to take a look, this involves close watchers.

@keithamus keithamus changed the title Remove dialog open clear list Fix dialog closedby and requestClose() (take 2) May 21, 2025
@lukewarlow
Copy link
Member

Does https://github.com/web-platform-tests/wpt/pull/50393/files provide anything new that's not already tested?

Copy link
Contributor

@mfreed7 mfreed7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together! I believe this matches the Chromium implementation, modulo the few comments I added.

</li>
<ol>
<li><p>If <var>removedNode</var> has an <code data-x="attr-dialog-open">open</code> attribute,
then run the <span>dialog cleanup steps</span> given <var>removedNode</var>.</p></li>

<li><p>If <var>removedNode</var>'s <span>node document</span>'s <span>top layer</span> <span
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me why we only do these two steps for element removal, and not for open attribute removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things get a little messy here to be honest. Chrome implements #10124 which effectively does the necessary steps. I don't know what would be simpler for us - to try to explain those steps in this PR, or to try to work on getting #10124 landed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that although Chromium implements #10124, it's not shipped yet, just behind experimental web platform features. And #10124 does more than just cleanup steps + top layer removal + is modal -> false; it does the whole "close a dialog" algorithm.

So it sounds like we should merge this PR as-is, as it aligns with what Chromium currently ships and is an improvement over the current spec which is buggy in lots of ways. Then, we should work on making the behavior more sane, which would include at a minimum aligning removal + attribute changed, but could go all the way to making removal and/or attribute changed do a full close (per #10124).

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM with one more typography fix. However, can you help reassure me that everything has web platform tests? For one example, I don't see fully active checks in the Chromium implementation. (They might be hidden in a base class or something.)

I'll also give people a few more days to review in case, and plan on merging next Monday Japan time if you reassure me on the test coverage.

</li>
<ol>
<li><p>If <var>removedNode</var> has an <code data-x="attr-dialog-open">open</code> attribute,
then run the <span>dialog cleanup steps</span> given <var>removedNode</var>.</p></li>

<li><p>If <var>removedNode</var>'s <span>node document</span>'s <span>top layer</span> <span
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that although Chromium implements #10124, it's not shipped yet, just behind experimental web platform features. And #10124 does more than just cleanup steps + top layer removal + is modal -> false; it does the whole "close a dialog" algorithm.

So it sounds like we should merge this PR as-is, as it aligns with what Chromium currently ships and is an improvement over the current spec which is buggy in lots of ways. Then, we should work on making the behavior more sane, which would include at a minimum aligning removal + attribute changed, but could go all the way to making removal and/or attribute changed do a full close (per #10124).

@keithamus
Copy link
Contributor Author

However, can you help reassure me that everything has web platform tests?

The tests have somewhat organically grown due to the lack of specification around this, and in addition a lot of this is "action at a distance", so they're not neatly organised but:

We could probably improve coverage, or at least organise it so it is more explicitly aligned to these spec changes, but overall I feel confident with the tests in place, but happy to take suggestions or guidance if you feel it's insufficient.

@domenic
Copy link
Member

domenic commented Jun 19, 2025

Well, I'm especially curious if there are tests for fa98a1c.

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

Successfully merging this pull request may close these issues.

Missing attribute changed steps for dialog can cause assertions to be hit
7 participants