Skip to content
Myr

client-code.tsx

This file

Path

apps/web/src/features/code/client-code.tsx

52 lines · 1.6 KiB · TypeScript

Last changed by

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

History of this file

Take it

Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229

lines 1–3why, one step back
1/**
2 * A file and a commit's diff, drawn in the browser only. `@pierre/diffs`3 * and Shiki's grammars are megabytes, and the drawing needs the DOM, so the

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

line 4why, one step back
4 * server renders `fallback` (numbered lines, or the plain-text diff)

Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229

lines 5–52why, one step back
5 * and the browser loads the drawing after hydration. `import.meta.env.SSR`
6 * is `true` in the Worker's build, so the dynamic imports below are dead7 * code there and the Worker bundles none of it (`bytes:check`), as8 * `features/finish/client-diff.tsx` does.9 */10import { ClientOnly } from "@tanstack/react-router";11import { lazy, Suspense } from "react";12import type { ReactNode } from "react";1314// Type-only imports are erased, so the server bundles nothing of these.15import type { FileCodeProps } from "./code-view.tsx";16import type { DiffCodeProps } from "./diff-view.tsx";1718const FileLater = import.meta.env.SSR19 ? undefined20 : lazy(() => import("./code-view.tsx"));2122const DiffLater = import.meta.env.SSR23 ? undefined24 : lazy(() => import("./diff-view.tsx"));2526export const ClientFile = ({27 fallback,28 ...props29}: FileCodeProps & { readonly fallback: ReactNode }) =>30 FileLater === undefined ? (31 fallback32 ) : (33 <ClientOnly fallback={fallback}>34 <Suspense fallback={fallback}>35 <FileLater {...props} />36 </Suspense>37 </ClientOnly>38 );3940export const ClientDiffs = ({41 fallback,42 ...props43}: DiffCodeProps & { readonly fallback: ReactNode }) =>44 DiffLater === undefined ? (45 fallback46 ) : (47 <ClientOnly fallback={fallback}>48 <Suspense fallback={fallback}>49 <DiffLater {...props} />50 </Suspense>51 </ClientOnly>52 );