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(calendar): stop the event composer from editing itself (#8544)
Eric Hayescdc05224baa6
diff --git a/.agents/rules/web/solid.md b/.agents/rules/web/solid.mdindex 4e6c9b4202..d08a3055e9 100644--- a/.agents/rules/web/solid.md+++ b/.agents/rules/web/solid.md@@ -77,3 +77,13 @@ State ownership, reactivity, and async error handling.- **FE-52** Read reactive values (feature flags, `isEditable()`, the currentuser) inside a reactive scope, never as a snapshot at mount. A flag that isstill loading is not "off".+- **FE-58** A memo that builds an array or object must not recompute on+ unrelated changes: read each input through its own memo first, so the result+ keeps its identity while its contents do. A prop that looks like a plain+ string often reaches you from an accessor that rereads the whole editor+ state, and a fresh `options` array makes a Kobalte `Select` re-assert its+ selection and call `onChange` again. Pair it with setters that write nothing+ when nothing changed (`setReminderMinutes` and `setField` in+ `create-calendar-event-form-controller.ts`): without both, the control's+ answer edits the state that produced it and the loop only ends in a stack+ overflow that takes the app down.diff --git a/apps/web/src/features/calendar/components/composer/EventForm.test.tsx b/apps/web/src/features/calendar/components/composer/EventForm.test.tsxnew file mode 100644index 0000000000..90a8473a91--- /dev/null+++ b/apps/web/src/features/calendar/components/composer/EventForm.test.tsx@@ -0,0 +1,122 @@+/**+ * @vitest-environment jsdom+ */++import { cleanup, render, screen } from '@solidjs/testing-library';+import userEvent from '@testing-library/user-event';+import { createMemo } from 'solid-js';+import { afterEach, beforeEach, expect, it, vi } from 'vitest';++vi.mock('@components/app/split-layout/split-router/mention-links', () => ({+ useMacroMentionLinkResolver: () => () => undefined,+}));+vi.mock(+ '@core/component/LexicalMarkdown/component/core/MarkdownTextarea',+ () => ({ MarkdownTextarea: () => null })+);+vi.mock('@property/editors/selectors/PropertyEntitySelector', () => ({+ PropertyEntitySelector: () => {+ const input = document.createElement('input');+ input.setAttribute('aria-label', 'Search for guests');+ return input;+ },+}));++import { createCalendarEventFormController } from './create-calendar-event-form-controller';+import { EventForm } from './EventForm';+import type { EventEditorCalendarOption } from './event-form-model';++class ObserverStub {+ observe() {}+ unobserve() {}+ disconnect() {}+}++const WORK_CALENDAR: EventEditorCalendarOption = {+ id: 'work-calendar',+ provider: 'google',+ capabilities: {+ autoDecline: true,+ emailReminders: true,+ customRecurrence: false,+ removeConference: false,+ resetRsvp: false,+ conferenceProvider: 'google_meet',+ },+ label: 'Work',+ color: '#123456',+ defaultReminders: [],+ isPrimary: true,+};++/** Renders the form and counts the edits it reports back to its host. */+function showForm() {+ const edits = { count: 0 };+ render(() => {+ const calendarOptions = createMemo(() => [WORK_CALENDAR]);+ const controller = createCalendarEventFormController({+ initialValue: {+ title: 'Customer demo',+ allDay: false,+ start: '2030-01-01T12:00',+ end: '2030-01-01T13:00',+ recurrenceLines: [],+ guests: '',+ location: '',+ description: '',+ conference: 'none',+ calendarId: WORK_CALENDAR.id,+ },+ calendarOptions,+ guestOptions: () => [],+ onChange: () => {+ edits.count += 1;+ // An edit loop overflows the stack and takes the app down with it, so+ // fail the test instead of hanging it.+ if (edits.count > 50) throw new Error('the event form never settled');+ },+ });+ return (+ <EventForm+ controller={controller}+ macroCallsEnabled+ pending={false}+ onCancel={vi.fn()}+ onSubmit={vi.fn()}+ />+ );+ });+ return edits;+}++beforeEach(() => {+ Element.prototype.scrollIntoView = vi.fn();+ vi.stubGlobal('ResizeObserver', ObserverStub);+ vi.stubGlobal('IntersectionObserver', ObserverStub);+ vi.stubGlobal('scrollTo', vi.fn() as unknown as typeof window.scrollTo);+});+afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();+});++it('settles after a typed title instead of editing itself', async () => {+ const user = userEvent.setup();+ const edits = showForm();+ await user.type(screen.getByLabelText('Title'), 'ab');+ expect(screen.getByLabelText('Title')).toHaveProperty(+ 'value',+ 'Customer demoab'+ );+ expect(edits.count).toBeLessThan(10);+});++it('settles after a Macro call is picked', async () => {+ const user = userEvent.setup();+ const edits = showForm();+ const trigger = screen.getByRole('button', { name: /Video conferencing/ });+ await user.click(trigger);+ await user.click(screen.getByRole('option', { name: 'Macro call' }));+ expect(trigger.textContent).toContain('Macro call');+ expect(edits.count).toBeLessThan(10);+});diff --git a/apps/web/src/features/calendar/components/composer/EventPropertyPills.test.tsx b/apps/web/src/features/calendar/components/composer/EventPropertyPills.test.tsxindex b3bd2cafbb..d071e51649 100644--- a/apps/web/src/features/calendar/components/composer/EventPropertyPills.test.tsx+++ b/apps/web/src/features/calendar/components/composer/EventPropertyPills.test.tsx@@ -324,6 +324,24 @@ describe('EventComposerConferencePill', () => {expect(trigger.textContent).toContain('Macro call');});+ it('keeps its selection to itself while the form around it changes', async () => {+ const onChange = vi.fn();+ const [edits, setEdits] = createSignal(0);+ render(() => (+ <EventComposerConferencePill+ value="macro"+ // The real provider arrives through the selected calendar, which the+ // composer rereads on every edit even when the answer is the same.+ provider={edits() >= 0 ? 'google_meet' : null}+ macroCallsEnabled+ canKeepExisting={false}+ onChange={onChange}+ />+ ));+ setEdits(1);+ expect(onChange).not.toHaveBeenCalled();+ });+it('does not offer a new Macro call when calls are unavailable', async () => {const user = userEvent.setup();render(() => (diff --git a/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx b/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsxindex aae066a177..bce310c386 100644--- a/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx+++ b/apps/web/src/features/calendar/components/composer/EventPropertyPills.tsx@@ -381,14 +381,21 @@ export function EventComposerConferencePill(const includesMacroCall = createMemo(() => props.macroCallsEnabled || props.value === 'macro');+ // The list must keep its identity while its contents do. A fresh array makes+ // the select re-assert its selection, which calls `onChange` again; with an+ // editor that rebuilds its state on every keystroke that is an endless loop.+ // The provider and the existing-conferencing flag reach us through accessors+ // that read the whole event, so each one is read through its own memo.+ const provider = createMemo(() => props.provider);+ const canKeepExisting = createMemo(() => props.canKeepExisting);const options = createMemo(() => [...(includesMacroCall() ? [MACRO_CALL_OPTION] : []),- ...(props.provider === 'microsoft_teams'+ ...(provider() === 'microsoft_teams'? [MICROSOFT_TEAMS_OPTION]- : props.provider === null || props.provider === 'other'+ : provider() === null || provider() === 'other'? []: [GOOGLE_MEET_OPTION]),- ...(props.canKeepExisting ? [EXISTING_CONFERENCING_OPTION] : []),+ ...(canKeepExisting() ? [EXISTING_CONFERENCING_OPTION] : []),NO_CONFERENCING_OPTION,]);const selectedOption = () =>diff --git a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.tsindex 60b566a112..df2661d60c 100644--- a/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts+++ b/apps/web/src/features/calendar/components/composer/create-calendar-event-form-controller.ts@@ -128,6 +128,17 @@ function cloneValue(value: EventEditorInitialValues): EventEditorInitialValues {};}+function sameEditorFields(+ current: EventEditorInitialValues,+ next: EventEditorInitialValues+) {+ const fields = new Set([+ ...Object.keys(current),+ ...Object.keys(next),+ ]) as Set<keyof EventEditorInitialValues>;+ return [...fields].every((field) => Object.is(current[field], next[field]));+}+function normalizedReminderMinutes(minutes: readonly number[]) {return [...new Set(minutes)].sort((first, second) => first - second);}@@ -364,7 +375,8 @@ export function createCalendarEventFormController(field: Key,next: EventEditorInitialValues[Key]) => {- const value = { ...state(), [field]: next };+ const current = state();+ const value = { ...current, [field]: next };if (field === 'calendarId') {const capabilities = calendarOptionFor(value.calendarId)?.capabilities;if (@@ -382,6 +394,11 @@ export function createCalendarEventFormController(declineMessage: '',};}+ // A set that leaves every field as it was is not an edit. Writing one+ // anyway hands every reader a new object, and a control that answers a+ // changed value by re-asserting its own selection would set the same field+ // right back — an edit loop the form never settles out of.+ if (sameEditorFields(current, value)) return;replaceState(value);};