Bug 239129 - Web Inspector: Clean up `WI.DOMNode` to no longer require the shared `WI.DOMManager` be passed during construction
Summary: Web Inspector: Clean up `WI.DOMNode` to no longer require the shared `WI.DOMM...
Status: REOPENED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Patrick Angle
URL:
Keywords: InRadar
Depends on: 189687
Blocks:
  Show dependency treegraph
 
Reported: 2022-04-12 09:25 PDT by Patrick Angle
Modified: 2022-05-22 11:13 PDT (History)
4 users (show)

See Also:


Attachments
Patch v1.0 (8.08 KB, patch)
2022-04-12 09:58 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff
Patch v1.1 (9.43 KB, patch)
2022-04-12 13:46 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff
Patch v1.2 - Review nit (9.48 KB, patch)
2022-04-12 14:00 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff
Patch v1.2 - Correct typos in for loops (9.48 KB, patch)
2022-04-12 15:38 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff
[fast-cq] Patch v1.3 - Add reviewer to changelog (9.44 KB, patch)
2022-04-13 11:31 PDT, Patrick Angle
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Angle 2022-04-12 09:25:33 PDT
Followup from review on bug 189687.
Comment 1 Radar WebKit Bug Importer 2022-04-12 09:25:46 PDT
<rdar://problem/91630867>
Comment 2 Patrick Angle 2022-04-12 09:58:18 PDT
Created attachment 457339 [details]
Patch v1.0
Comment 3 Devin Rousso 2022-04-12 12:35:59 PDT
Comment on attachment 457339 [details]
Patch v1.0

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

I actually had something similar I was working on last night :P

> Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js:191
> +    setNodeForId(nodeId, node)

NIT: It's probably not necessary to path both the `nodeId` and `node` given that the `node.id` should match the `nodeId`, so we could just use `node.id` instead.

> Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js:195
> +        this._idToDOMNode[nodeId] = node;

IMO the fact that this is only used in one spot makes me think that having a method for it is maybe overkill.  Yes it's not our usual style to allow for private members to be accessed outside of that class, but perhaps for a one-off like this that's somewhat OK (especially since we don't want this to be used by anyone else).

> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:35
> +    constructor(doc, isInShadowTree, payload)

While we're at it, I think we could/should adjust this to be more in line with modern Web Inspector style:
- rename `doc` to `ownerDocument`
- have `payload` as the first parameter as that's really the only one that's required (yes technically `ownerDocument` is normally expected, but the fact that there's a codepath where it's not used (when `this._nodeType === Node.DOCUMENT_NODE`) in my mind means it's not required)
- move `ownerDocument` and `isInShadowTree` to an `options = {}` parameter
resulting in something like `constructor(payload, {ownerDocument, isInShadowTree} = {})`, which should let us get rid of all the `null` provided when creating any `WI.DOMNode`.

And I'd also make these changes to `WI.DOMNode.newOrExistingFromPayload` so that they match :)
Comment 4 Patrick Angle 2022-04-12 13:46:05 PDT
Created attachment 457411 [details]
Patch v1.1
Comment 5 Devin Rousso 2022-04-12 13:53:03 PDT
Comment on attachment 457411 [details]
Patch v1.1

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

r=me, nice!  Thanks for iterating :)

> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:60
> +        this.ownerDocument = this._nodeType === Node.DOCUMENT_NODE ? this : ownerDocument;

NIT: probably could/should have a `console.assert(this.ownerDocument, this);` right after :)
Comment 6 Patrick Angle 2022-04-12 14:00:04 PDT
Created attachment 457443 [details]
Patch v1.2 - Review nit
Comment 7 Patrick Angle 2022-04-12 15:38:55 PDT
Created attachment 457484 [details]
Patch v1.2 - Correct typos in for loops
Comment 8 Patrick Angle 2022-04-13 11:31:26 PDT
Created attachment 457551 [details]
[fast-cq] Patch v1.3 - Add reviewer to changelog
Comment 9 EWS 2022-04-13 11:54:26 PDT
Committed r292818 (249598@main): <https://commits.webkit.org/249598@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 457551 [details].
Comment 10 Patrick Angle 2022-05-22 11:13:05 PDT
Reverted in https://commits.webkit.org/250847@main due to issues between frontend and backend representation of DOM tree.