Bug 194299

Summary: REGRESSION: Elements tab: Uncaught Exception: No node with given id found
Product: WebKit Reporter: Matt Baker <mattbaker>
Component: Web InspectorAssignee: Matt Baker <mattbaker>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, hi, inspector-bugzilla-changes, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
URL: file:///Users/mattbaker/Desktop/Test%20pages/delete-multiple-dom-nodes.html
Attachments:
Description Flags
[HTML] Test Page
none
Patch
none
Patch for landing none

Description Matt Baker 2019-02-05 12:58:44 PST
Created attachment 361211 [details]
[HTML] Test Page

-------
Inspected URL:        file:///Users/mattbaker/Desktop/Test%20pages/delete-multiple-dom-nodes.html
Loading completed:    true
Frontend User Agent:  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko)

Uncaught Exceptions:
 - No node with given id found (at Connection.js:158:29)
    _dispatchResponseToPromise @ Connection.js:158:29
    _dispatchResponse @ Connection.js:120:44
    dispatch @ Connection.js:70:35
    dispatchMessageFromTarget @ TargetManager.js:101:35
    dispatchMessageFromTarget @ TargetObserver.js:42:51
    dispatchEvent @ InspectorBackend.js:340:42
    _dispatchEvent @ Connection.js:195:32
    dispatch @ Connection.js:72:32
    dispatch @ InspectorBackend.js:178:52
    dispatchNextQueuedMessageFromBackend @ MessageDispatcher.js:42:34
-------

* STEPS TO REPRODUCE
1. Inspect test page
2. Elements tab
3. Select and expand DIV "parent-1"
4. Hit delete
  => Uncaught exception
Comment 1 Radar WebKit Bug Importer 2019-02-05 13:15:56 PST
<rdar://problem/47828647>
Comment 2 Matt Baker 2019-03-05 15:46:14 PST
Created attachment 363703 [details]
Patch
Comment 3 Devin Rousso 2019-03-05 22:11:12 PST
Comment on attachment 363703 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363703&action=review

r=me

> Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js:307
> +        this._treeElementsToRemove.sort((a, b) => getLevel(b) - getLevel(a));

Should we sort before calling `removeSelectedItems`?  It should make performance slightly better since it organizes the array to be bottom-up based on the DOM and we check bottom-up inside `canSelectTreeElement`, meaning that the "lower" nodes are more likely to be earlier on in the array.

> Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js:330
> +            return super.canSelectTreeElement(treeElement);

Rather than only using this path if we aren't removing, I think we should flip this around.
```
    if (!super.canSelectTreeElement(treeElement))
        return false;

    let willRemoveAncestorOrSelf = false;
    if (this._treeElementsToRemove) {
        while (treeElement && !willRemoveAncestorOrSelf) {
            willRemoveAncestorOrSelf = this._treeElementsToRemove.includes(treeElement);
            treeElement = treeElement.parent;
        }
    }
    return !willRemoveAncestorOrSelf;
```
Comment 4 Matt Baker 2019-03-06 15:40:50 PST
Created attachment 363803 [details]
Patch for landing
Comment 5 Matt Baker 2019-03-06 15:43:34 PST
Comment on attachment 363703 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363703&action=review

>> Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js:307
>> +        this._treeElementsToRemove.sort((a, b) => getLevel(b) - getLevel(a));
> 
> Should we sort before calling `removeSelectedItems`?  It should make performance slightly better since it organizes the array to be bottom-up based on the DOM and we check bottom-up inside `canSelectTreeElement`, meaning that the "lower" nodes are more likely to be earlier on in the array.

The sort would need to go in SelectionController, and this is only needed for the DOMTreeOutline. If this path needs to be optimized in the future I will investigate then.
Comment 6 WebKit Commit Bot 2019-03-06 16:09:28 PST
Comment on attachment 363803 [details]
Patch for landing

Clearing flags on attachment: 363803

Committed r242577: <https://trac.webkit.org/changeset/242577>
Comment 7 WebKit Commit Bot 2019-03-06 16:09:30 PST
All reviewed patches have been landed.  Closing bug.