# GitLab !50: Fix setTimeout async anti-pattern in calendar-year component Original: `nessar/vac-optimizer`; GitLab MergeRequest ID 106. Target: [#128](https://gitea.nessar.fr/nessar/vac-optimizer/pulls/128). Author: admin-backup (GitLab user 3). Created: 2025-11-17T23:17:39.000Z. Last source update: 2025-11-17T23:26:21.000Z. Source state: merged; discussion locked: False. This linked record preserves source attribution, timestamps, discussion grouping, review positions and historical diffs. Current Gitea activity is separate from the original source dates. Old CI jobs and their reports are omitted by owner decision. Source requested reviewers: admin-backup (GitLab user 3). ## Discussions and activity ### Discussion 1750ee35ebf7bdfb38a99d0c170aedd393cec7b0 #### Source note 614 — admin-backup (GitLab user 3) — 2025-11-17T23:17:40Z system activity. ````text assigned to `@Copilot` ```` ### Discussion 2aa64d02eaed29b8d269b1dc85082b2b2f51cede #### Source note 615 — admin-backup (GitLab user 3) — 2025-11-17T23:17:40Z system activity. ````text assigned to `@THoguet` ```` ### Discussion 63b0a3d7e1941939706e91ae55e36160efaa769a #### Source note 618 — admin-backup (GitLab user 3) — 2025-11-17T23:17:42Z system activity. ````text mentioned in merge request !49 ```` ### Discussion 2e85f7ebda51a1c6f746bf67b0eaffa3d2eef001 #### Source note 616 — admin-backup (GitLab user 3) — 2025-11-17T23:23:49Z system activity. ````text changed title from **{-[WIP] Update loading spinner enhancement and progress indication-}** to **{+Fix setTimeout async anti-pattern in calendar-year component+}** ```` ### Discussion 6243beb0a759954e9d5bb26fdfea860eb57a7d20 #### Source note 617 — admin-backup (GitLab user 3) — 2025-11-17T23:23:56Z system activity. ````text requested review from `@THoguet` ```` ### Discussion 529baa0e0f19a0d7e3263b6f8ade68389ddd9d95 #### Source note 619 — admin-backup (GitLab user 3) — 2025-11-17T23:26:19Z ````text *Merged by: THoguet at 2025-11-17 23:26:19 UTC* ```` ## State event records - {"close_after_error_tracking_resolve": false, "close_auto_resolve_prometheus_alert": false, "created_at": "2025-11-17T23:26:19+00:00", "epic_id": null, "id": 328, "imported_from": 4, "issue_id": null, "merge_request_id": 106, "namespace_id": 38, "source_commit": null, "source_merge_request_id": null, "state": 2, "user_id": 3} - {"close_after_error_tracking_resolve": false, "close_auto_resolve_prometheus_alert": false, "created_at": "2025-11-17T23:26:19+00:00", "epic_id": null, "id": 330, "imported_from": 4, "issue_id": null, "merge_request_id": 106, "namespace_id": 38, "source_commit": "54c2160f0dd293f8c1c78342e155a65d891041fd", "source_merge_request_id": null, "state": 3, "user_id": 3} ## Historical diff versions ### Diff version 105 — 2026-05-03T15:59:55.823278Z Base `5ab29ef7700cb45e321469e2b5f69678a5761fff`; start `3fab4c4922c14fb3b30c29801100cac634008827`; head `ae28ffa07ad52a6a649045a9758d4e4a2175a60e`. Files: 1; stored commits: 2. #### `src/app/components/calendar-year/calendar-year.ts` → `None` Modes 100644 → 100644; new=False, deleted=False, renamed=False, binary=False, too_large=False. ````diff @@ -41,23 +41,25 @@ export class CalendarYear { console.log('Optimizing vacations with data:', vacationData); this.isLoading.set(true); this.loadingProgress.set(0); - // Simulate server-side calculation with a small delay - setTimeout(async () => { - if (this.selectedDates) { - // Create a copy to avoid mutating the original signal data - const remainingDays = await this.selectedDates.optimizeVacations( - { ...vacationData }, - this.calendarSettingsService, - this.calendarService, - (progress: number) => { - this.loadingProgress.set(progress); - }, - ); - // Update the remaining vacation days signal - this.userInput.remainingVacationDaysSignal.set(remainingDays); - } - this.isLoading.set(false); - }, 1); + // Defer execution to allow UI to update + queueMicrotask(() => { + void (async () => { + if (this.selectedDates) { + // Create a copy to avoid mutating the original signal data + const remainingDays = await this.selectedDates.optimizeVacations( + { ...vacationData }, + this.calendarSettingsService, + this.calendarService, + (progress: number) => { + this.loadingProgress.set(progress); + }, + ); + // Update the remaining vacation days signal + this.userInput.remainingVacationDaysSignal.set(remainingDays); + } + this.isLoading.set(false); + })(); + }); }); } ````