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(fableloom): retain selected exports across dialog and story updates (#13111)

[._.]/ Adam Eivyc7defda41cd0
diff --git a/client/src/components/fableloom/LoomExportModal.jsx b/client/src/components/fableloom/LoomExportModal.jsx
index 584a153438..32998abe0c 100644
--- a/client/src/components/fableloom/LoomExportModal.jsx
+++ b/client/src/components/fableloom/LoomExportModal.jsx
@@ -10,7 +10,7 @@ import { formatBytes, formatCount } from '../../utils/formatters.js';
const gates = ['graph', 'outline', 'production', 'media', 'approval', 'cast'];
const terminal = job => ['completed', 'failed', 'cancelled'].includes(job?.status);
-export default function LoomExportModal({ loom, onClose }) {
+export default function LoomExportModal({ loom, open = true, onClose }) {
const [options, setOptions] = useState({ episodeIds: loom.episodes.map(e => e.id), includePlayer: true,
includeCharacters: false, includeVoice: false, allowDraft: false, mediaProfile: 'source' });
const [preflight, setPreflight] = useState(null);
@@ -20,22 +20,20 @@ export default function LoomExportModal({ loom, onClose }) {
const [busy, setBusy] = useState(false);
const mounted = useMounted();
const identity = JSON.stringify([loom, options]);
- const currentIdentity = useRef(identity);
- currentIdentity.current = identity;
const controller = useRef(null);
- useSocketSubscription('fableloom', { onResubscribe: () => controller.current?.() });
+ useSocketSubscription('fableloom', { enabled: open || !!jobId, onResubscribe: () => controller.current?.() });
useEffect(() => {
let active = true;
setPreflight(null);
setError('');
- if (options.episodeIds.length) {
+ if (open && options.episodeIds.length) {
api.preflightLoomExport(loom.id, options, { silent: true }).then(result => {
if (active) setPreflight({ identity, ...result });
}).catch(err => { if (active) setError(err.message); });
}
return () => { active = false; };
- }, [loom.id, identity, options]);
+ }, [loom.id, identity, options, open]);
useEffect(() => {
let active = true;
@@ -57,9 +55,8 @@ export default function LoomExportModal({ loom, onClose }) {
if (busy || !preflight?.canBuild || preflight.identity !== identity) return;
setBusy(true);
setError('');
- const startedIdentity = identity;
await api.startLoomExport(loom.id, options, { silent: true }).then(result => {
- if (mounted.current && currentIdentity.current === startedIdentity) setJobId(result.jobId);
+ if (mounted.current) setJobId(result.jobId);
}).catch(err => { if (mounted.current) setError(err.message); });
if (mounted.current) setBusy(false);
};
@@ -73,7 +70,7 @@ export default function LoomExportModal({ loom, onClose }) {
const checked = preflight?.identity === identity ? preflight : null;
const findings = checked?.findings || [];
const running = jobId && (!job || !terminal(job));
- return <Modal open onClose={onClose} size="lg" ariaLabel="Export story" panelClassName="bg-port-card border border-port-border rounded-lg p-4 space-y-4">
+ return <Modal open={open} onClose={onClose} size="lg" ariaLabel="Export story" panelClassName="bg-port-card border border-port-border rounded-lg p-4 space-y-4">
<div className="flex items-center justify-between gap-2"><h2 className="text-lg font-semibold">Export story</h2><button onClick={onClose}>Close</button></div>
<p className="text-sm text-port-text-muted">Build a static ZIP for handoff. Draft assets are refused by default. Voice requires character opt-in and approved voice references.</p>
<fieldset disabled={busy || !!running} className="space-y-3">
diff --git a/client/src/components/fableloom/LoomExportModal.test.jsx b/client/src/components/fableloom/LoomExportModal.test.jsx
index f65fab4899..59d4e0dfc5 100644
--- a/client/src/components/fableloom/LoomExportModal.test.jsx
+++ b/client/src/components/fableloom/LoomExportModal.test.jsx
@@ -63,4 +63,28 @@ describe('story export interaction', () => {
expect(screen.queryByText('error: Old loom')).toBeNull();
expect(screen.getByText('Build ZIP')).toBeEnabled();
});
+
+ it('retains the selected job when closed during admission, accepts same-loom edits and resumes completed downloads', async () => {
+ let resolveStart;
+ api.startLoomExport.mockReturnValueOnce(new Promise(resolve => { resolveStart = resolve; }));
+ const close = vi.fn();
+ const { rerender } = render(<LoomExportModal loom={loom} onClose={close} />);
+ await waitFor(() => expect(screen.getByText('Build ZIP')).toBeEnabled());
+ fireEvent.click(screen.getByText('Build ZIP'));
+ fireEvent.click(screen.getByText('Close'));
+ expect(close).toHaveBeenCalled();
+ const changed = { ...loom, name: 'Updated while admitting' };
+ rerender(<LoomExportModal loom={changed} open={false} onClose={close} />);
+ await act(async () => resolveStart({ jobId: 'selected' }));
+ expect(screen.queryByRole('dialog')).toBeNull();
+ rerender(<LoomExportModal loom={changed} open onClose={close} />);
+ await screen.findByText(/selected: packing/);
+ expect(api.startLoomExport).toHaveBeenCalledTimes(1);
+ rerender(<LoomExportModal loom={changed} open={false} onClose={close} />);
+ await emit(snapshot('selected', 'completed', 2));
+ rerender(<LoomExportModal loom={changed} open onClose={close} />);
+ expect(screen.getByText('Download selected ZIP')).toBeEnabled();
+ await act(async () => {});
+ });
+
});
diff --git a/client/src/pages/FableLoomStory.jsx b/client/src/pages/FableLoomStory.jsx
index d425bac8f6..237c4e4aa0 100644
--- a/client/src/pages/FableLoomStory.jsx
+++ b/client/src/pages/FableLoomStory.jsx
@@ -784,7 +784,7 @@ export default function FableLoomStory({ view = 'graph' }) {
/>
)}
- {exportOpen && <LoomExportModal key={loom.id} loom={loom} onClose={() => setExportOpen(false)} />}
+ <LoomExportModal key={loom.id} loom={loom} open={exportOpen} onClose={() => setExportOpen(false)} />
<LoomSettingsDrawer
open={settingsOpen}