0

The loadable component on SSR not rendering on the server but works fine on the client-side. In my main container header and footer is rendering on server only component with loadable is not loading on server

react version

"react": "^16.12.0" 
"react-router-config": "^1.0.0-beta.4", 
"react-router-dom": "^4.3.0", 
"react-router-redux": "^5.0.0-alpha.9"

server.js

<ChunkExtractorManager extractor={extractor}> 
    <Provider store={store}> 
      <StaticRouter location={location} context={context}> 
        <ReduxAsyncConnect routes={routes} /> 
      </StaticRouter> 
    </Provider> 
</ChunkExtractorManager>

Client.js

loadableReady(() => { 
         hydrate( 
            <Provider store={store}> 
              <ConnectedRouter history={history}> 
                <ReduxAsyncConnect routes={routes} /> 
              </ConnectedRouter> 
            </Provider>, document.getElementById('app') ); 
})

Webpack plugin also added. stats.json file is created with chunk hash values. What am I doing wrong here?

4

1 回答 1

0

对于可加载的组件,在您的 App 组件中,您可以使用您自己选择的 Provider 包装您需要的组件:

import { loadableReady } from '@loadable/component'
loadableReady(() => {
  const root = document.getElementById('main')
  hydrate(<App />, root)
})

对于块:

import { renderToString } from 'react-dom/server'
import { ChunkExtractor, ChunkExtractorManager } from '@loadable/server'
const statsFile = path.resolve('../dist/loadable-stats.json')
const extractor = new ChunkExtractor({ statsFile })
const html = renderToString(
  <ChunkExtractorManager extractor={extractor}>
    <YourApp />
  </ChunkExtractorManager>,
)
const scriptTags = extractor.getScriptTags() 
于 2020-02-25T08:07:57.800 回答