import React, { type JSX } from 'react' import { isHTTPAccessFallbackError } from '../../client/components/http-access-fallback/http-access-fallback' import { getURLFromRedirectError, getRedirectStatusCodeFromError, } from '../../client/components/redirect' import { isRedirectError } from '../../client/components/redirect-error' import { renderToReadableStream } from 'react-dom/server' import { streamToString } from '../stream-utils/node-web-streams-helper' import { RedirectStatusCode } from '../../client/components/redirect-status-code' import { addPathPrefix } from '../../shared/lib/router/utils/add-path-prefix' import type { ClientTraceDataEntry } from '../lib/trace/tracer' export function makeGetServerInsertedHTML({ polyfills, renderServerInsertedHTML, serverCapturedErrors, tracingMetadata, basePath, }: { polyfills: JSX.IntrinsicElements['script'][] renderServerInsertedHTML: () => React.ReactNode tracingMetadata: ClientTraceDataEntry[] | undefined serverCapturedErrors: Array basePath: string }) { let flushedErrorMetaTagsUntilIndex = 0 // flag for static content that only needs to be flushed once let hasFlushedInitially = false const polyfillTags = polyfills.map((polyfill) => { return