Repository: remix-run/react-router
File: packages/react-router/lib/rsc/server.ssr.tsx (TypeScript)

Code before:
 *   fetchServer,
 *   createFromReadableStream,
 *   async renderHTML(getPayload) {
 *     const payload = await getPayload();
 *
 *     return await renderHTMLToReadableStream(
 *       <RSCStaticRouter getPayload={getPayload} />,
 *       {
 *         bootstrapScriptContent,
 *         formState: await getFormState(payload),
 *       }
 *     );
 *   },
 * });
 *
 * @name unstable_RSCStaticRouter
 * @public
 * @category RSC
 * @mode data
 * @param props Props
 * @param {unstable_RSCStaticRouterProps.getPayload} props.getPayload n/a
 * @returns A React component that renders the {@link unstable_RSCPayload} as HTML.
 */
export function RSCStaticRouter({ getPayload }: RSCStaticRouterProps) {
  // Can be replaced with React.use when v18 compatibility is no longer required.
  const payload = react18compatibleUse(getPayload()) as RSCPayload;

  if (payload.type === "redirect") {
    throw new Response(null, {
      status: payload.status,
      headers: {
        Location: payload.location,
      },
    });
  }

  if (payload.type !== "render") return null;

  let patchedLoaderData = { ...payload.loaderData };
  for (const match of payload.matches) {
    // Clear out the loaderData to avoid rendering the route component when the
    // route opted into clientLoader hydration and either:
    // * gave us a HydrateFallback
    // * or doesn't have a server loader and we have no data to render
    if (
      shouldHydrateRouteLoader(
        match.id,
        match.clientLoader,
        match.hasLoader,
        false,
      ) &&

Review comment (suggestion):
```suggestion
  const payload = useSafe(getPayload());
```

Code after:
 *   async renderHTML(getPayload) {
 *     const payload = await getPayload();
 *
 *     return await renderHTMLToReadableStream(
 *       <RSCStaticRouter getPayload={getPayload} />,
 *       {
 *         bootstrapScriptContent,
 *         formState: await getFormState(payload),
 *       }
 *     );
 *   },
 * });
 *
 * @name unstable_RSCStaticRouter
 * @public
 * @category RSC
 * @mode data
 * @param props Props
 * @param {unstable_RSCStaticRouterProps.getPayload} props.getPayload n/a
 * @returns A React component that renders the {@link unstable_RSCPayload} as HTML.
 */
export function RSCStaticRouter({ getPayload }: RSCStaticRouterProps) {
  // Can be replaced with React.use when v18 compatibility is no longer required.
  const payload = useSafe(getPayload());

  if (payload.type === "redirect") {
    throw new Response(null, {
      status: payload.status,
      headers: {
        Location: payload.location,
      },
    });
  }

  if (payload.type !== "render") return null;

  let patchedLoaderData = { ...payload.loaderData };
  for (const match of payload.matches) {
    // Clear out the loaderData to avoid rendering the route component when the
    // route opted into clientLoader hydration and either:
    // * gave us a HydrateFallback
    // * or doesn't have a server loader and we have no data to render
    if (
      shouldHydrateRouteLoader(
        match.id,
        match.clientLoader,
        match.hasLoader,
        false,
      ) &&
      (match.hydrateFallbackElement || !match.hasLoader)
    ) {