From 44eed51887c71aa683656443789016b1143b2842 Mon Sep 17 00:00:00 2001 From: Laurent Caouissin Date: Fri, 8 Nov 2024 14:31:20 +0100 Subject: [PATCH] fix: mount external resources Entry point for Pearl-Jam is only the `mount` function exported by boostrap.tsx --- drama-queen/src/bootstrap.tsx | 19 +++++++++++-------- drama-queen/src/main.tsx | 6 +----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drama-queen/src/bootstrap.tsx b/drama-queen/src/bootstrap.tsx index e179d36b..24e39f82 100644 --- a/drama-queen/src/bootstrap.tsx +++ b/drama-queen/src/bootstrap.tsx @@ -5,6 +5,7 @@ import { RouterProvider } from 'react-router-dom' import { unsubscribeOldSW } from 'unsubscribe_old_sw' import { CoreProvider } from 'createCore' import { createRouter, type RoutingStrategy } from 'ui/routing/createRouter' +import { EXTERNAL_RESOURCES_URL } from 'core/constants' const CenteredSpinner = () => ( @@ -12,6 +13,13 @@ const CenteredSpinner = () => ( ) +const mountExternalResources = (externalResourcesUrl: string) => { + console.log('Mount External resources') + const script = document.createElement('script') + script.src = `${externalResourcesUrl}/entry.js` + document.body.appendChild(script) +} + const mount = ({ mountPoint, initialPathname, @@ -26,6 +34,8 @@ const mount = ({ // unsubscribe to old SW unsubscribeOldSW() + if (EXTERNAL_RESOURCES_URL) mountExternalResources(EXTERNAL_RESOURCES_URL) + const router = createRouter({ strategy: routingStrategy, initialPathname }) const root = createRoot(mountPoint) root.render( @@ -37,11 +47,4 @@ const mount = ({ return () => queueMicrotask(() => root.unmount()) } -const mountExternalResources = (externalResourcesUrl: string) => { - console.log('Mount External resources') - const script = document.createElement('script') - script.src = `${externalResourcesUrl}/entry.js` - document.body.appendChild(script) -} - -export { mount, mountExternalResources } +export { mount } diff --git a/drama-queen/src/main.tsx b/drama-queen/src/main.tsx index 87475d8b..21e0dcc9 100644 --- a/drama-queen/src/main.tsx +++ b/drama-queen/src/main.tsx @@ -1,14 +1,10 @@ -import { EXTERNAL_RESOURCES_URL } from 'core/constants' - -import('./bootstrap').then(({ mount, mountExternalResources }) => { +import('./bootstrap').then(({ mount }) => { const localRoot = document.getElementById('drama-queen') mount({ mountPoint: localRoot!, routingStrategy: 'browser', }) - - if (EXTERNAL_RESOURCES_URL) mountExternalResources(EXTERNAL_RESOURCES_URL) }) export {}