Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
feat(client): add async-component and async-bootstrapper
Browse files Browse the repository at this point in the history
feat(client): add async-component and async-bootstrapper
  • Loading branch information
Metnew committed Nov 3, 2017
1 parent ab7da79 commit db5ef11
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import 'semantic-ui-css/components/statistic.css'
import 'promise-polyfill'
import 'isomorphic-fetch'
// Application
import React from 'react'
import {hydrate} from 'react-dom'
import {AsyncComponentProvider} from 'react-async-component'
import asyncBootstrapper from 'react-async-bootstrapper'
import {configureApp, configureRootComponent} from 'common/app'
import type {GlobalState} from 'reducers'
import type {i18nConfigObject} from 'types'
Expand All @@ -39,7 +42,8 @@ if (process.env.NODE_ENV === 'production') {

const initialState: GlobalState = window.__INITIAL_STATE__ || {}
const i18n: i18nConfigObject = window.__I18N__ || {}
// NOTE: V8 doesn't optimize code with `delete`
const asyncState: Object = window.__ASYNC_STATE__ || {}
// NOTE: V8 doesn't optimize `delete`
// delete window.__INITIAL_STATE__
const {store, routes, history} = configureApp(initialState)
const RootComponent = configureRootComponent({
Expand All @@ -49,7 +53,16 @@ const RootComponent = configureRootComponent({
i18n
})

hydrate(RootComponent, document.getElementById('app'))
const app = (
<AsyncComponentProvider rehydrateState={asyncState}>
{RootComponent}
</AsyncComponentProvider>
)

asyncBootstrapper(app).then(() => {
console.log('FROM SERVER:', document.getElementById('app').innerHTML)
hydrate(app, document.getElementById('app'))
})

if (module.hot) {
module.hot.accept()
Expand Down

0 comments on commit db5ef11

Please sign in to comment.