Closing a dialog restores focus to whatever was focused when it opened.
If nothing was focused -- the reporter's case was a page loaded with focus
still in the browser UI, then a dialog with an autofocused input --
there is nothing to restore, and
HTMLDialogElement::CloseDialog() simply left
document.activeElement on the node inside the dialog that is now
closed and no longer focusable.
The visible symptom from the 2016 report: keydown /
keyup listeners on the document stop firing, so a barcode
scanner typing into the page goes nowhere, and even a reload does not help
until the page is refocused from the browser UI.
The close steps in the HTML spec only say what to do when there is a previously focused element; the CL fills in the missing else branch by clearing the focused element when focus is still inside the dialog.
document.activeElement is
<input id=field>, inside the closed dialog.
The restore and the new fallback are the two halves of one decision, so
they are now a single if/else instead of two separate passes over
previously_focused_element_ -- the second of which used to run
even right after the first had restored focus.
A WPT,
the-dialog-element/dialog-close-focus-no-previous.html, asserts
that document.activeElement is the body after the close; it
fails on a build without the fix.
the-dialog-element WPT directory +
fast/dom/HTMLDialogElement: 146 tests as expected; the three
outliers fail the same way on a build without the patch.