Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
fix(dashboard): null-prototype lesson dictionary, scroll retry, always-reachable lesson toggle (#753)
06FallingLight900773ad023ca9
diff --git a/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsx b/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsxindex bbdc8e2a..f688006b 100644--- a/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsx+++ b/understand-anything-plugin/packages/dashboard/src/components/CodeViewer.tsx@@ -307,12 +307,16 @@ export default function CodeViewer({const showRendered = isMarkdown && mdView === "rendered";// Scroll to the selected lesson range after the source lines mount- // following a Rendered → Source switch (review #4). Only reacts to- // view-mode switches; direct selection scrolls synchronously in- // toggleSection, so the deps intentionally cover showRendered only.+ // following a Rendered → Source switch (review #4), and again once source+ // finishes loading: a section picked while loading scrolled before any+ // data-line element existed, and non-Markdown files never flip+ // showRendered, so without reacting to `source` the selected range could+ // stay offscreen. Direct selections still scroll synchronously in+ // toggleSection; the deps intentionally exclude lessonHighlight (cleared on+ // node switch anyway — the effect below only re-runs the CURRENT selection).useEffect(() => {- if (!showRendered && lessonHighlight) scrollToLine(lessonHighlight.start);- }, [showRendered]);+ if (!showRendered && lessonHighlight && source) scrollToLine(lessonHighlight.start);+ }, [showRendered, source]);if (!node) {return (@@ -372,6 +376,20 @@ export default function CodeViewer({)}</div><div className="flex items-center gap-2 shrink-0">+ {/* Lesson toggle lives in the shared header, not the source toolbar,+ so it stays reachable while source is loading or failed (e.g.+ files over the preview size limit) — the lesson panel itself does+ not depend on source loading. */}+ {lesson && (+ <button+ type="button"+ onClick={() => setLessonPanelOpen((open) => !open)}+ className="xl:hidden text-[10px] uppercase tracking-wider text-accent hover:text-accent/80 transition-colors"+ aria-expanded={lessonPanelOpen}+ >+ {lessonPanelOpen ? t.codeViewer.hideLesson : t.codeViewer.showLesson}+ </button>+ )}{onExpand && (<buttontype="button"@@ -419,16 +437,6 @@ export default function CodeViewer({<div className="px-4 py-2 border-b border-border-subtle bg-surface text-[11px] text-text-muted flex items-center justify-between"><span>{source.lineCount} {t.codeViewer.linesLabel}</span><div className="flex items-center gap-3">- {lesson && (- <button- type="button"- onClick={() => setLessonPanelOpen((open) => !open)}- className="xl:hidden text-[10px] uppercase tracking-wider text-accent hover:text-accent/80 transition-colors"- aria-expanded={lessonPanelOpen}- >- {lessonPanelOpen ? t.codeViewer.hideLesson : t.codeViewer.showLesson}- </button>- )}{isMarkdown && (<div className="flex items-center rounded border border-border-subtle overflow-hidden" role="group">{(["rendered", "source"] as const).map((view) => (diff --git a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/codeLessons.test.ts b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/codeLessons.test.tsindex 6d29fa30..5fde946a 100644--- a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/codeLessons.test.ts+++ b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/codeLessons.test.ts@@ -134,4 +134,49 @@ describe("normalizeCodeLessons", () => {expect(result?.version).toBe(1);expect(result?.generatedAt).toBe("");});++ it("uses a null-prototype dictionary so prototype-key filenames behave like normal keys", () => {+ // Real payloads come from JSON.parse, where "__proto__" is a plain own+ // key (an object literal would instead reassign the prototype).+ const entry = JSON.stringify(validFileEntry());+ const result = normalizeCodeLessons(+ JSON.parse(`{+ "files": {+ "__proto__": ${entry},+ "constructor": ${entry},+ "toString": ${entry},+ "src/a.ts": ${entry}+ }+ }`),+ );+ expect(result).not.toBeNull();+ // The dictionary's prototype chain must be empty.+ expect(Object.getPrototypeOf(result?.files ?? {})).toBeNull();+ // Missing prototype-named lessons resolve to undefined (→ null at the+ // call site), never an inherited function that crashes .sections.length.+ expect(result?.files["hasOwnProperty"]).toBeUndefined();+ // Present prototype-named lessons round-trip as own entries, and the+ // "__proto__" input key stays an own entry instead of mutating Object.prototype.+ expect(result?.files.constructor).toEqual(validFileEntry());+ expect(result?.files.toString).toEqual(validFileEntry());+ expect((result?.files as Record<string, unknown>)["__proto__"]).toEqual(validFileEntry());+ expect(Object.keys(result?.files ?? {})).toEqual([+ "__proto__",+ "constructor",+ "toString",+ "src/a.ts",+ ]);+ });++ it("survives a lessons document whose files object mixes inherited-looking keys", () => {+ const result = normalizeCodeLessons({+ files: Object.assign(Object.create({ valueOf: validFileEntry() }), {+ "src/a.ts": validFileEntry(),+ }),+ });+ // Object.entries only reads own keys, so the inherited "valueOf" entry is+ // invisible; the own entry survives.+ expect(result?.files["src/a.ts"]).toBeDefined();+ expect(result?.files.valueOf).toBeUndefined();+ });});diff --git a/understand-anything-plugin/packages/dashboard/src/utils/codeLessons.ts b/understand-anything-plugin/packages/dashboard/src/utils/codeLessons.tsindex 5cea1d5f..46f7a14f 100644--- a/understand-anything-plugin/packages/dashboard/src/utils/codeLessons.ts+++ b/understand-anything-plugin/packages/dashboard/src/utils/codeLessons.ts@@ -50,7 +50,10 @@ export function normalizeCodeLessons(data: unknown): CodeLessons | null {const files = candidate.files;if (!files || typeof files !== "object" || Array.isArray(files)) return null;- const normalizedFiles: CodeLessons["files"] = {};+ // Null-prototype dictionary: a lesson keyed "constructor"/"toString" must not+ // resolve to an inherited function (crashes at lesson.sections.length), and+ // a "__proto__" key must become an own entry instead of mutating Object.prototype.+ const normalizedFiles = Object.create(null) as CodeLessons["files"];for (const [filePath, entry] of Object.entries(files as Record<string, unknown>)) {if (!entry || typeof entry !== "object" || Array.isArray(entry)) {console.warn(`[code-lessons] dropped malformed entry for "${filePath}"`);