Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(web): archive a Docs page whose editing session did not open (#615)

Croff9258bb683516
diff --git a/apps/web/src/features/documents/components/DocumentEditor.tsx b/apps/web/src/features/documents/components/DocumentEditor.tsx
index c7457b3d..d539baec 100644
--- a/apps/web/src/features/documents/components/DocumentEditor.tsx
+++ b/apps/web/src/features/documents/components/DocumentEditor.tsx
@@ -145,10 +145,13 @@ export default function DocumentEditor({
restoreDocument.isPending ||
setDocumentFavorite.isPending;
const actionPending = documentAction.pending || providerActionPending;
+ // A session that failed to open holds no local steps, so an action goes with the
+ // page's own version instead of waiting for a session that may never open.
+ const usesSession = editable && !collaboration.openFailed;
const busy =
actionPending ||
saveState === 'saving' ||
- (editable && (!collaboration.ready || collaboration.status === 'saving'));
+ (usesSession && (!collaboration.ready || collaboration.status === 'saving'));
useEffect(() => {
const element = titleRef.current;
@@ -164,8 +167,8 @@ export default function DocumentEditor({
const prepareVersion = async () => {
if (providerActionPending || saveState === 'conflict' || saveState === 'error') return null;
- const synchronized = editable ? await collaboration.flush() : null;
- if (editable && !synchronized) return null;
+ const synchronized = usesSession ? await collaboration.flush() : null;
+ if (usesSession && !synchronized) return null;
const updatedDraft = await save();
if (dirty && !updatedDraft) return null;
return updatedDraft?.version ?? synchronized?.version ?? version;
diff --git a/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx b/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx
index 6ce6a248..c841cc78 100644
--- a/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx
+++ b/apps/web/src/features/documents/hooks/useDocumentCollaboration.test.tsx
@@ -29,6 +29,8 @@ let useDocumentCollaboration: UseDocumentCollaboration;
let originalFetch: typeof fetch;
let originalGlobalDescriptors: Map<string, PropertyDescriptor | undefined>;
let sessionSeed: Record<string, unknown> | null;
+let sessionRejected: boolean;
+let collaboration: ReturnType<UseDocumentCollaboration>;
function projectDocument(version: number, content: string): ProjectDocument {
return {
@@ -56,7 +58,7 @@ function projectDocument(version: number, content: string): ProjectDocument {
}
function Probe({ document }: { document: ProjectDocument }) {
- useDocumentCollaboration({
+ collaboration = useDocumentCollaboration({
editor,
projectKey: 'SEKTA',
document,
@@ -97,8 +99,15 @@ beforeEach(async () => {
({ useDocumentCollaboration } = await import('./useDocumentCollaboration'));
originalFetch = globalThis.fetch;
sessionSeed = null;
+ sessionRejected = false;
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
if (String(input).endsWith('/session')) {
+ if (sessionRejected) {
+ return Response.json(
+ { error: 'contentJson contains an unsupported node.' },
+ { status: 400 },
+ );
+ }
sessionSeed = JSON.parse(String(init?.body)).contentJson;
return Response.json({ documentId: 42, epoch: 'e1', version: 0, contentJson: sessionSeed });
}
@@ -151,5 +160,20 @@ describe('useDocumentCollaboration', () => {
assert.match(JSON.stringify(sessionSeed), /New requirement/);
assert.doesNotMatch(JSON.stringify(sessionSeed), /Old requirement/);
assert.equal(editor.getText(), 'New requirement');
+ assert.equal(collaboration.openFailed, false);
+ });
+
+ it('reports a session the api refused to open', async () => {
+ sessionRejected = true;
+ await act(async () => {
+ root.render(
+ <QueryClientProvider client={queryClient}>
+ <Probe document={projectDocument(2, 'New requirement')} />
+ </QueryClientProvider>,
+ );
+ });
+
+ assert.equal(collaboration.ready, false);
+ assert.equal(collaboration.openFailed, true);
});
});
diff --git a/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts b/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts
index 20120aaa..c4a4be81 100644
--- a/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts
+++ b/apps/web/src/features/documents/hooks/useDocumentCollaboration.ts
@@ -300,6 +300,7 @@ export function useDocumentCollaboration({
status,
version: confirmedVersion.current,
ready,
+ openFailed: !ready && (status === 'error' || status === 'offline'),
flush,
recoveryConflict,
discardRecovery,