Skip to content

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

Merged
zcorpan merged 34 commits intowhatwg:mainfrom
keithamus:remove-dialog-open-clear-list
Aug 27, 2025
Merged

Fix dialog closedby and requestClose() (take 2)#11326
zcorpan merged 34 commits intowhatwg:mainfrom
keithamus:remove-dialog-open-clear-list

Conversation

@keithamus
Copy link
Copy Markdown
Member

@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
Copy Markdown
Member 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
Copy Markdown
Member

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

Copy link
Copy Markdown
Collaborator

@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><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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
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><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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
Member

domenic commented Jun 19, 2025

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

@domenic domenic requested a review from zcorpan June 24, 2025 04:27
@domenic
Copy link
Copy Markdown
Member

domenic commented Jul 15, 2025

@zcorpan can you re-review to clear the "changes requested" that is blocking this from landing?

@lukewarlow
Copy link
Copy Markdown
Member

Is there anything left needed to get this landed (have been out of the loop so not sure what the state of this PR is). It would be good to get the spec fixed up so further implementations can be done (e.g. webkit, servo, ladybird) in a way that we can be more confident.

@zcorpan zcorpan merged commit 4e71f6e into whatwg:main Aug 27, 2025
2 checks passed
@domenic
Copy link
Copy Markdown
Member

domenic commented Aug 28, 2025

I would prefer to have tests for the latest changes, in particular fa98a1c. @lukewarlow, is that something you can help with?

@lukewarlow
Copy link
Copy Markdown
Member

Yeah as part of the WebKit implementation I can add additional tests. I'll be honest though I'm not immediately clear on what a "non fully-active" document actually is that like document.implementation stuff?

@domenic
Copy link
Copy Markdown
Member

domenic commented Aug 28, 2025

The three major sources of non-fully active are: synthetic documents (e.g. document.implementation), documents from disconnected iframes (i.e. const doc = iframe.contentDocument; iframe.remove();), and documents in bfcache (i.e. const doc = iframe.contentDocument; iframe.contentWindow.location.href = "..."). The latter is perhaps the most important to test.

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