I am building a react app and I did code splitting on the client for the bundle
. My app properly render on the server as I am using SSR
, I have no code Splitting on the server but on the client I do. I am getting the following warning on client with hydrate
.
Warning: Did not expect server HTML to contain a <div> in <div>.
I am using @loadable/component
for code splitting on the client
I have my App.js file on the client side as:-
import React from "react"
import loadable from '@loadable/component'
import { Route, Switch } from 'react-router-dom'
const AsyncHome = loadable(() =>
import('./components/Home/Home')
)
const AsyncPost = loadable(() =>
import('./components/Post/Post')
)
function App(){
return(
<div>
<Switch>
<Route path="/" component={AsyncHome}/>
<Route path="post" component={AsyncPost}/>
</Switch>
</div>
)
}
I have my index.js
file on the client as:
import React from 'react'
import { hydrate } from 'react-dom'
import { BrowserRouter} from 'react-router-dom'
import App from './App'
hydrate(
<BrowserRouter><App/></BrowserRouter>,
document.getElementById('app')
)
How to get fix that warning with using code-splitting
only on the client. I have also tried React.lazy
and React.Suspense
but i am getting the same error.