Skip to content

Commit

Permalink
React.lazy loads HyloEditorMobile and moves it above our routing setu…
Browse files Browse the repository at this point in the history
…p allowing it to code-split with minimum dependencies
  • Loading branch information
lorenjohnson committed Oct 21, 2022
1 parent 62205c8 commit beafd50
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
19 changes: 16 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import React from 'react'
import React, { Suspense } from 'react'
import ReactDOM from 'react-dom'
import { rootDomId } from 'client/util'
import App from './router'
import Loading from 'components/Loading'

import './client/websockets'
import './css/global/index.scss'

const App = React.lazy(() => import('./router'))
const HyloEditorMobile = React.lazy(() => import('components/HyloEditor/HyloEditorMobile'))

ReactDOM.render(
<App />,
window.location.pathname === '/hyloApp/editor'
? (
<Suspense fallback={() => null}>
<HyloEditorMobile />
</Suspense>
) : (
<Suspense fallback={() => <Loading type='fullscreen' />}>
<App />
</Suspense>
),
document.getElementById(rootDomId)
)
7 changes: 1 addition & 6 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react'
import { ConnectedRouter } from 'connected-react-router'
import { Switch, Route } from 'react-router'
import { DndProvider } from 'react-dnd'
import { HTML5Backend } from 'react-dnd-html5-backend'
import { Provider } from 'react-redux'
import { LayoutFlagsProvider } from 'contexts/LayoutFlagsContext'
import createStore, { history } from '../store'
import RootRouter from 'routes/RootRouter'
import HyloAppRouter from 'routes/HyloAppRouter'

const store = createStore()

Expand All @@ -19,10 +17,7 @@ export default function App () {
<DndProvider backend={HTML5Backend}>
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch>
<Route path='/hyloApp' component={HyloAppRouter} />
<RootRouter />
</Switch>
<RootRouter />
</ConnectedRouter>
</Provider>
</DndProvider>
Expand Down
16 changes: 0 additions & 16 deletions src/routes/HyloAppRouter/HyloAppRouter.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/routes/HyloAppRouter/index.js

This file was deleted.

0 comments on commit beafd50

Please sign in to comment.