Skip to content

Commit 5c1f34e

Browse files
authored
Skip loadScriptSource if we know the preload is already supposed to be a module (microsoft#164405)
1 parent 5f14f1b commit 5c1f34e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,33 @@ async function webviewPreloads(ctx: PreloadContext) {
247247
return new Function(...args.map(([k]) => k), functionSrc)(...args.map(([, v]) => v));
248248
};
249249

250-
const runKernelPreload = async (url: string, originalUri: string, forceLoadAsModule: boolean): Promise<void> => {
250+
async function runKernelPreload(url: string, originalUri: string, forceLoadAsModule: boolean): Promise<void> {
251+
if (forceLoadAsModule) {
252+
return activateModuleKernelPreload(url);
253+
}
254+
251255
const text = await loadScriptSource(url, originalUri);
252256
const isModule = /\bexport\b.*\bactivate\b/.test(text);
253257
try {
254-
if (isModule || forceLoadAsModule) {
255-
const module: KernelPreloadModule = await __import(url);
256-
if (!module.activate) {
257-
console.error(`Notebook preload (${url}) looks like a module but does not export an activate function`);
258-
return;
259-
}
260-
return module.activate(createKernelContext());
258+
if (isModule) {
259+
return activateModuleKernelPreload(url);
261260
} else {
262261
return invokeSourceWithGlobals(text, { ...kernelPreloadGlobals, scriptUrl: url });
263262
}
264263
} catch (e) {
265264
console.error(e);
266265
throw e;
267266
}
268-
};
267+
}
268+
269+
async function activateModuleKernelPreload(url: string) {
270+
const module: KernelPreloadModule = await __import(url);
271+
if (!module.activate) {
272+
console.error(`Notebook preload '${url}' was expected to be a module but it does not export an 'activate' function`);
273+
return;
274+
}
275+
return module.activate(createKernelContext());
276+
}
269277

270278
const dimensionUpdater = new class {
271279
private readonly pending = new Map<string, webviewMessages.DimensionUpdate>();

0 commit comments

Comments
 (0)