Skip to content

Commit

Permalink
fix: mount external resources
Browse files Browse the repository at this point in the history
Entry point for Pearl-Jam is only the `mount` function exported by boostrap.tsx
  • Loading branch information
laurentC35 committed Nov 8, 2024
1 parent 282d916 commit 44eed51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 11 additions & 8 deletions drama-queen/src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ 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 = () => (
<Stack alignItems="center" justifyContent="center" height="100vh">
<CircularProgress size={'5em'} />
</Stack>
)

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,
Expand All @@ -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(
Expand All @@ -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 }
6 changes: 1 addition & 5 deletions drama-queen/src/main.tsx
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 44eed51

Please sign in to comment.