Skip to content

Debugging Server Rendering

Justin Gordon edited this page Feb 20, 2019 · 2 revisions

Motivation

Because server rendering often uses react_component_hash to get the meta tags for SEO, we can't just flip a switch and turn off server rendering to debug the code in the browser. Here are the steps to debug the rendering code if using the React on Rails Pro Node VM Renderer.

  1. Start the compilation of the webpack files and in a separate process.
  2. Start Node process in its own shell with this command, like this:
node --inspect vm-renderer.js -p 3800
  1. Open up the Chrome dev tools devices: chrome://inspect/#devices
  2. Click the "Configure..." button next to Discover network targets.
  3. Look at your terminal for for the vm-renderer and add the port corresponding to a line looking like Debugger listening on ws://127.0.0.1:9229/84cd33a7-8965-48f6-ad6b-31d9e368b667.
  4. Open up the debugger window by clicking inspect under the Target that does not have the version of Node listed.
  5. When you click inspect, you'll see the message Debugger attached. in the your terminal window for the vm-renderer.
  6. Add a debugger line to the place in the rendering JavaScript code where you'd like the debugger to stop.
  7. Hit the affected URL in the browser and the debugger window should open to the line where you put the debugger breakpoint.
  8. You can navigate in the stack up to App and see what props are coming from Rails.

Troubleshooting

On the chrome://inspect/#devices

  1. Double check that you configured the right network target. Check your console log from the vm-renderer
  2. Try clicking the other "Target" under "Remote Target.
  3. Since the workers restart per the console message: [ROR-VM] info: Scheduled workers restarts every 15 minutes (2 minutes btw each) you will need to reattach the debugger.

Setup

2019-02-17_19-01-52

2019-02-17_19-02-11

2019-02-17_19-17-21

2019-02-17_21-52-29

2019-02-17_19-10-43

Debugger line

2019-02-17_21-37-19

Seeing props sent to the app

2019-02-17_22-09-12