Skip to content

[performance] applying the polyfill in self contained web components with light dom #254

@tlouisse

Description

@tlouisse

Hi,
as one of the creators of a component library I want to apply this polyfill inside our components (that is, a consumer would load the polyfill and our web component responds to class/attr changes + it calls applyFocusVisiblePolyfill)

The readme states the following code is needed for shadow dom support. If our interactive element lived in shadow dom, this would be sufficient.

if (window.applyFocusVisiblePolyfill != null) {
  window.applyFocusVisiblePolyfill(myComponent.shadowRoot);
}

However, in our situation the interactive element lives in light dom. Thus, we should do within the component:

if (window.applyFocusVisiblePolyfill != null) {
  window.applyFocusVisiblePolyfill(this.getRootNode());
}

See a working example of how this would be applied here: https://webcomponents.dev/edit/NDbZaQP8185CCrMVZ7Rk/src/index.stories.js

Problem here: all siblings will do the same, leading to multiple registrations for the same node.
Would it be possible to make sure the polyfill only handles nodes max 1 time (for instance by maintaing a WeakMap and returning when already handled)?
This way, we can keep our web components self contained (without needing an extra orchestration layer for this) and performant.

Thanks in advance. I hope my explanation is a bit clear :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions