From aef37ad52bc3009e684dae700ae8b9608794c307 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 22 May 2023 17:42:06 -0700 Subject: [PATCH] Allow using the shim in fast or slow modes --- Civi/Core/Container.php | 2 +- Civi/Esm/README.md | 3 ++- Civi/Esm/ShimLoader.php | 46 ++++++++++++++++++++++++++++++---- settings/Developer.setting.php | 2 +- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 82768108dd..a4fb4aa275 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -589,7 +589,7 @@ class Container { public static function createEsmLoader($container): object { $name = \Civi::settings()->get('esm_loader'); if ($name === 'auto') { - $name = 'shim'; + $name = 'shim-fast'; \Civi::dispatcher()->dispatch('civi.esm.loader.default', GenericHookEvent::create(['default' => &$name])); } if ($container->has("esm.loader.$name")) { diff --git a/Civi/Esm/README.md b/Civi/Esm/README.md index e19115de34..68048ef49c 100644 --- a/Civi/Esm/README.md +++ b/Civi/Esm/README.md @@ -107,7 +107,8 @@ There are a few variations on how to perform these steps. Each variant defines a (implemented in `Civi\Esm\XXX`). For example, these two are currently implemented: * `esm.loader.browser` (`Civi\Esm\BrowserLoader`): Use pure, browser-based loading with `", json_encode($importMap, $flags)); + return $shimHtml . sprintf("", htmlentities($this->scriptTypes['importmap']), json_encode($importMap, $flags)); } /** * @inheritDoc */ protected function renderModuleScript(array $snippet): string { - return sprintf("\n", $snippet['script']); + return sprintf("\n", htmlentities($this->scriptTypes['module']), $snippet['script']); } /** * @inheritDoc */ protected function renderModuleUrl(array $snippet): string { - return sprintf("\n", $snippet['scriptUrl']); + return sprintf("\n", htmlentities($this->scriptTypes['module']), $snippet['scriptUrl']); } } diff --git a/settings/Developer.setting.php b/settings/Developer.setting.php index 8dea989ea6..74258511de 100644 --- a/settings/Developer.setting.php +++ b/settings/Developer.setting.php @@ -120,7 +120,7 @@ return [ 'is_contact' => 0, 'description' => NULL, 'help_text' => NULL, - 'options' => ['auto' => ts('Default (Auto-detect)'), 'browser' => ts('Browser'), 'shim' => ts('es-module-shims')], + 'options' => ['auto' => ts('Default (Auto-detect)'), 'browser' => ts('Browser'), 'shim-fast' => ts('es-module-shims (fast mode)'), 'shim-slow' => ts('es-module-shims (slow mode)')], ], 'fatalErrorHandler' => [ 'group_name' => 'Developer Preferences', -- 2.25.1