async function renderToString(serverRenderer, element) {
  let didError = false;
  const stream = await serverRenderer.renderToReadableStream(element, {
    onError(error) {
      didError = true;
      console.error(error);
    },
  });
  await stream.allReady;

  if (didError) {
    throw new Error('The above error occurred while rendering to string.');
  }

  const response = new Response(stream);
  return response.text();
}
@param {import('react-dom/server')} serverRenderer