Skip to content

Instantly share code, notes, and snippets.

@kziemski
Forked from marcosmapf/app-umd-bootstrap.tsx
Created October 24, 2025 21:12
Show Gist options
  • Save kziemski/4e60d64937df2f8db7968439e60f499d to your computer and use it in GitHub Desktop.
Save kziemski/4e60d64937df2f8db7968439e60f499d to your computer and use it in GitHub Desktop.

Revisions

  1. @marcosmapf marcosmapf renamed this gist Aug 10, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @marcosmapf marcosmapf created this gist Aug 10, 2022.
    52 changes: 52 additions & 0 deletions bootstrap.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    import React, { lazy, Suspense } from 'react'
    import { render } from 'react-dom'

    import { initRequestConfiguration } from 'utils/request'
    import {
    createShadowDom,
    initializeTagManager,
    setLocales,
    setToken
    } from 'startup/utils'
    import handleFederatedApp from 'utils/federatedApp'

    import 'config/requestRegister'

    const App = lazy(() => import('startup/umd/app'))
    const Root = () => {
    return (
    <div id={process.env.PROJECT_NAME}>
    <Suspense fallback={null}>
    <App />
    </Suspense>
    </div>
    )
    }

    const renderApp = async (rootElement: any, {
    baseUrl = '/',
    lang,
    token
    }) => {
    // eslint-disable-next-line camelcase
    __webpack_public_path__ = baseUrl
    const { setAppRoot } = handleFederatedApp()

    const shadowRoot = createShadowDom(rootElement)

    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    setAppRoot(process.env.PROJECT_NAME!, shadowRoot)

    if (!token) {
    throw new Error('Missing valid token param')
    }

    await setLocales(lang)
    setToken(token)
    initRequestConfiguration(token)
    initializeTagManager()

    render(<Root />, shadowRoot)
    }

    export default renderApp