Files
kolaytercih/src/components/ui/markdown-lazy.tsx
bilalgursen 90ac590737 perf: sohbet markdown lazy + marked client'tan çıktı, mermaid görünürlükte (Faz 4)
- markdown.tsx: blok bölme marked.lexer yerine çit-farkındalıklı boş satır
  bölücüsü — react-markdown'ın yanında ikinci tam parser (~460 KB paket)
  client'a inmiyordu artık gerekmiyor; memoized blok yapısı aynen korunur
- markdown-lazy: react-markdown+remark zinciri (~215 KB) lazy; fallback
  aynı class'lı düz metin (stream'de flash/CLS yok), sohbet mount'unda
  preloadMarkdown ile chunk önden ısınır — /listem 1315->1133 KB eager JS
- el-cizimi-sema: mermaid importu IntersectionObserver'a bağlandı
  (rootMargin 200px); şemalar hep fold altında, ~1 MB mount'ta inmiyor

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 14:01:48 +03:00

33 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
// react-markdown + remark zinciri (~215 KB) yalnızca markdown gerçekten
// çizileceği zaman insin. next/dynamic yerine elle sarmalayıcı: `loading`
// children alamıyor, fallback'in AYNI class'lı düz metin olması gerekiyor ki
// stream sırasında iskelet/boşluk flash'ı olmasın (chunk gelince yerinde
// zenginleşir).
import { useEffect, useReducer } from "react";
import type { MarkdownProps } from "./markdown";
let mod: typeof import("./markdown") | null = null;
let soz: Promise<void> | null = null;
/** Chunk'ı önden ısıt (ör. sohbet mount olduğunda). */
export function preloadMarkdown(): Promise<void> {
return (soz ??= import("./markdown").then((m) => {
mod = m;
}));
}
export function MarkdownLazy({
fallback,
...props
}: MarkdownProps & { fallback: React.ReactNode }) {
const [, tazele] = useReducer((c: number) => c + 1, 0);
useEffect(() => {
if (!mod) void preloadMarkdown().then(() => tazele());
}, []);
const Markdown = mod?.Markdown;
return Markdown ? <Markdown {...props} /> : <>{fallback}</>;
}