fix(play): fix CLAUDE.md typo and dialogue history memo anti-pattern
- Fix @AGETNTS.md → @AGENTS.md typo in CLAUDE.md - Remove ref read inside useMemo (React anti-pattern causing one-frame stale data) - Simplify buildDialogueHistory to read visitedBeatIds directly from session.history, which also fixes incorrect scene-ID matching when the same ID appears multiple times Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+3
-13
@@ -268,17 +268,12 @@ type ScenePathStep = {
|
|||||||
|
|
||||||
function buildDialogueHistory(
|
function buildDialogueHistory(
|
||||||
session: Session | null,
|
session: Session | null,
|
||||||
currentSceneId: string | undefined,
|
|
||||||
currentVisitedBeatIds: string[],
|
|
||||||
): DialogueHistoryItem[] {
|
): DialogueHistoryItem[] {
|
||||||
if (!session) return [];
|
if (!session) return [];
|
||||||
|
|
||||||
return session.history.flatMap((entry, sceneIndex) => {
|
return session.history.flatMap((entry, sceneIndex) => {
|
||||||
const beatsById = new Map(entry.scene.beats.map((b) => [b.id, b]));
|
const beatsById = new Map(entry.scene.beats.map((b) => [b.id, b]));
|
||||||
const visitedBeatIds =
|
const visitedBeatIds = entry.visitedBeatIds;
|
||||||
entry.scene.id === currentSceneId
|
|
||||||
? currentVisitedBeatIds
|
|
||||||
: entry.visitedBeatIds;
|
|
||||||
|
|
||||||
return visitedBeatIds.flatMap((beatId, beatIndex) => {
|
return visitedBeatIds.flatMap((beatId, beatIndex) => {
|
||||||
const beat = beatsById.get(beatId);
|
const beat = beatsById.get(beatId);
|
||||||
@@ -611,13 +606,8 @@ function PlayInner() {
|
|||||||
}, [currentScene, currentBeatId]);
|
}, [currentScene, currentBeatId]);
|
||||||
|
|
||||||
const dialogueHistory = useMemo<DialogueHistoryItem[]>(
|
const dialogueHistory = useMemo<DialogueHistoryItem[]>(
|
||||||
() =>
|
() => buildDialogueHistory(session),
|
||||||
buildDialogueHistory(
|
[session],
|
||||||
session,
|
|
||||||
currentScene?.id,
|
|
||||||
visitedBeatsRef.current,
|
|
||||||
),
|
|
||||||
[session, currentScene?.id, currentBeatId],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const audioSrc = (currentBeat ? beatAudioMap[currentBeat.id] : undefined) ?? null;
|
const audioSrc = (currentBeat ? beatAudioMap[currentBeat.id] : undefined) ?? null;
|
||||||
|
|||||||
Reference in New Issue
Block a user