Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#60232 closed enhancement (duplicate)

Script Modules API: Add import map polyfill

Reported by: luisherranz Owned by:
Priority: normal Milestone: 6.5
Component: Script Loader Version:
Severity: major Keywords:
Cc: Focuses: javascript

Description

Now that WordPress is going to support import maps through the new Modules API, we need to make sure that they work on the majority of browsers because even though all the major ones already support import maps, some old versions still require a polyfill.

The requirements for such polyfill are:

  • As all the modern browsers already support import maps and the polyfill is only for compatibility with old browsers, the polyfill should only be downloaded when the browser doesn't support import maps. So instead of the entire polyfill, we should add an inline script that checks if the polyfill is needed, and only add it in that case.
  • The polyfill should only provide functionality for the import maps and nothing else to be able to safely remove it in the future. So we need to make sure that the polyfill doesn't include other functionality than just the import map polyfilling.
  • The polyfill script will need to be maintained until the percentage of users using old browsers without import map support drops significantly.

I've opened ​an issue on the es-module-shims repository to start working on that, and this work should be finished before the WordPress 6.5 release.

Change History (5)

#1 @Bernhard Reiter
3 years ago

  • Milestone Awaiting Review → 6.5

#2 @gziolo
3 years ago

We have a solution to conditionally load the polyfill only in the browsers that don’t implement natively import maps. Therefore there is no risk of introducing backward compatibility issue by exposing the additional features that polyfill provides because the same features don’t exist today for 90% of browser clients used by users as of today. It seems that mirroring how Gutenberg loads the polyfill would conclude the task.

#3 @luisherranz
3 years ago

Totally true. Thanks, @gziolo. Therefore, we can safely include es-module-shims as it is today as long as we load it conditionally, and we will be able to remove it safely in the future.

#4 @luisherranz
3 years ago

  • Summary Modules API: Add import map polyfill → Script Modules API: Add import map polyfill

#5 @luisherranz
3 years ago

  • Resolution → duplicate
  • Status new → closed

Duplicate of #60348.

It looks like @cbravobernal opened another Trac ticket for this. Closing this one as duplicate because they other one already contains a PR.

Note: See TracTickets for help on using tickets.