Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#60232 closed enhancement (duplicate)

Script Modules API: Add import map polyfill

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


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 months ago

  • Milestone changed from Awaiting Review to 6.5

#2 @gziolo
3 months 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 months 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 months ago

  • Summary changed from Modules API: Add import map polyfill to Script Modules API: Add import map polyfill

#5 @luisherranz
3 months ago

  • Resolution set to duplicate
  • Status changed from new to 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.