Skip to content

Framework: Use standard polyfill pattern for Element#closest polyfill #7159

@aduth

Description

@aduth

Related: #7033 (specifically overview at #7033 (review) )

We should consolidate our approaches to polyfilling missing behavior, mostly impacting Internet Explorer support. Our use of the element-closest module has proven difficult to maintain. The approach used in #7033 for polyfilling Node#contains is looking to be a better candidate for its maintenance and performance implications.

As part of this, we must determine a way to ensure these polyfills are loaded by all dependent scripts. Some ideas:

In that sense, and given that these are true progressive enhancements which do nothing if a browser is detected to support a given feature, I'd say: Load it everywhere; every WordPress admin screen; for any features we ever use.

#7033 (review)

we should probably not need to load it if:

  • There are zero scripts on a screen otherwise
  • We have some way of knowing / inferring that modern authoring practices are employed
    • Only those which are transpiled (from a build directory)?
    • Some other metric akin to @babel/preset-env@next's useBuiltIns: 'usage'?
    • Register scripts through a new abstracted registration function, e.g. wp_register_script_with_polyfill?

#7033 (comment)

There's a couple things I'd like to see, but not necessarily as part of these changes:

  • Avoid polyfills being considered as dependencies of specific scripts, unless we're certain we can maintain those dependencies.
    • There's nothing about wp-dom that depends on the Node#contains polyfill. Wherever we're using it should be the dependency
    • But then again, this highlights the bigger problem that this is a source of maintenance headaches and is likely not worth maintaining, vs. load always
  • Better names for the script enqueues, which avoids potential plugin incompatibilities. Probably something with a WP-specific prefix, e.g. wp-polyfill-node-contains

#7033 (review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrameworkIssues related to broader framework topics, especially as it relates to javascript[Type] TaskIssues or PRs that have been broken down into an individual action to take

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions