Skip to content

Missing attribute changed steps for dialog can cause assertions to be hit #10953

@lukewarlow

Description

@lukewarlow
Member

What is the issue with the HTML Standard?

Currently showModal() and show() on a dialog, assert that the dialog isn't in document's open dialogs list.

However, it turns out this isn't always true.

For example if you do:
dialog.showModal(); // Adds the dialog to the open dialogs list
dialog.removeAttribute('open'); // Dialog is now in a strange state
dialog.showModal(); // Assertion fails because the dialog is already in the open dialogs list

The spec needs attribute changed steps for dialog open attribute being removed and needs to remove the dialog from the list.

Activity

lukewarlow

lukewarlow commented on Jan 27, 2025

@lukewarlow
MemberAuthor

Related to #5802 but a more scoped and required fix for the spec.

domenic

domenic commented on Jan 28, 2025

@domenic
Member

I don't understand why the correct fix here is to implement some subset of #5802 instead of removing the broken assert.

lukewarlow

lukewarlow commented on Jan 28, 2025

@lukewarlow
MemberAuthor

For the close watcher aspect it would actually be broken behaviour right now I think. The original close watcher would never be removed from the list so I'm assuming events would fire twice or it would lead to null reference or something.

This also is what chrome implements so I thought it's generally best for the spec to match implementations.

lukewarlow

lukewarlow commented on Jan 28, 2025

@lukewarlow
MemberAuthor

Also removing the assertions doesn't prevent bugs occurring. open dialogs list is a list not an ordered set, which means it can have duplicate entries. I don't know if doing remove(this) only removes the last one or all matching entries but I can potentially see that causing issues too.

lukewarlow

lukewarlow commented on Jan 28, 2025

@lukewarlow
MemberAuthor

cc @mfreed7 (and @keithamus because I know you're implementing in Firefox)

keithamus

keithamus commented on Jan 28, 2025

@keithamus
Member

Yeah it seems the change is observable. We could change the set the dialog close watcher steps to tear down the existing close watcher, if it exists, but that seems a little awkward. I wonder if this allows some level of circumvention of the close watcher anti abuse mechanisms, also?

domenic

domenic commented on Jan 29, 2025

@domenic
Member

Alright, thanks for explaining. It sounds like we have a few options:

Assuming other implementers are OK with it, I'm happy with trying to move forward and applying one of the fixes. I'd appreciate a summary of the delta between #10954 and #10124 / the proposals in #5802 though, to know what the future evolution might look like.

lukewarlow

lukewarlow commented on Jan 29, 2025

@lukewarlow
MemberAuthor

I'll try my best to summarise the differences not wishing to speak for @josepharhar (feel free to correct me if I'm wrong).

#10954 is a minimal set of changes needed to satisfy the spec assertions as written (with the addition of an extra one for clarity), and to match the actual implementation within Chromium (again @mfreed7 correct me if I'm wrong on that).

In summary it adds a new attribute changed step for the dialog element such that if the open attribute is removed, the dialog is removed from the document's list of open dialogs, preventing assertions in showModal/show being hit. It also destroys and nullifies dialog's close watcher, asserting this within 'setup the dialog close watcher'. While definitely a normative change it's designed to spell out the necessary changes for the spec to be in a good state.

#10124 is a more maximal approach to the wider problem of the open attribute, it does new normative changes which solve wider UX (but not spec) issues such as modal dialogs still blocking the document. It does this by invoking the full close algorithm of the dialog, which ensures full cleanup of state. So it's a superset of my proposed change. This requires more thought on changes related to focusing which is I believe the hold up on it.

Side Note: I'm fully supportive of the direction of #10124 and I think it should be the eventual end state of the spec.

I don't think reverting the PR is the best approach, despite contentions around process I believe there is overall support of at least two implementors for the overall gist of the addition and it's largely just the exact specifics that need cleaning up. I also don't believe we would have necessarily found all these issues before merging even if it had stayed unmerged for longer.

I also don't think patching up the spec by removing assertions etc is the correct approach either. I believe there could be observable differences between cleaning up upon calling show/showModal and cleaning up upon removal of the open attribute.

Specs should generally match implementations and that is what my PR proposes.

keithamus

keithamus commented on Jan 29, 2025

@keithamus
Member

to know what the future evolution might look like.

#10954 is/can effectively be a subset; that is to say I believe it is entirely plausible for us to merge #10954 and follow up with #10124. I believe #10954 (or at least something like it) is necessary, and #10124 just adds extra steps that aren't in conflict.

mfreed7

mfreed7 commented on Jan 29, 2025

@mfreed7
Collaborator

Thanks for highlighting this issue! And I roughly/completely agree with the above comments. #10124 is the best eventual state, #10954 is a great (and perhaps less risky?) intermediate step, and we should attempt to land both. Both PRs make the open attribute behavior incrementally better. I suppose we could try to just jump directly to #10124, but that'd require some compat work or an attempt to ship it in a browser. I'm willing to try to do that in Chromium, if it helps the effort, and folks are onboard with that plan.

open dialogs list is a list not an ordered set, which means it can have duplicate entries.

This is a very interesting point. In Chromium, it's actually an ordered set, but also with the same assertions that the spec has, to make sure we're not using it as a set. Kind of belt and suspenders, but I wonder if the spec should make it an ordered set? Given the assertions, it shouldn't be observable.

domenic

domenic commented on Jan 30, 2025

@domenic
Member

Thanks all; that was very helpful. With my editor hat on, I'm convinced that #10954 first is the way to go. I hope someone can follow up with the rest of the #10124 stuff in due time.

We still need to formally confirm multi-implementer interest beyond Chromium. If @lukewarlow can speak for WebKit and/or @keithamus can speak for Gecko in that regard, that's excellent, but I'll defer that judgement to you two.

lukewarlow

lukewarlow commented on Jan 30, 2025

@lukewarlow
MemberAuthor

We still need to formally confirm multi-implementer interest beyond Chromium. If @lukewarlow can speak for WebKit and/or @keithamus can speak for Gecko in that regard, that's excellent, but I'll defer that judgement to you two.

I'm unfamiliar with whatwg procedure on that point but I don't believe I can formally speak for WebKit. Cc @annevk

Having said that they've recently indicated that they will mark the wider feature as positive.

10 remaining items

added a commit that references this issue on Aug 27, 2025
4e71f6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @past@keithamus@domenic@aleventhal@mfreed7

      Issue actions

        Missing attribute changed steps for dialog can cause assertions to be hit · Issue #10953 · whatwg/html