commit 2e9ec140e43d01902a6b095fbcade959a28f31a7
parent a627767792aea8f47a0e7432e8d8712f3daabd13
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 14 Oct 2026 08:51:00 -0400
umtool: the reader's note and citation buttons wait for hydration
A "+ note" on a section, a citation, or "+ whole article" clicked before
React hydrated fired nothing (article-slides' dev-mode red): disabled until
hydrated (components/ui/use-hydrated.ts), the house rule.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/umtool/components/articles/ArticleBody.tsx b/umtool/components/articles/ArticleBody.tsx
@@ -2,6 +2,7 @@
import { createContext, memo, useContext, type AnchorHTMLAttributes, type ReactNode } from "react";
import { Markdown } from "yt-dlp-transcript-common/components/Markdown";
+import { useHydrated } from "@/components/ui/use-hydrated";
import type { CitationView, ReportPageView } from "yt-dlp-transcript-common/lib/report/views";
// The article's text, as blocks the notes anchor to (`data-block`: title,
@@ -15,6 +16,12 @@ import type { CitationView, ReportPageView } from "yt-dlp-transcript-common/lib/
// A citation is a button (its label, which is part of the text) and its
// number (which is not: `data-anchor-skip`). Clicking it opens the evidence
// panel; nothing here links out of umtool.
+//
+// Both buttons here (a citation, a section's "+ note") are disabled until
+// hydrated (the house rule, components/ui/use-hydrated.ts): a click that
+// landed before React hydrated fired nothing -- the section note's composer
+// never opened -- and looked like a click never made. Only the button
+// re-renders when it turns on; the memoised text around it does not.
export type ArticleActions = {
openCite: (id: string) => void;
@@ -28,8 +35,6 @@ const CitationsContext = createContext<Readonly<Record<string, CitationView>>>({
const CITE_SCHEME = "cite:";
function CiteLink({ href, children }: AnchorHTMLAttributes<HTMLAnchorElement>) {
- const actions = useContext(ArticleActionsContext);
- const citations = useContext(CitationsContext);
const id = href?.startsWith(CITE_SCHEME) ? href.slice(CITE_SCHEME.length).trim() : null;
if (id === null) {
return (
@@ -38,15 +43,23 @@ function CiteLink({ href, children }: AnchorHTMLAttributes<HTMLAnchorElement>) {
</a>
);
}
+ return <CiteButton id={id}>{children}</CiteButton>;
+}
+
+function CiteButton({ id, children }: { id: string; children: ReactNode }) {
+ const actions = useContext(ArticleActionsContext);
+ const citations = useContext(CitationsContext);
+ const hydrated = useHydrated();
const c = citations[id];
return (
<>
<button
type="button"
+ disabled={!hydrated}
data-cite={id}
onClick={() => actions?.openCite(id)}
title={c ? `${c.quote}${c.speaker ? ` — ${c.speaker}` : ""}` : `citation ${id}`}
- className="cursor-pointer rounded-sm text-left text-[var(--color-text)] underline decoration-[var(--color-sel)] decoration-dotted underline-offset-2 hover:bg-[var(--color-panel-2)] data-[has-note=true]:bg-[color-mix(in_srgb,var(--color-dirty)_22%,transparent)]"
+ className="cursor-pointer rounded-sm text-left text-[var(--color-text)] disabled:cursor-default underline decoration-[var(--color-sel)] decoration-dotted underline-offset-2 hover:bg-[var(--color-panel-2)] data-[has-note=true]:bg-[color-mix(in_srgb,var(--color-dirty)_22%,transparent)]"
>
{children}
</button>
@@ -78,9 +91,11 @@ export function Md({ text }: { text: string }) {
function NoteButton({ section, title }: { section: string; title: string }) {
const actions = useContext(ArticleActionsContext);
+ const hydrated = useHydrated();
return (
<button
type="button"
+ disabled={!hydrated}
data-anchor-skip
aria-label={`note on ${title}`}
onClick={() => actions?.noteSection(section, title)}
diff --git a/umtool/components/articles/ArticleReader.tsx b/umtool/components/articles/ArticleReader.tsx
@@ -6,6 +6,7 @@ import { buildReportSlides, hasSlides, reportPageAnchorIds, slideIndexForPlace,
import { useReaderPlace } from "yt-dlp-transcript-common/components/report/slides/useReaderPlace";
import { ViewSwitch } from "yt-dlp-transcript-common/components/report/slides/ViewSwitch";
import CopyButton from "@/components/CopyButton";
+import { useHydrated } from "@/components/ui/use-hydrated";
import { locateQuote, quoteAnchor } from "@/lib/annotations/anchor.mjs";
import type { Anchor, Note, NotesRead } from "@/lib/annotations/types";
import { useNotes } from "@/lib/annotations/useNotes";
@@ -108,6 +109,8 @@ export default function ArticleReader({
const [orphans, setOrphans] = useState<Set<string>>(new Set());
const [hover, setHover] = useState<string | null>(null);
const [drawer, setDrawer] = useState(false);
+ // The rail's "+ whole article" waits for hydration, as the body's buttons do (ArticleBody).
+ const hydrated = useHydrated();
const bodyRef = useRef<HTMLDivElement>(null);
const evidence = useEvidence(site, report, cite);
const shapes = hasSlides(view);
@@ -437,6 +440,7 @@ export default function ArticleReader({
))}
<button
type="button"
+ disabled={!hydrated}
onClick={() => openComposer({ kind: "whole" })}
className="ml-auto text-[11px] text-[var(--color-dim)] hover:text-[var(--color-sel)]"
>