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

feat: mark manuscript issue tabs holding an unsaved edit (#3399)

[._.]/ Adam Eivy13db357eb0f8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index f30cd8b0ff..f5ff23b800 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -43,3 +43,4 @@
- **Routes**: writersRoom/sprites/musicVideo/games lists support opt-in pagination; rounds + songbook partial updates move to `PATCH`; rounds sanitizers extracted to `server/lib/roundsValidation.js`; `universeBuilderRefine` reuses `lib/jsonExtract`
- **Touch targets**: City HUD, writers dock, and music surfaces meet the 44px convention
- ~90 new falsifiability-verified tests across the changed surfaces; creative-director autopilot runs gain a 45-minute idle backstop
+- **Manuscript issue tabs show which issues hold an unsaved edit.** Sections only persist onBlur, so typing in issue 3 and tabbing to issue 7 left the pending text with no cue anywhere on screen. The saved-content baselines the unload guard already tracked are now state rather than a bare ref, so the tab strip subscribes to them: an issue with content drifting from its last server-confirmed save gets a dot (and an "unsaved edits" tooltip) that clears when the save lands — and stays put when the save fails. (#3399)
diff --git a/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.jsx b/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.jsx
index 4666c18b4c..cd09aad66b 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.jsx
@@ -3,12 +3,14 @@
* (`/pipeline/series/:id/manuscript/:issueNumber`), so the editor focuses one
* issue at a time instead of one page-length scroll of every issue. Each tab
* carries a badge with its count of open editorial notes anchored in the current
- * format, so where the feedback lives is visible at a glance.
+ * format, so where the feedback lives is visible at a glance, plus a dot when
+ * that issue holds an unsaved edit — sections only persist onBlur, so tabbing
+ * away mid-edit would otherwise leave the pending text with no cue (#3399).
*/
import { Link } from 'react-router';
-export default function ManuscriptIssueTabs({ seriesId, sections, activeNumber, openCountByNumber }) {
+export default function ManuscriptIssueTabs({ seriesId, sections, activeNumber, openCountByNumber, dirtyNumbers }) {
if (sections.length === 0) return null;
return (
<nav
@@ -18,12 +20,14 @@ export default function ManuscriptIssueTabs({ seriesId, sections, activeNumber,
{sections.map((s) => {
const active = s.number === activeNumber;
const count = openCountByNumber.get(s.number) || 0;
+ const dirty = dirtyNumbers?.has(s.number) || false;
+ const label = s.title ? `Issue ${s.number} — ${s.title}` : `Issue ${s.number}`;
return (
<Link
key={s.issueId}
to={`/pipeline/series/${seriesId}/manuscript/${s.number}`}
aria-current={active ? 'page' : undefined}
- title={s.title ? `Issue ${s.number} — ${s.title}` : `Issue ${s.number}`}
+ title={dirty ? `${label} (unsaved edits)` : label}
className={`shrink-0 inline-flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium border transition-colors ${
active
? 'bg-port-accent text-white border-port-accent'
@@ -37,6 +41,14 @@ export default function ManuscriptIssueTabs({ seriesId, sections, activeNumber,
{count}
</span>
) : null}
+ {dirty ? (
+ <span
+ role="img"
+ aria-label={`Issue ${s.number} has unsaved edits`}
+ title="Unsaved edits — this section saves when the editor loses focus"
+ className={`ml-0.5 w-1.5 h-1.5 rounded-full shrink-0 ${active ? 'bg-white' : 'bg-port-warning'}`}
+ />
+ ) : null}
</Link>
);
})}
diff --git a/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.test.jsx b/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.test.jsx
new file mode 100644
index 0000000000..cee1c1567c
--- /dev/null
+++ b/client/src/components/pipeline/manuscript/ManuscriptIssueTabs.test.jsx
@@ -0,0 +1,58 @@
+import { describe, it, expect } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import { MemoryRouter } from 'react-router';
+
+import ManuscriptIssueTabs from './ManuscriptIssueTabs';
+
+const SECTIONS = [
+ { issueId: 'i1', number: 1, title: 'First', stageId: 'prose', content: 'a' },
+ { issueId: 'i2', number: 2, title: '', stageId: 'prose', content: 'b' },
+];
+
+const renderTabs = (props = {}) => render(
+ <MemoryRouter>
+ <ManuscriptIssueTabs
+ seriesId="s1"
+ sections={SECTIONS}
+ activeNumber={1}
+ openCountByNumber={new Map()}
+ {...props}
+ />
+ </MemoryRouter>,
+);
+
+describe('ManuscriptIssueTabs', () => {
+ it('renders one deep-linkable tab per issue', () => {
+ renderTabs();
+ expect(screen.getByTitle('Issue 1 — First')).toHaveAttribute('href', '/pipeline/series/s1/manuscript/1');
+ expect(screen.getByTitle('Issue 2')).toHaveAttribute('href', '/pipeline/series/s1/manuscript/2');
+ });
+
+ it('badges the count of open notes anchored in that issue', () => {
+ renderTabs({ openCountByNumber: new Map([[2, 3]]) });
+ expect(screen.getByText('3')).toBeInTheDocument();
+ });
+
+ it('marks only the issues holding an unsaved edit (#3399)', () => {
+ renderTabs({ dirtyNumbers: new Set([2]) });
+ expect(screen.getByLabelText('Issue 2 has unsaved edits')).toBeInTheDocument();
+ expect(screen.queryByLabelText('Issue 1 has unsaved edits')).not.toBeInTheDocument();
+ // The tooltip says so too, for the pointer path.
+ expect(screen.getByTitle('Issue 2 (unsaved edits)')).toBeInTheDocument();
+ });
+
+ it('renders no dirty dot when no issue has pending edits', () => {
+ renderTabs({ dirtyNumbers: new Set() });
+ expect(screen.queryByLabelText(/unsaved edits/)).not.toBeInTheDocument();
+ });
+
+ it('tolerates an absent dirtyNumbers prop', () => {
+ renderTabs();
+ expect(screen.queryByLabelText(/unsaved edits/)).not.toBeInTheDocument();
+ });
+
+ it('renders nothing when the series has no drafted sections', () => {
+ const { container } = renderTabs({ sections: [] });
+ expect(container).toBeEmptyDOMElement();
+ });
+});
diff --git a/client/src/pages/PipelineManuscriptEditor.jsx b/client/src/pages/PipelineManuscriptEditor.jsx
index 56720382cc..b83f4c0b1b 100644
--- a/client/src/pages/PipelineManuscriptEditor.jsx
+++ b/client/src/pages/PipelineManuscriptEditor.jsx
@@ -62,6 +62,19 @@ const EMPTY = [];
const VIEW_MODE_KEY = 'portos.manuscript.viewMode';
const initialViewMode = () => (safeReadStorage(VIEW_MODE_KEY) === 'review' ? 'review' : 'live');
+// A section's saved-content key. Includes the stage so switching formats can't
+// compare a teleplay draft against the prose baseline.
+const baselineKey = (section) => `${section.issueId}:${section.stageId}`;
+
+// Has this section drifted from what the server last confirmed? `has` first:
+// an un-seeded key means "we don't know the saved text yet", NOT "unsaved" —
+// without that gate every section reads dirty in the frame before the load
+// resolves, flashing the tab badges on.
+const isSectionDirty = (baselines, section) => {
+ const key = baselineKey(section);
+ return baselines.has(key) && baselines.get(key) !== section.content;
+};
+
export default function PipelineManuscriptEditor() {
const params = useParams();
const { seriesId } = params;
@@ -112,9 +125,24 @@ export default function PipelineManuscriptEditor() {
setFixDrafts((prev) => ({ ...prev, [commentId]: entry }));
// textarea elements keyed by issue number, for reveal-to-section scroll/focus.
const sectionRefs = useRef(new Map());
- const baselineRef = useRef(new Map());
- const seedBaselines = (list) => {
- baselineRef.current = new Map((list || []).map((s) => [`${s.issueId}:${s.stageId}`, s.content]));
+ // Last server-confirmed content per section, as STATE so the issue tabs can
+ // subscribe to unsaved-edit state (sections only persist onBlur, so a tab
+ // switch away from a pending edit needs a visible cue). `baselineRef` mirrors
+ // it for the handlers that read it outside the render cycle (the unload guard,
+ // and the save path's synchronous no-op check) — every write goes through
+ // `commitBaselines` so the ref never trails the state.
+ const [baselines, setBaselines] = useState(() => new Map());
+ const baselineRef = useRef(baselines);
+ const commitBaselines = (next) => {
+ baselineRef.current = next;
+ setBaselines(next);
+ };
+ const seedBaselines = (list) =>
+ commitBaselines(new Map((list || []).map((s) => [baselineKey(s), s.content])));
+ const setBaseline = (key, content) => {
+ const next = new Map(baselineRef.current);
+ next.set(key, content);
+ commitBaselines(next);
};
const patchSection = (issueId, fields) =>
@@ -132,10 +160,7 @@ export default function PipelineManuscriptEditor() {
// whenever any section's live content has drifted from its saved baseline.
useEffect(() => {
const onBeforeUnload = (e) => {
- const dirty = liveSectionsRef.current.some((s) => {
- const key = `${s.issueId}:${s.stageId}`;
- return baselineRef.current.get(key) !== s.content;
- });
+ const dirty = liveSectionsRef.current.some((s) => isSectionDirty(baselineRef.current, s));
if (dirty) e.preventDefault();
};
window.addEventListener('beforeunload', onBeforeUnload);
@@ -395,7 +420,7 @@ export default function PipelineManuscriptEditor() {
const setSectionContent = (issueId, content) => patchSection(issueId, { content });
const saveSectionContent = async (section, content) => {
- const key = `${section.issueId}:${section.stageId}`;
+ const key = baselineKey(section);
if (baselineRef.current.get(key) === content) return;
setSaveState((prev) => ({ ...prev, [section.issueId]: 'saving' }));
const result = await savePipelineManuscriptSection(
@@ -408,7 +433,7 @@ export default function PipelineManuscriptEditor() {
return null;
});
if (result?.section) {
- baselineRef.current.set(key, result.section.content);
+ setBaseline(key, result.section.content);
patchSection(section.issueId, { versions: result.section.versions });
}
setSaveState((prev) => ({ ...prev, [section.issueId]: result ? 'saved' : undefined }));
@@ -477,7 +502,7 @@ export default function PipelineManuscriptEditor() {
if (!result?.stage) return null;
const content = result.stage.output || '';
const versions = (result.stage.runHistory || []).map((h) => ({ runId: h.runId, createdAt: h.createdAt }));
- baselineRef.current.set(`${section.issueId}:${section.stageId}`, content);
+ setBaseline(baselineKey(section), content);
patchSection(section.issueId, { content, versions });
setSaveState((prev) => ({ ...prev, [section.issueId]: 'saved' }));
toast.success('Reverted to the selected version');
@@ -527,7 +552,7 @@ export default function PipelineManuscriptEditor() {
list.forEach((changed) => {
if (changed?.issueId && changed.stageId === viewType) {
patchSection(changed.issueId, { content: changed.content, versions: changed.versions });
- baselineRef.current.set(`${changed.issueId}:${changed.stageId}`, changed.content);
+ setBaseline(baselineKey(changed), changed.content);
setSaveState((prev) => ({ ...prev, [changed.issueId]: 'saved' }));
}
});
@@ -565,6 +590,15 @@ export default function PipelineManuscriptEditor() {
return set;
}, [sectionSpans]);
+ // Issue numbers holding an unsaved edit, for the tab dirty dots. Sections save
+ // onBlur, so tabbing away from a pending edit leaves it unsaved with no cue
+ // unless the tab itself carries one (#3399).
+ const dirtyNumbers = useMemo(() => {
+ const set = new Set();
+ sections.forEach((s) => { if (isSectionDirty(baselines, s)) set.add(s.number); });
+ return set;
+ }, [sections, baselines]);
+
// Open-note count per issue, for the tab badges.
const openCountByNumber = useMemo(() => {
const map = new Map();
@@ -740,6 +774,7 @@ export default function PipelineManuscriptEditor() {
sections={sections}
activeNumber={activeNumber}
openCountByNumber={openCountByNumber}
+ dirtyNumbers={dirtyNumbers}
/>
{activeSection ? (() => {
const section = activeSection;
diff --git a/client/src/pages/PipelineManuscriptEditor.test.jsx b/client/src/pages/PipelineManuscriptEditor.test.jsx
index 87286b51a7..0598d0a4fd 100644
--- a/client/src/pages/PipelineManuscriptEditor.test.jsx
+++ b/client/src/pages/PipelineManuscriptEditor.test.jsx
@@ -234,6 +234,34 @@ describe('PipelineManuscriptEditor', () => {
expect(await screen.findByTitle('Show prior saved versions')).toBeInTheDocument();
});
+ it('marks the issue tab while an edit is unsaved and clears it once the save lands (#3399)', async () => {
+ api.savePipelineManuscriptSection.mockResolvedValue({
+ section: { issueId: 'iss-1', number: 1, title: 'One', stageId: 'prose', content: 'The hero walked in. She stayed.', versions: [] },
+ });
+ renderEditor();
+ const ta = await screen.findByDisplayValue('The hero walked in. She left.');
+ // Loaded and untouched — no dirty dot.
+ expect(screen.queryByLabelText('Issue 1 has unsaved edits')).not.toBeInTheDocument();
+
+ // Sections persist onBlur, so typing alone leaves the edit pending — the tab
+ // must say so, since the user can navigate away before the field blurs.
+ fireEvent.change(ta, { target: { value: 'The hero walked in. She stayed.' } });
+ expect(await screen.findByLabelText('Issue 1 has unsaved edits')).toBeInTheDocument();
+
+ fireEvent.blur(ta);
+ await waitFor(() => expect(screen.queryByLabelText('Issue 1 has unsaved edits')).not.toBeInTheDocument());
+ });
+
+ it('keeps the tab marked when a save fails, so the pending edit stays visible (#3399)', async () => {
+ api.savePipelineManuscriptSection.mockResolvedValue(null); // service rejected → caller toasts + resolves null
+ renderEditor();
+ const ta = await screen.findByDisplayValue('The hero walked in. She left.');
+ fireEvent.change(ta, { target: { value: 'The hero walked in. She stayed.' } });
+ fireEvent.blur(ta);
+ await waitFor(() => expect(api.savePipelineManuscriptSection).toHaveBeenCalled());
+ expect(screen.getByLabelText('Issue 1 has unsaved edits')).toBeInTheDocument();
+ });
+
it('Review mode renders annotated prose with an Edit toggle that swaps in the textarea', async () => {
renderEditor();
await screen.findByText('My Series');