Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(markdown): show an editor error when a document has no initial state (#9415)
Wolf Mermelstein6e6ffb415565
diff --git a/apps/web/src/features/drive-view/components/FileDetail.test.tsx b/apps/web/src/features/drive-view/components/FileDetail.test.tsxindex 488f4b740d..d9af47cb82 100644--- a/apps/web/src/features/drive-view/components/FileDetail.test.tsx+++ b/apps/web/src/features/drive-view/components/FileDetail.test.tsx@@ -67,8 +67,14 @@ afterEach(() => {document.body.replaceChildren();});-type Loaded = { userAccessLevel: AccessLevel };-function mount(load: () => Promise<Loaded>, cleanupEditor?: () => void) {+type Loaded = {+ userAccessLevel: AccessLevel;+ source?: { cleanup: () => void };+};+function mount(+ load: (id: string) => Promise<Loaded>,+ cleanupEditor?: () => void+) {const container = document.createElement('div');document.body.appendChild(container);dispose = render(@@ -78,6 +84,7 @@ function mount(load: () => Promise<Loaded>, cleanupEditor?: () => void) {entityType="md"label="document"load={load}+ dispose={(data) => data.source?.cleanup()}>{(data) => {onCleanup(() => cleanupEditor?.());@@ -251,3 +258,42 @@ it('holds the view flow while the shared document resource loads', async () => {await settled.promise;expect(ready).toHaveBeenCalledOnce();});++it('cleans up a sync source returned after its view is disposed', async () => {+ const pending = Promise.withResolvers<Loaded>();+ const cleanupSource = vi.fn();+ const loaded = {+ userAccessLevel: 'view' as const,+ source: { cleanup: cleanupSource },+ };+ mount(() => pending.promise);+ dispose?.();+ dispose = undefined;+ pending.resolve(loaded);+ await pending.promise;+ await Promise.resolve();+ expect(cleanupSource).toHaveBeenCalledOnce();+});++it('reauthorizes after revocation and a late resource at the same access level', async () => {+ const pending = Promise.withResolvers<Loaded>();+ const cleanupSource = vi.fn();+ const load = vi+ .fn<() => Promise<Loaded>>()+ .mockReturnValueOnce(pending.promise)+ .mockResolvedValue({ userAccessLevel: 'view' });+ const container = mount(load);+ notifyAccess?.(null);+ pending.resolve({+ userAccessLevel: 'view',+ source: { cleanup: cleanupSource },+ });+ await pending.promise;+ await Promise.resolve();+ notifyAccess?.('view');+ await vi.waitFor(() =>+ expect(container.textContent).toContain('Document content: view')+ );+ expect(load).toHaveBeenCalledTimes(2);+ expect(cleanupSource).toHaveBeenCalledOnce();+});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/collaboration/CollabProvider.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/collaboration/CollabProvider.tsxindex a664bb0719..1701a570b4 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/collaboration/CollabProvider.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/collaboration/CollabProvider.tsx@@ -8,7 +8,7 @@ import {} from '@core/component/LexicalMarkdown/collaboration/LexicalAwareness';import { $reconcileLexicalState } from '@core/component/LexicalMarkdown/collaboration/reconcile';import { useRemoteCursors } from '@core/component/LexicalMarkdown/collaboration/remote-cursor';-import type { MarkdownEditorErrors } from '@core/component/LexicalMarkdown/constants';+import { MarkdownEditorErrors } from '@core/component/LexicalMarkdown/constants';import type { PluginManager } from '@core/component/LexicalMarkdown/plugins';import {initializeEditorEmpty,@@ -518,16 +518,16 @@ export function CollabProvider(props: CollabProviderProps) {message: 'CollabProvider: manager initialized, initializing editor',});- //TODO: some more descriptive user facing error should be displayed hereif (!state) {logSyncService({documentId: syncSource()!.documentId,level: 'error',context: {},message:- 'editor init: no state from loroManager — editor will NOT become ready (skeleton stays)',+ 'editor init: no state from loroManager — showing the empty-source error',});props.span?.error('Editor initial state is missing');+ props.setEditorError(MarkdownEditorErrors.EMPTY_SOURCE);return;}