@@ -155,7 +155,14 @@ def get_uid_str(uid):
155155
156156# lang: js
157157ESM = """
158- import { importWithMap } from 'https://unpkg.com/dynamic-importmap@0.1.0';
158+ let importWithMap;
159+ try {
160+ importWithMap = (await import('https://unpkg.com/dynamic-importmap@0.1.0')).importWithMap;
161+ } catch(e) {
162+ console.warn("Import of dynamic-importmap failed, trying fallback.");
163+ importWithMap = (await import('https://cdn.vitessce.io/dynamic-importmap@0.1.0/dist/index.js')).importWithMap;
164+ }
165+
159166const successfulImportMap = {
160167 imports: {
161168
@@ -170,11 +177,10 @@ def get_uid_str(uid):
170177};
171178const fallbackImportMap = {
172179 imports: {
173- //"react": "https://cdn.vitessce.io/react@18.2.0/index.js",
174- //"react-dom": "https://cdn.vitessce.io/react-dom@18.2.0/index.js",
175- //"react-dom/client": "https://cdn.vitessce.io/react-dom@18.2.0/es2022/client.mjs",
176-
177- // Replace with version-specific URL below.
180+ "react": "https://cdn.vitessce.io/react@18.2.0/index.js",
181+ "react-dom": "https://cdn.vitessce.io/react-dom@18.2.0/index.js",
182+ "react-dom/client": "https://cdn.vitessce.io/react-dom@18.2.0/es2022/client.mjs",
183+ // Replaced with version-specific URL below.
178184 "vitessce": "https://cdn.vitessce.io/vitessce@3.8.5/dist/index.min.js",
179185 },
180186};
@@ -184,15 +190,13 @@ def get_uid_str(uid):
184190 "react": "https://cdn.vitessce.io/react@18.2.0/index_dev.js",
185191 "react-dom": "https://cdn.vitessce.io/react-dom@18.2.0/index_dev.js",
186192 "react-dom/client": "https://cdn.vitessce.io/react-dom@18.2.0/es2022/client.development.mjs",
187- // Replace with version-specific URL below.
193+ // Replaced with version-specific URL below.
188194 "vitessce": "https://cdn.vitessce.io/@vitessce/dev@3.8.5/dist/index.js",
189195 },
190196};
191197*/
192198
193199async function importWithMapAndFallback(moduleName, importMap, fallbackMap) {
194- console.log(`Importing ${moduleName} with import map`, importMap, fallbackMap);
195-
196200 let result = null;
197201 if (!fallbackMap) {
198202 // fallbackMap is null, user may have provided custom JS URL.
@@ -213,7 +217,7 @@ def get_uid_str(uid):
213217 });
214218 successfulImportMap.imports[moduleName] = importMap.imports[moduleName];
215219 } catch (e) {
216- console.warn(`Importing ${moduleName} failed with import map `, importMap, e );
220+ console.warn(`Importing ${moduleName} failed with importMap `, importMap, "trying fallback", fallbackMap, successfulImportMap );
217221 result = await importWithMap(moduleName, {
218222 imports: {
219223 ...fallbackMap.imports,
@@ -315,7 +319,6 @@ def get_uid_str(uid):
315319}
316320
317321async function render(view) {
318- console.log("Rendering Vitessce widget...");
319322 const cssUid = view.model.get('uid');
320323 const jsDevMode = view.model.get('js_dev_mode');
321324 const jsPackageVersion = view.model.get('js_package_version');
0 commit comments