diff --git a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.test.tsx b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.test.tsx
index dc78b4455d54b..c5fb3bdf8357a 100644
--- a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.test.tsx
+++ b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.test.tsx
@@ -189,6 +189,43 @@ describe('CreateMaintenanceWindowForm', () => {
expect(managementInput).toBeChecked();
});
+ it('should initialize MWs with selected category ids properly', async () => {
+ const result = appMockRenderer.render(
+
+ );
+
+ await waitFor(() => {
+ expect(
+ result.queryByTestId('maintenanceWindowCategorySelectionLoading')
+ ).not.toBeInTheDocument();
+ });
+
+ const observabilityInput = within(
+ result.getByTestId('maintenanceWindowCategorySelection')
+ ).getByTestId('checkbox-observability');
+ const securityInput = within(
+ result.getByTestId('maintenanceWindowCategorySelection')
+ ).getByTestId('checkbox-securitySolution');
+ const managementInput = within(
+ result.getByTestId('maintenanceWindowCategorySelection')
+ ).getByTestId('checkbox-management');
+
+ expect(observabilityInput).toBeChecked();
+ expect(managementInput).toBeChecked();
+ expect(securityInput).not.toBeChecked();
+ });
+
it('can select category IDs', async () => {
const result = appMockRenderer.render();
diff --git a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx
index f51f16d972c02..3a99e8bf75b90 100644
--- a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx
+++ b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx
@@ -120,7 +120,7 @@ export const CreateMaintenanceWindowForm = React.memo({
+ const [{ recurring, timezone, categoryIds }, _, mounted] = useFormData({
form,
watch: ['recurring', 'timezone', 'categoryIds'],
});
@@ -188,6 +188,9 @@ export const CreateMaintenanceWindowForm = React.memo ruleType.category))]);
hasSetInitialCategories.current = true;
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [isEditMode, ruleTypes]);
+ }, [isEditMode, ruleTypes, mounted]);
// For edit mode, if a maintenance window => category_ids is not an array, this means
// the maintenance window was created before the introduction of category filters.
@@ -206,6 +209,9 @@ export const CreateMaintenanceWindowForm = React.memo