Error Tracking

We can track errors by using pageContext.errorWhileRendering:

// server.js

const { createPageRenderer } = require('vite-plugin-ssr')

const renderPage = createPageRenderer(/* ... */)
app.get('*', async (req, res, next) => {
  const pageContext = await renderPage({ url: req.url })

  // An error occured during server-side rendering
  if (pageContext.errorWhileRendering) {
    myErrorTracker(pageContext.errorWhileRendering)
  }

  // ...
})

So that we can, for example, install the tracker code of a tracking service such as Sentry, Bugsnag, or Rollbar.