(dev/core#4279) Add configuration option for ESM loader
authorTim Otten <totten@civicrm.org>
Tue, 16 May 2023 04:33:50 +0000 (21:33 -0700)
committerTim Otten <totten@civicrm.org>
Mon, 22 May 2023 21:40:33 +0000 (14:40 -0700)
commit4e272a9fac26f4af9cf58e1b87e43b61c439fc1c
tree6eb758dc87f86962460a89af23a6e73c7ff2e77f
parent09ea80f65265633dc5af8168cb42025db581261d
(dev/core#4279) Add configuration option for ESM loader

(a) I don't really care about customizing `esm_loader` via web UI on a
day-to-day basis. It's not terrible that the web UI has the setting,
but that's not the main point. So why have a setting?

(b) When/if some CMS or CMS-addon causes a break in ESM loading, the
site-builder should be able to swap loaders and work-around the problem.
Neither loader is invicible, but they have some complementary failure-modes.
Compare:

  - If the conflict is two browser-level "importmap"s, then switching
    Civi to "importmap-shim" (`esm.loader.shim`) should work-around that.
  - If the conflict is two copies of "es-module-shims.js", then switching
    to basic "importmap" (`esm.loader.browser`) should work-around that.

(c) I went back/forth on whether the configuration should be a constant
(`CIVICRM_ESM_LOADER`), setting (`esm_loader`), or something even more
esoteric. In the event of a failure/conflict, settings provide the most
media through which the site-builder can enable a work-around, eg

  - Edit `civicrm.settings.php`, or
  - Edit `/etc/civicrm.settings.d`, or
  - Use CLI like `cv vset` or `drush cvapi`
  - Use browser console like `CRM.api3` or `CRM.api4`
  - Use REST API

(d) When/if there's a conflict, the long-term fix will (probably) be
implementation of another loader (`esm.loader.drupal` or `esm.loader.wp`)
based on some future API. At that point, we would need to change the default
for that environment (*without changing defaults for anyone else*). Hence
the support for dynamic defaults (a la `prevNextBackend` or `assetCache`).
CRM/Admin/Form/Setting/Miscellaneous.php
Civi/Core/Container.php
settings/Developer.setting.php