Search code examples
node.jsreactjsserver-sideserver-side-rendering

Need advice converting React app to use server side rendering


I'm trying to convert an app to SSR for the first time. All the tutorials I've found only provide instructions for converting simple apps or building from scratch (and sharing the same package.json between client & server), but my app has dedicated package.json files & node_modules folders for the client & server.

  1. In order for the server to build the initial render of my root component, it needs access to all of the client dependencies, correct?
  2. If the answer to question #1 is true, does it make the most sense to refactor my code to share a single package.json in the root directory?

Solution

  • Some inputs:

    1) In order for the server to build the initial render of my root component, it does need access to all of the client dependencies and they should be SSR compatible(eg: Libraries like reflux doesn't work with SSR AFAIK).

    2) It does make the most sense to refactor your code to share a single package.json in the root directory, if you have minimal npm dependencies in both server and client. But, this can get un-manageable as you add more packagaes. You can still have multiple package.json in different folders and use workspace management tools like lerna (Note: I have not worked with lerna and SSR together, but theoretically it should work).