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

Hide all popovers when beforetoggle shows a popover #10015

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Dec 20, 2023

From @mfreed7's notes in http://crrev.com/c/5141430

It was previously possible to hit some underspecified behavior with something like this:

<div popover id=p1>Popover 1
  <div popover id=p2>Popover 2</div>
</div>
<script>
  p1.showPopover();
  p1.addEventListener('beforetoggle',() => p2.showPopover());
  p1.hidePopover();
</script>

The problem is that "hide all popovers until" doesn't end up with the desired "until" popover on the top of the stack in this case. There is already a similar situation within the "hide all..." algorithm itself, but that only handles the case where a popover being hidden by "hide all..." has the beforetoggle listener. This is the same problem, but for the case that the "until" popover has that listener.

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


/popover.html ( diff )

From @mfreed7's notes in http://crrev.com/c/5141430

It was previously possible to hit some underspecified behavior with
something like this:

```html
<div popover id=p1>Popover 1
  <div popover id=p2>Popover 2</div>
</div>
<script>
  p1.showPopover();
  p1.addEventListener('beforetoggle',() => p2.showPopover());
  p1.hidePopover();
</script>
```

The problem is that "hide all popovers until" doesn't end up with
the desired "until" popover on the top of the stack in this case.
There is already a similar situation within the "hide all..."
algorithm itself, but that only handles the case where a popover
being hidden by "hide all..." has the beforetoggle listener.
This is the same problem, but for the case that the "until" popover
has that listener.
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.

LGTM, but you should obviously get a review from another implementer also.

@domenic domenic added the topic: popover The popover attribute and friends label Jan 25, 2024
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.

Editorially LGTM. @nt1m maybe can help review?

@nt1m
Copy link
Member

nt1m commented Jan 25, 2024

I'm not sure I understand what bug this is fixing, in all browsers the above testcase ends up with both popovers hidden, which seems like what we want?

Can you describe more in detail what the expected / actual result should be in this case?

@josepharhar
Copy link
Contributor Author

It looks like safari and firefox don't pass the newly added wpt yet: https://wpt.fyi/results/html/semantics/popovers/popover-open-in-beforetoggle.html
The WPT doesn't perfectly match the test case in the description. @mfreed7 can you suggest a more helpful explanation? @nt1m does the WPT help explain any better?

@mfreed7
Copy link
Contributor

mfreed7 commented Jan 27, 2024

I'm not sure I understand what bug this is fixing, in all browsers the above testcase ends up with both popovers hidden, which seems like what we want?

So in this test case:

<div popover id=p1>Popover 1
  <div popover id=p2>Popover 2</div>
</div>
<script>
  p1.showPopover();
  p1.addEventListener('beforetoggle',() => p2.showPopover());
  p1.hidePopover();
</script>

the issue is that hiding p1 (last line of script) triggers beforetoggle which opens p2. Before the change, the spec bailed out before all of the popovers were closed. In Chromium, this test case would hit a DCHECK. From the WPT results, it looks like one of the popovers is left open in other browsers.

There's already a very similar bit of the algorithm for "hide all popovers until" at step 6. Step 6.6 detects the newly opened popover and sets a flag to close everything and stop firing events in that case. This PR is the equivalent thing for hidePopover().

@nt1m
Copy link
Member

nt1m commented Jan 27, 2024

If this is the only edge case this changes that seems fine. @annevk Can you think of any unintended consequences of this PR?

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.

Nothing comes to mind. Seems reasonable modulo nit.

@@ -84360,6 +84360,9 @@ dictionary <dfn dictionary>DragEventInit</dfn> : <span>MouseEventInit</span> {
</ol>
</li>

<li><p>Let <var>autoPopoverListContainsThis</var> be true if <var>document</var>'s <span>showing
Copy link
Member

Choose a reason for hiding this comment

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

Nit: it seems weird for this to end in "This" when there's no this in this algorithm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it from "this" to "element"

@domenic domenic merged commit e41f54e into whatwg:main Feb 7, 2024
2 checks passed
@domenic
Copy link
Member

domenic commented Feb 7, 2024

OK, merged! Please remember to file bugs on Gecko and WebKit and update the OP with them.

@josepharhar
Copy link
Contributor Author

gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Feb 20, 2024
…emilio

whatwg/html#10015

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

UltraBlame original commit: 67f44aef7e5026fd3358bdc67a4ad3f302839d34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: popover The popover attribute and friends
Development

Successfully merging this pull request may close these issues.

5 participants