[scoped-registry] Support cross document adoption [chromium/src : main]

0 views
Skip to first unread message

Jayson Chen (Gerrit)

unread,
Sep 10, 2025, 6:56:28 PM (11 days ago) Sep 10
to Mason Freed, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org, dominicc+...@chromium.org
Attention needed from Joey Arhar and Mason Freed

Jayson Chen voted and added 1 comment

Votes added by Jayson Chen

Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 4 (Latest):
Jayson Chen . resolved

Hey all, here's the last big CL for the scoped registry for now. It implements the logic relating to cross document adoption of a node and how we take care of the registry in these scenarios.

Some note:

  • In these scenarios, I found that in certain situation we DO want to know if an element's registry is null instead of by default falling back to the tree scope's registry, but instead of creating new data structure like we did before, I'm leveraging the rare data vector give us this flexibility on registry information storage. 
  • Given that it is the last chunk of implementation of the current spec/WPT requirement, I'm playing around with an optimization idea (patch 3) that should be able to reduce the need of storing registry in an element by a good amount by removing the field in rare data if we can just fallback to the tree scope's registry. Except in some cases (before we move a node cross scope) we want to ensure we retain knowledge from previous scope, for the rest of the majority cases, we could just erase the registry field in rare data if we can rely on the tree scope's registry.

PTAL, thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • Joey Arhar
  • Mason Freed
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I04ac1e032ee7583d07f3a8db08ffa72c6adc9a12
Gerrit-Change-Number: 6934219
Gerrit-PatchSet: 4
Gerrit-Owner: Jayson Chen <jayso...@microsoft.com>
Gerrit-Reviewer: Jayson Chen <jayso...@microsoft.com>
Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
Gerrit-Attention: Joey Arhar <jar...@chromium.org>
Gerrit-Attention: Mason Freed <mas...@chromium.org>
Gerrit-Comment-Date: Wed, 10 Sep 2025 22:56:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Joey Arhar (Gerrit)

unread,
Sep 11, 2025, 9:02:21 PM (10 days ago) Sep 11
to Jayson Chen, Mason Freed, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org, dominicc+...@chromium.org
Attention needed from Jayson Chen and Mason Freed

Joey Arhar added 4 comments

File third_party/blink/renderer/core/dom/element.h
Line 1450, Patchset 4 (Latest): bool explicit_set = false);
Joey Arhar . unresolved

want to add a comment here explaining what explicit_set does?

File third_party/blink/renderer/core/dom/element_rare_data_vector.h
Line 328, Patchset 4 (Latest): std::optional<CustomElementRegistry*> GetCustomElementRegistry() const;
Joey Arhar . unresolved

want to add a comment here explaining the difference between nullptr and nullopt?

File third_party/blink/renderer/core/dom/element_rare_data_vector.cc
Line 552, Patchset 4 (Latest): // We intentionally don't use SetField function because SetField will erase
Joey Arhar . unresolved

I don't understand this... if we aren't supposed to be using SetField, then why is SetField being called here?

File third_party/blink/renderer/core/dom/tree_scope.cc
Line 304, Patchset 4 (Latest):// Custom element registry of a tree scope can only be set once except the tree
Joey Arhar . unresolved

except when the?

Open in Gerrit

Related details

Attention is currently required from:
  • Jayson Chen
  • Mason Freed
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I04ac1e032ee7583d07f3a8db08ffa72c6adc9a12
    Gerrit-Change-Number: 6934219
    Gerrit-PatchSet: 4
    Gerrit-Owner: Jayson Chen <jayso...@microsoft.com>
    Gerrit-Reviewer: Jayson Chen <jayso...@microsoft.com>
    Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
    Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
    Gerrit-Attention: Jayson Chen <jayso...@microsoft.com>
    Gerrit-Attention: Mason Freed <mas...@chromium.org>
    Gerrit-Comment-Date: Fri, 12 Sep 2025 01:02:11 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Mason Freed (Gerrit)

    unread,
    Sep 15, 2025, 8:09:55 PM (6 days ago) Sep 15
    to Jayson Chen, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, blink-re...@chromium.org, blink-rev...@chromium.org, blink-...@chromium.org, dominicc+...@chromium.org
    Attention needed from Jayson Chen

    Mason Freed added 10 comments

    Patchset-level comments
    Mason Freed . resolved

    Generally looks good, just some concerns about the `nullptr` vs. `nullopt` thing.

    File third_party/blink/renderer/core/dom/document.h
    Line 2255, Patchset 4 (Latest): CustomElementRegistry* EffectiveGlobalCustomElementRegistry() const;
    Mason Freed . unresolved

    This could use a comment explaining what it is (i.e. what "effective" means). I don't love the name either - maybe something closer to `CustomElementRegistryIfGlobal()` or something? I don't know.

    File third_party/blink/renderer/core/dom/element.cc
    Line 6638, Patchset 4 (Latest): // If the registry is the same as the tree scope's registry, we typically
    // can clear the registry field in rare data and have the registry implicitly
    Mason Freed . unresolved

    Does this break in some circumstances? E.g. is there some way to later insert an element in between this one and the root, which uses a custom registry, and have that take effect for this element?

    Line 6640, Patchset 4 (Latest): // inferred. There are certain scenarios where we want the registry to be
    Mason Freed . unresolved

    +1 to Joey's comment - it'd be good to enumerate those scenarios.

    File third_party/blink/renderer/core/dom/element_rare_data_vector.h
    Line 328, Patchset 4 (Latest): std::optional<CustomElementRegistry*> GetCustomElementRegistry() const;
    Joey Arhar . unresolved

    want to add a comment here explaining the difference between nullptr and nullopt?

    Mason Freed

    Yeah +1 to this. I'd perhaps go a step further and split it into two methods. One like `bool HasCustomElementRegistrySet()` that is used instead of `std::optional`, and then this one that does `DCHECK(HasCustomElementRegistrySet())` (so you only call it when you've already checked it), and then just returns the pointer. That's a lot easier to keep track of in your head, I think.

    File third_party/blink/renderer/core/dom/element_rare_data_vector.cc
    Line 534, Patchset 4 (Latest): if (fields_.HasField(FieldId::kCustomElementRegistry)) {
    return static_cast<CustomElementRegistry*>(
    fields_.GetField(FieldId::kCustomElementRegistry).Get());
    }
    // Return nullopt to signify that the field has never been set.
    Mason Freed . unresolved

    Yeah, the logic around nullptr vs. nullopt is really hard to wrap your head around.

    Line 547, Patchset 4 (Latest): if (GetField(FieldId::kCustomElementRegistry)) {
    DCHECK(static_cast<CustomElementRegistry*>(
    GetField(FieldId::kCustomElementRegistry))
    ->IsGlobalRegistry());
    }
    Mason Freed . unresolved

    Better not to have DCHECK-only code inside an `if`. Perhaps this instead?

    ```
    DCHECK(!GetField(FieldId::kCustomElementRegistry) ||
    static_cast<CustomElementRegistry*>(
    GetField(FieldId::kCustomElementRegistry))
    ->IsGlobalRegistry());
    ```
    Line 552, Patchset 4 (Latest): // We intentionally don't use SetField function because SetField will erase
    Joey Arhar . unresolved

    I don't understand this... if we aren't supposed to be using SetField, then why is SetField being called here?

    Mason Freed

    I think he means ElementRareDataVector::SetField, rather than the one on `fields_`.

    Line 553, Patchset 4 (Latest): // the field if we set null to the field. However, there are scenarios where
    Mason Freed . unresolved

    Again, good to enumerate scenarios.

    File third_party/blink/renderer/core/dom/tree_scope_adopter.cc
    Line 190, Patchset 4 (Latest): // keep track of it in case the registry is implicitly implied by the
    Mason Freed . unresolved

    nit: `implicitly implied` -> `implied`

    But really this comment is a little hard to parse, if there's anything that can be simplified/clarified?

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Jayson Chen
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I04ac1e032ee7583d07f3a8db08ffa72c6adc9a12
    Gerrit-Change-Number: 6934219
    Gerrit-PatchSet: 4
    Gerrit-Owner: Jayson Chen <jayso...@microsoft.com>
    Gerrit-Reviewer: Jayson Chen <jayso...@microsoft.com>
    Gerrit-Reviewer: Joey Arhar <jar...@chromium.org>
    Gerrit-Reviewer: Mason Freed <mas...@chromium.org>
    Gerrit-Attention: Jayson Chen <jayso...@microsoft.com>
    Gerrit-Comment-Date: Tue, 16 Sep 2025 00:09:47 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Joey Arhar <jar...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages