Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: StrictMode-safe mounted guard, no auto-start after close, keep dotted acronyms whole (#1304)

[._.]/ Adam Eivyd741895c163d
diff --git a/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx b/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx
index 7182df9232..314c5c6f11 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptReadAloud.jsx
@@ -43,14 +43,25 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {
const [elapsedMs, setElapsedMs] = useState(0);
const audioRef = useRef(null);
+ // Set true on (re)mount, false on unmount. The body-set is required because
+ // the app runs under React.StrictMode, which does mount→cleanup→mount on the
+ // initial mount; a cleanup-only guard would be left false and freeze every
+ // later narration at the mounted check.
const mountedRef = useRef(true);
- useEffect(() => () => { mountedRef.current = false; }, []);
+ useEffect(() => {
+ mountedRef.current = true;
+ return () => { mountedRef.current = false; };
+ }, []);
// Live mirror of the prose the modal is showing, so an in-flight narration
// response can detect that the section's text changed (edit, reformat, accepted
// fix, or a section swap) while it was synthesizing and discard itself rather
// than apply stale audio/offsets to different prose.
const contentRef = useRef(content);
contentRef.current = content;
+ // Live mirror of `open` so a narration that resolves after the modal was
+ // closed doesn't auto-start playback into an unmounted <audio> element.
+ const openRef = useRef(open);
+ openRef.current = open;
// Reset narration when the prose being read changes — a different issue/stage,
// or the SAME section edited under it. The cached segments + their char offsets
@@ -109,7 +120,10 @@ export default function ManuscriptReadAloud({ open, onClose, section }) {
const segs = Array.isArray(result.segments) ? result.segments : [];
setSegments(segs);
setElapsedMs(0);
- if (segs.length) { setCurrentIndex(0); setIsPlaying(true); }
+ // Only auto-start when the modal is still open — otherwise the <audio> is
+ // unmounted and the play effect would set "Pause" with nothing playing. The
+ // segments still load, so reopening shows the prose ready to Play.
+ if (segs.length && openRef.current) { setCurrentIndex(0); setIsPlaying(true); }
};
const togglePlay = () => {
diff --git a/server/services/pipeline/manuscriptNarration.js b/server/services/pipeline/manuscriptNarration.js
index dba0ac7fd4..4173785bf9 100644
--- a/server/services/pipeline/manuscriptNarration.js
+++ b/server/services/pipeline/manuscriptNarration.js
@@ -39,8 +39,8 @@ const isAbbreviation = (word) => {
const w = word.toLowerCase().replace(/[^a-z.]/g, '');
if (ABBREVIATIONS.has(w) || ABBREVIATIONS.has(w.replace(/\.$/, ''))) return true;
// Single-letter initials ("J." in "J. R. R. Tolkien") and dotted acronyms
- // ("U.S.A.") — a lone capital before the period.
- return /^[a-z]\.?$/i.test(w);
+ // ("U.S.", "U.S.A.") — a run of single letters each followed by a period.
+ return /^(?:[a-z]\.){1,}[a-z]?$/.test(w);
};
/**
diff --git a/server/services/pipeline/manuscriptNarration.test.js b/server/services/pipeline/manuscriptNarration.test.js
index 075d79fd1d..0827834e54 100644
--- a/server/services/pipeline/manuscriptNarration.test.js
+++ b/server/services/pipeline/manuscriptNarration.test.js
@@ -39,11 +39,18 @@ describe('splitProseIntoSentences', () => {
expect(segs[1].text).toBe('They talked.');
});
- it('does not split a decimal number or dotted acronym mid-token', () => {
+ it('does not split a decimal number mid-token', () => {
expect(splitProseIntoSentences('Pi is 3.14 today.').map((s) => s.text))
.toEqual(['Pi is 3.14 today.']);
});
+ it('does not split a dotted acronym followed by another word', () => {
+ expect(splitProseIntoSentences('He joined the U.S. Navy last year. It changed him.').map((s) => s.text))
+ .toEqual(['He joined the U.S. Navy last year.', 'It changed him.']);
+ expect(splitProseIntoSentences('She wrote to J. R. R. Tolkien once.').map((s) => s.text))
+ .toEqual(['She wrote to J. R. R. Tolkien once.']);
+ });
+
it('keeps trailing quotes/brackets with the sentence', () => {
const segs = splitProseIntoSentences('"Run!" she cried. He froze.');
expect(segs[0].text).toBe('"Run!" she cried.');