1

I have been trying for a while now, to no avail, to get my configuration working for an app that has the following characterstics:

  1. Typescript
  2. React
  3. Server side rendering using loadable-components
  4. Webpack

For some reason, this snippet, which is supposed to find all the chunks that were used during the server side rendering, is not working:

server.get("*", (req, res, next) => {
    const extractor = new ChunkExtractor({ statsFile });
    ...
    const tsx = extractor.collectChunks(
        <ChunkExtractorManager extractor={extractor}>
            <StaticRouter location={req.url}>
                <App data={data}/>
            </StaticRouter>
        </ChunkExtractorManager>
    );
    console.log(extractor.getScriptTags()); // prints server.js bundle but this isn't correct
});

It's returning the server.js bundle instead of the needed client/vendor bundles. Rather than post all the code here, I've pushed all the code to my branch on github: https://github.com/markdstevens/ssr-ts-react-webpack-boilerplate/tree/ssr-with-code-splitting

I must be missing some configuration in webpack or in loadable-components, but I've looked everywhere and can't seem to find the issue. Any tips would be most welcome. Thanks!

Mark
  • 9,718
  • 6
  • 29
  • 47

1 Answers1

1

Found the issue. In my webpack configuration, I had this in my server config:

import * as LoadablePlugin from '@loadable/webpack-plugin';
...
{
  entry: './src/server/app.tsx',
  target: 'node',
  externals: [nodeExternals()],
  output: {
    filename: 'server.js',
  },
  plugins: [
    new LoadablePlugin()
  ]
}

I had to add the LoadablePlugin to my client configuration as well in order for everything to work.

Mark
  • 9,718
  • 6
  • 29
  • 47
  • 6
    Iv'e done over 800+ hrs of configuring SSR for our team, code splitting, routing, rendering react-dom portals in the header of the page on the server, client- side only components, redux hydration on server etc etc etc etc, My advice to people now on SSR with react is to use NextJS and avoid countless hours of headaches. – Shanon Jackson Dec 22 '19 at 23:17
  • i get performance score around 70-80 with react and ssr in desktop. my problem is that i can't use renderToNodeStream and when i use loadable components i get a blink . here is [my post](https://stackoverflow.com/questions/66050007/react-ssr-blinks-when-starting-client) .please let me know if i can help or if you've got a clue about the problems. i really need some clues. – zahra shahrouzi Feb 05 '21 at 12:20