Bug 238093

Summary: preventScroll does not work with dynamically created elements
Product: WebKit Reporter: Elliot Nahman <Elliot.nahman>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: augus.dupin, caleb, cdumez, rik, simon.fraser, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: Mac (Intel)   
OS: macOS 11   
See Also: https://bugs.webkit.org/show_bug.cgi?id=267051

Description Elliot Nahman 2022-03-18 13:46:22 PDT
Safari 15 appears to have implemented the preventScroll option for Element.focus(). See the resolved webkit bug: https://bugs.webkit.org/show_bug.cgi?id=178583. 

While this feature works fine for elements already existing in the DOM, it does not work for dynamically added elements. 

Please see: https://codepen.io/nonmetalhail/pen/KKZzagd
Comment 1 Simon Fraser (smfr) 2022-03-18 13:52:27 PDT
Thanks for the report. I can reproduce.
Comment 2 Radar WebKit Bug Importer 2022-03-18 13:52:39 PDT
<rdar://problem/90502768>
Comment 3 Simon Fraser (smfr) 2022-03-18 14:12:36 PDT
In the bad case we're scrolling via FrameSelection::updateAppearanceAfterLayoutOrStyleChange().
Comment 4 Simon Fraser (smfr) 2022-03-18 14:17:42 PDT
Layout calls FrameSelection::setNeedsSelectionUpdate() which resets m_selectionRevealMode to SelectionRevealMode::Reveal here:

    if (innerTextSizeChanged && frame().selection().isFocusedAndActive() && document().focusedElement() == &inputElement()) {
        // The caps lock indicator was hidden or shown. If it is now visible then it may be occluding
        // the current selection (say, the caret was after the last character in the text field).
        // Schedule an update and reveal of the current selection.
        frame().selection().setNeedsSelectionUpdate(FrameSelection::RevealSelectionAfterUpdate::Forced);
    }

This is trying to ensure that text within the input is scrolled into view, but has the side effect of also triggering page scrolling.