WICG / inert

Polyfill for the inert attribute and property.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I check if the polyfill is already loaded?

fwebdev opened this issue · comments

I'm in an environment where parts of all Pages already have loaded the Polyfill. I don't want to load the Polyfill again on those pages by my Component.

commented

We have a similar scenario where inert is getting pulled in multiple times and sets the mutation observers each time. I played around with this locally to figure out if there's a way to only set the InertManager when it hasn't been set yet and found it behaves properly if I move the instantiation into the prototype condition.

Currently

/** @type {!InertManager} */
  const inertManager = new InertManager(document);

  if (!Element.prototype.hasOwnProperty('inert')) {
    Object.defineProperty(Element.prototype, 'inert', {

Recommendation

if (!Element.prototype.hasOwnProperty('inert')) {
    /** @type {!InertManager} */
    const inertManager = new InertManager(document);

    Object.defineProperty(Element.prototype, 'inert', {

Not sure if this is the proper solution, but it's hurt us a couple of times and think it shouldn't create the mutation observers if they're already being observed.

This sounds similar to #163

@timbomckay would you be interested in sending in a PR for that fix?

commented

Ah yes. Meant to do that a while back but never got around to it. We implemented this in our repo and haven't had any issues since. I'll try to get a PR up today or tomorrow.