Skip to content

Commit

Permalink
feat: bootstrap.util.ts
Browse files Browse the repository at this point in the history
- mv bootstrap logic to util
  • Loading branch information
denchiklut committed Dec 29, 2022
1 parent a908401 commit 1b4ae2a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/client/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { BrowserRouter } from 'react-router-dom'
import { createRoot, hydrateRoot } from 'react-dom/client'
import { loadableReady } from '@loadable/component'
import { bootstrap } from 'client/utils'
import { App } from '@shared/app'

loadableReady(() => {
const container = document.getElementById('root') as HTMLElement
const AppContainer = (
<BrowserRouter>
<App />
</BrowserRouter>
)
const AppContainer = () => (
<BrowserRouter>
<App />
</BrowserRouter>
)

if (IS_SPA) createRoot(container).render(AppContainer)
else hydrateRoot(container, AppContainer)
})
bootstrap(<AppContainer />)
10 changes: 10 additions & 0 deletions src/client/utils/bootstrap.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ReactNode } from 'react'
import { loadableReady } from '@loadable/component'
import { createRoot, hydrateRoot } from 'react-dom/client'

export const bootstrap = (app: ReactNode) => {
const container = document.getElementById('root') as HTMLElement

if (IS_SPA) createRoot(container).render(app)
else loadableReady(() => hydrateRoot(container, app))
}
1 change: 1 addition & 0 deletions src/client/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lazy.util'
export * from './bootstrap.util'
2 changes: 1 addition & 1 deletion src/server/middleware/render/render.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getHtml = (reactHtml: string, chunkExtractor: ChunkExtractor) => {
<head>
<meta charset='UTF-8'>
<title>SSR app</title>
<link rel='icon' href='favicon.ico' />
<link rel='icon' href='/favicon.ico' />
<meta content='width=device-width, initial-scale=1' name='viewport' />
${linkTags}
${styleTags}
Expand Down

0 comments on commit 1b4ae2a

Please sign in to comment.