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

Don't throw when popover/dialog is in requested state #9142

Merged
merged 7 commits into from
May 9, 2023

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Apr 10, 2023

This patch makes the following changes:

  • Don't throw exceptions when showPopover or hidePopover is called and the popover is already in the requested state.
  • Don't throw exceptions when dialog.showModal, dialog.show, or dialog.close is called and the dialog is already in the requested state.
  • Throw exceptions when trying to switch between modal and non-modal dialog modes via dialog.showModal or dialog.show.

Fixes #9045

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


/interactive-elements.html ( diff )
/popover.html ( diff )

This patch makes the following changes:
- Don't throw exceptions when showPopover or hidePopover is called and
  the popover is already in the requested state.
- Don't throw exceptions when dialog.showModal, dialog.show, or
  dialog.close is called and the dialog is already in the
  requested state.
- Throw exceptions when trying to switch between modal and non-modal
  dialog modes via dialog.showModal or dialog.show.

Fixes whatwg#9045
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@nt1m nt1m added topic: popover The popover attribute and friends topic: dialog The <dialog> element labels Apr 12, 2023
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Looks good editorially.

source Outdated
<li><p>If <span>this</span> has an <code data-x="attr-dialog-open">open</code> attribute, then
return.</p></li>
throw an <span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

This is a new exception, how certain are we that this is web compatible?

Copy link
Member

Choose a reason for hiding this comment

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

Tim convinced me that it's unlikely this will break anything.

@annevk annevk added the needs tests Moving the issue forward requires someone to write tests label Apr 24, 2023
@annevk
Copy link
Member

annevk commented Apr 24, 2023

Once this has tests and impl bugs this should be good to go. Thanks @josepharhar!

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 1, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 1, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
@josepharhar
Copy link
Contributor Author

Once this has tests and impl bugs this should be good to go.

Done

@josepharhar
Copy link
Contributor Author

@mfreed7 suggested that we should throw when hidePopover is called on a disconnected popover. This PR currently makes disconnected popovers stop throwing when hidePopover is called on them.

Does anyone have thoughts on this? If not I'll make that case start throwing again.

@mfreed7
Copy link
Contributor

mfreed7 commented May 5, 2023

@mfreed7 suggested that we should throw when hidePopover is called on a disconnected popover. This PR currently makes disconnected popovers stop throwing when hidePopover is called on them.

Does anyone have thoughts on this? If not I'll make that case start throwing again.

...my rationale was simply that this is a different case than calling showPopover when it's already showing. Calling showPopover/hidePopover in "invalid" cases should still throw. These include elements not containing the popover attribute, disconnected elements, etc.

@annevk
Copy link
Member

annevk commented May 8, 2023

I don't care strongly, though I suspect it'll be easier for people to use when there are less cases that throw, including what one might think of as erroneous cases. I'm wondering what web developers would do when they encounter the exception. Add a conditional or solve their ordering problem? If they would usually do the former, they are better served by us not throwing.

Either way, this will need some rebasing.

@josepharhar
Copy link
Contributor Author

I resolved the conflicts, which included the current document vs expected document check, which I included in the list of conditions after the no-exception early out.

@mfreed7
Copy link
Contributor

mfreed7 commented May 8, 2023

I don't care strongly, though I suspect it'll be easier for people to use when there are less cases that throw, including what one might think of as erroneous cases. I'm wondering what web developers would do when they encounter the exception. Add a conditional or solve their ordering problem? If they would usually do the former, they are better served by us not throwing.

One quick data point: nobody evaluating the popover API that I worked with encountered this issue, or at least never relayed it to me, so hopefully it's fairly corner case.

My intuition is that we'll most help them by throwing. If you call showPopover() while the element is disconnected, it won't do anything. So calling attention to this seems like the right thing to do, rather than silently succeeding and doing nothing. If the problem was an ordering problem, e.g. popover.showPopover(); document.body.appendChild(popover); then the only fix is to solve the ordering problem. If the problem was a state problem, e.g. function justTryShowing() {popover.showPopover} then the only fix is a conditional. But without a signal like an exception, it'll be very frustrating to try to figure out why the popover isn't showing. (I've encountered this frustration - it's real.)

@annevk annevk merged commit ba956cb into whatwg:main May 9, 2023
webkit-commit-queue pushed a commit to rwlbuis/WebKit that referenced this pull request May 11, 2023
https://bugs.webkit.org/show_bug.cgi?id=255879

Reviewed by Tim Nguyen.

Implement the spec changes from:
whatwg/html#9142

The dialog related changes are tested by dialog-no-throw-requested-state.html.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-no-throw-requested-state-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-no-throw-requested-state.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-attribute-basic.html:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss.html:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-move-documents.html:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/resources/popover-utils.js:
(async sendTab):
(async sendEscape):
(async sendEnter):
(assertPopoverVisibility):
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* Source/WebCore/html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::show):
(WebCore::HTMLDialogElement::showModal):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::checkPopoverValidity):
(WebCore::HTMLElement::showPopover):
(WebCore::HTMLElement::hidePopoverInternal):

Canonical link: https://commits.webkit.org/263957@main
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 16, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 16, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
aarongable pushed a commit to chromium/chromium that referenced this pull request May 16, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4494823
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1144952}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 16, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4494823
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1144952}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 16, 2023
This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4494823
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1144952}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 22, 2023
…e in requested state, a=testonly

Automatic update from web-platform-tests
Don't throw when popovers and dialogs are in requested state

This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4494823
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1144952}

--

wpt-commits: 0297d56d41123bb302ed3fdc84ec4f0fa891c4bf
wpt-pr: 39781
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this pull request May 23, 2023
…e in requested state, a=testonly

Automatic update from web-platform-tests
Don't throw when popovers and dialogs are in requested state

This is being changed in the HTML spec here:
whatwg/html#9142

Change-Id: Ib8aaaf314c2a1de5d082494e5172e029d531c8e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4494823
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1144952}

--

wpt-commits: 0297d56d41123bb302ed3fdc84ec4f0fa891c4bf
wpt-pr: 39781
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 25, 2023
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this pull request May 27, 2023
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request May 31, 2023
…e. r=emilio

Update to be in line with spec discussions at
whatwg/html#9142

Differential Revision: https://phabricator.services.mozilla.com/D178782

UltraBlame original commit: 39007d3d4f3eee8382115fb59e595de006ceca70
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request May 31, 2023
…e. r=emilio

Update to be in line with spec discussions at
whatwg/html#9142

Differential Revision: https://phabricator.services.mozilla.com/D178782

UltraBlame original commit: 39007d3d4f3eee8382115fb59e595de006ceca70
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request May 31, 2023
…e. r=emilio

Update to be in line with spec discussions at
whatwg/html#9142

Differential Revision: https://phabricator.services.mozilla.com/D178782

UltraBlame original commit: 39007d3d4f3eee8382115fb59e595de006ceca70
@mbrodesser-Igalia
Copy link
Member

mbrodesser-Igalia commented Jun 20, 2023

@mfreed7 suggested that we should throw when hidePopover is called on a disconnected popover. This PR currently makes disconnected popovers stop throwing when hidePopover is called on them.
Does anyone have thoughts on this? If not I'll make that case start throwing again.

Assuming this is an edge-case, with unclear developer benefit, consistency with showPopover() and togglePopover() seems preferable. An argument against the current inconsistency is, that it must propagate through the spec down to the calls of https://html.spec.whatwg.org/#check-popover-validity. Let's please make this consistent.

@emilio: what's your view on this?

CC @mfreed7

...my rationale was simply that this is a different case than calling showPopover when it's already showing. Calling showPopover/hidePopover in "invalid" cases should still throw. These include elements not containing the popover attribute, disconnected elements, etc.

@mbrodesser-Igalia
Copy link
Member

CC @josepharhar

@josepharhar
Copy link
Contributor Author

Assuming this is an edge-case, with unclear developer benefit

Let's please make this consistent.

What exactly are you proposing?

consistency with showPopover() and togglePopover() seems preferable

On a disconnected popover:

@mbrodesser-Igalia
Copy link
Member

Assuming this is an edge-case, with unclear developer benefit

Let's please make this consistent.

What exactly are you proposing?

To let hidePopover throw on a disconnected popover.

consistency with showPopover() and togglePopover() seems preferable

On a disconnected popover:

* showPopover will throw

* togglePopover will throw after [Make togglePopover throw more exceptions #9451](https://github.com/whatwg/html/pull/9451)

* hidePopover does not throw after this PR

Then those three methods all throw, hence, are consistent.

@josepharhar
Copy link
Contributor Author

Ok, yeah I suppose that making hidePopover throw on a disconnected popover doesnt necessarily go against the original motivation of the issue that this PR fixed, so I'm ok with making it throw again

@nt1m
Copy link
Member

nt1m commented Jul 5, 2023

The current setup is consistent with dialog fwiw, HTMLDialogElement::close() does not throw, but HTMLDialogElement::showModal() does.

@annevk
Copy link
Member

annevk commented Jul 5, 2023

Yeah, there's a difference between not being able to show and hiding no-opping. This was discussed in one of the many issues.

@mbrodesser-Igalia
Copy link
Member

The current setup is consistent with dialog fwiw, HTMLDialogElement::close() does not throw, but HTMLDialogElement::showModal() does.

Thanks for pointing that out.

Be aware that hidePopover() called on an element without the popover attribute does throw. See https://html.spec.whatwg.org/#dom-hidepopover. That differs from https://html.spec.whatwg.org/#close-the-dialog.

Consistency within the popover API seems preferable, or?

@nt1m
Copy link
Member

nt1m commented Jul 10, 2023

Be aware that hidePopover() called on an element without the popover attribute does throw. See https://html.spec.whatwg.org/#dom-hidepopover. That differs from https://html.spec.whatwg.org/#close-the-dialog.

You can't really change the tagname for <dialog>, so there isn't a parallel here I think.

@mbrodesser-Igalia
Copy link
Member

You can't really change the tagname for <dialog>

True.

, so there isn't a parallel here I think.

@mbrodesser-Igalia
Copy link
Member

Yeah, there's a difference between not being able to show and hiding no-opping. This was discussed in one of the many issues.

Presumably you mean #9142 (comment) and previous comments.

I lack the experience of what web-developers actually prefer. As there are arguments for both behaviors, throwing and not throwing, let's leave the API in the current state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Moving the issue forward requires someone to write tests topic: dialog The <dialog> element topic: popover The popover attribute and friends
Development

Successfully merging this pull request may close these issues.

Should popover/dialog show/hide when already shown/hidden throw?
6 participants