Fix grocery sync deletions not persisting and Reminders race condition

Stop cascading syncs by adding an isReconciling flag so that
reconcileFromServer no longer triggers scheduleSync via addItem/deleteItem.
Make Reminders write-only by removing the diff/sync logic from the
onDataChanged callback. Fetch fresh server state in RecipeView reconcile
instead of using stale local cache. Track pending removal recipe IDs via
DataStore so performInitialSync can push deletions for recipes whose
grocery keys have already been removed from groceryDict.

Fix a race condition in RemindersGroceryStore where EKEventStoreChanged
notifications triggered load() before saveMappings() finished writing to
disk, causing the correct in-memory state to be overwritten with stale
data. Add ignoreNextExternalChange flag to skip self-triggered reloads.

Restyle the add/remove all grocery button to match the Plan recipe button
style using Label, subheadline font, and rounded rectangle background.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 06:04:41 +01:00
parent 8b23652f10
commit c38d4075be
6 changed files with 123 additions and 35 deletions

View File

@@ -88,8 +88,12 @@ struct RecipeView: View {
// Reconcile server grocery state with local data
if UserSettings.shared.grocerySyncEnabled {
let serverRecipe = await appState.getRecipe(
id: viewModel.recipe.recipe_id,
fetchMode: .onlyServer
)
groceryList.syncManager?.reconcileFromServer(
serverState: viewModel.recipeDetail.groceryState,
serverState: serverRecipe?.groceryState,
recipeId: String(viewModel.recipe.recipe_id),
recipeName: viewModel.recipeDetail.name
)