import ReactDOMServer from "react-dom/server";
const renderRouterToString = async ({
  router,
  responseHeaders,
  children
}) => {
  try {
    let html = ReactDOMServer.renderToString(children);
    router.serverSsr.setRenderFinished();
    const injectedHtml = router.serverSsr.takeBufferedHtml();
    if (injectedHtml) {
      html = html.replace(`</body>`, () => `${injectedHtml}</body>`);
    }
    return new Response(`<!DOCTYPE html>${html}`, {
      status: router.state.statusCode,
      headers: responseHeaders
    });
  } catch (error) {
    console.error("Render to string error:", error);
    return new Response("Internal Server Error", {
      status: 500,
      headers: responseHeaders
    });
  } finally {
    router.serverSsr?.cleanup();
  }
};
export {
  renderRouterToString
};//# sourceMappingURL=https://main.vscode-cdn.net/sourcemaps/e0b7a2bcf575cfba10528c4e7c10bd3ce2d7769a/node_modules/@tanstack/react-router/dist/esm/ssr/renderRouterToString.js.map
