Subscribe on changes!

Add support for AbortController to renderToString and Streaming APIs

avatar
May 21st 2022

What problem does this feature solve?

Right now if you abort a request while a server is still rendering your app it won't stop until the whole app is rendered. This leads to unnecessary workload for aborted requests (for example multiple page refreshes).

What does the proposed API look like?

renderToString and Streaming APIs should be able to receive a signal from AbortController and stop execution if controller was aborted.

const controller = new AbortController()

const resultPromise = renderToString(App, ssrContext, controller.signal)

request.on('close', () => { controller.abort() })

resultPromise
  .then((result) => {
    request.send(result)
  })
  .catch((error) => {
    if (error instanceof AbortError) { ... } // type of error is to be discussed
    else { ... }
  })