From 2bbd5521fe69674699dd01d4cb472440ee0f20b4 Mon Sep 17 00:00:00 2001 From: Esteban Beltran Date: Wed, 27 Sep 2023 13:56:35 +0200 Subject: [PATCH] Sandbox: Use resolveCache to resolve plugin's code file as systemjs does (#75509) * Sandbox: Use resolveCache to resolve plugin's code file as systemjs does * Add clarifying comments --- public/app/features/plugins/sandbox/code_loader.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/public/app/features/plugins/sandbox/code_loader.ts b/public/app/features/plugins/sandbox/code_loader.ts index dfb94698277..6b7626cd802 100644 --- a/public/app/features/plugins/sandbox/code_loader.ts +++ b/public/app/features/plugins/sandbox/code_loader.ts @@ -1,6 +1,7 @@ import { PluginMeta } from '@grafana/data'; import { transformPluginSourceForCDN } from '../cdn/utils'; +import { resolveWithCache } from '../loader/cache'; import { isHostedOnCDN } from '../loader/utils'; import { SandboxEnvironment } from './types'; @@ -40,7 +41,7 @@ export async function loadScriptIntoSandbox(url: string, meta: PluginMeta, sandb export async function getPluginCode(meta: PluginMeta): Promise { if (isHostedOnCDN(meta.module)) { - // should load plugin from a CDN + // Load plugin from CDN, no need for "resolveWithCache" as CDN URLs already include the version const url = meta.module; const response = await fetch(url); let pluginCode = await response.text(); @@ -51,8 +52,10 @@ export async function getPluginCode(meta: PluginMeta): Promise { }); return pluginCode; } else { - //local plugin loading - const response = await fetch(meta.module); + // local plugin. resolveWithCache will append a query parameter with its version + // to ensure correct cached version is served + const pluginCodeUrl = resolveWithCache(meta.module); + const response = await fetch(pluginCodeUrl); let pluginCode = await response.text(); pluginCode = patchPluginSourceMap(meta, pluginCode); pluginCode = patchPluginAPIs(pluginCode);