andreiduca / cra-ssr-code-splitting

Demo code for Server Side Rendering and Code Splitting in a create-react-app.
https://medium.com/bucharestjs/upgrading-a-create-react-app-project-to-a-ssr-code-splitting-setup-9da57df2040a
221 stars 70 forks source link

Undetected chunks #7

Open marcopeg opened 5 years ago

marcopeg commented 5 years ago

Hello, thank you for this example and for the article that you shared on Medium.

I am experiencing a weird behavior that is really driving me crazy crazy crazy. I wonder if you stumbled upon something similar yourself.

if you change the PageAnother.jsx to:

import React from 'react';
import moment from 'moment';

export default () => (
    <div>This is for another page. {JSON.stringify(moment())}</div>
);

(basically adding a dependency)

the SSR will break.

Actually, the SSR itself works just fine, but it fails to detect all the chunks that the app generates and uses. This end up in a re-rendering in the client.

If you look at the requested js files with the Chrome console, and compare it with the list of chuncks that are present in the html source, you'll notice that chunk 5.xxxxx.js is missing in the original HTML source.

This is what is causing the flickering.

Do you have any idea how to fix this?

marcopeg commented 5 years ago

Looks like you need to hook into webpack's configuration and fix the optimization configuration:

config.optimization = {
        ...config.optimization,
        splitChunks: { chunks: 'initial' },
}

I do this using react-scripts-rewired