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(projects): keep the Add to project save alive after the picker closes (#7663)
Peter Chinman2117e3beb22f
diff --git a/apps/web/src/lib/queries/properties/graphql/entity.test.ts b/apps/web/src/lib/queries/properties/graphql/entity.test.tsindex 9e8d1861a8..1d6beeeac2 100644--- a/apps/web/src/lib/queries/properties/graphql/entity.test.ts+++ b/apps/web/src/lib/queries/properties/graphql/entity.test.ts@@ -846,6 +846,73 @@ describe('createGraphqlBulkSaveEntityPropertiesMutation', () => {'settled:test',]);});++ it('saves values requested by an editor that has already closed', async () => {+ const onSettled = vi.fn();+ const mutation = vi.fn(+ (+ _document: unknown,+ _variables: unknown,+ context: Record<string, unknown>+ ) => ({+ toPromise: async () => ({+ operation: { kind: 'mutation', context } as Operation,+ data: { setEntityProperty: { id: 'assignment-1' } },+ stale: false,+ hasNext: false,+ }),+ })+ );+ graphqlClientState.current = { mutation } as unknown as Client;+ let save!: ReturnType<typeof createGraphqlBulkSaveEntityPropertiesMutation>;+ // The project picker closes before its save settles, taking the owner of+ // these mutations with it.+ createRoot((rootDispose) => {+ save = createGraphqlBulkSaveEntityPropertiesMutation({ onSettled });+ rootDispose();+ });++ const result = await save.mutateAsync({+ properties: [+ {+ entityType: 'TASK',+ entityId: 'task-1',+ property: {+ propertyId: 'assignment-1',+ propertyDefinitionId: 'project',+ displayName: 'Project',+ valueType: 'ENTITY',+ isMultiSelect: false,+ } as Property,+ apiValues: {+ valueType: 'ENTITY',+ refs: [{ entity_id: 'project-1', entity_type: 'INITIATIVE' }],+ },+ },+ ],+ });++ expect(result.error).toBeUndefined();+ expect(mutation).toHaveBeenCalledWith(+ expect.anything(),+ {+ input: {+ entityType: 'DOCUMENT',+ entityId: 'task-1',+ propertyDefinitionId: 'project',+ value: {+ entityReference: {+ entityId: 'project-1',+ entityType: 'INITIATIVE',+ specificMessageId: null,+ },+ },+ },+ },+ expect.anything()+ );+ expect(onSettled).toHaveBeenCalledOnce();+ });});describe('createGraphqlEntityPropertiesQuery', () => {diff --git a/apps/web/src/lib/urql-solid/create-urql-mutation.test.tsx b/apps/web/src/lib/urql-solid/create-urql-mutation.test.tsxindex c6f4f6c043..b8ecd718fa 100644--- a/apps/web/src/lib/urql-solid/create-urql-mutation.test.tsx+++ b/apps/web/src/lib/urql-solid/create-urql-mutation.test.tsx@@ -158,6 +158,40 @@ describe('createUrqlMutation', () => {});});+ it('completes a mutation requested as its owner tears down', async () => {+ const { client, executions } = makeFakeClient();+ const onSettled = vi.fn();+ let mutation!: UrqlMutationResult<Data, Variables>;+ createRoot((dispose) => {+ mutation = createUrqlMutation<Data, Variables>(() => ({+ mutation: DOCUMENT,+ client,+ onSettled,+ }));+ dispose();+ });++ const promise = mutation.mutateAsync({ input: 'closing' });+ expect(executions).toHaveLength(1);++ const result: OperationResult<Data, Variables> = {+ operation: operation(),+ data: { updateValue: 'saved' },+ stale: false,+ hasNext: false,+ };+ executions[0].deferred.resolve(result);++ await expect(promise).resolves.toBe(result);+ expect(onSettled).toHaveBeenCalledWith(+ result.data,+ null,+ { input: 'closing' },+ undefined,+ result+ );+ });+it('supports custom execution with merged operation context', async () => {const { client } = makeFakeClient();const pending = deferred<OperationResult<Data, Variables>>();diff --git a/apps/web/src/lib/urql-solid/mutation-observer.ts b/apps/web/src/lib/urql-solid/mutation-observer.tsindex 180089a307..eda3be47de 100644--- a/apps/web/src/lib/urql-solid/mutation-observer.ts+++ b/apps/web/src/lib/urql-solid/mutation-observer.ts@@ -153,10 +153,10 @@ export class MutationObserver<OnMutateResult> = {}): Promise<OperationResult<MutationData, Variables>> => {- if (this.destroyed) {- throw new Error('cannot execute a destroyed mutation observer');- }-+ // Destroying only detaches reactive delivery. A save fired as its owner+ // tears down — a property editor that closes before its write settles —+ // still reaches the client and still runs its lifecycle callbacks; only+ // the state updates below are skipped.const execution = {};const options = this.options;const client = this.client;