From a0b3ef02af718e232246515bb873ad8c090fa55d Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Wed, 2 Aug 2023 15:20:22 -0400 Subject: [PATCH] fix(item-sliding): account for options added before watcher (#27915) Issue number: resolves #27910 --------- ## What is the current behavior? There is an edge case in our `ion-item-sliding` code where options can be added after the `querySelectorAll` has been run in `updateOptions` but before `watchForOptions` has been called which causes us to miss the newly created options. These options can never be shown as a result. ## What is the new behavior? - `watchForOptions` is called before the initial `updateOptions` call so that we can re-run `updateOptions` in the event that options are added while that first call is running. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `7.2.2-dev.11690983626.19a2a8cb` --- core/src/components/item-sliding/item-sliding.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/components/item-sliding/item-sliding.tsx b/core/src/components/item-sliding/item-sliding.tsx index ec605429b5..a250b5e9bf 100644 --- a/core/src/components/item-sliding/item-sliding.tsx +++ b/core/src/components/item-sliding/item-sliding.tsx @@ -76,12 +76,19 @@ export class ItemSliding implements ComponentInterface { this.item = el.querySelector('ion-item'); this.contentEl = findClosestIonContent(el); - await this.updateOptions(); - + /** + * The MutationObserver needs to be added before we + * call updateOptions below otherwise we may miss + * ion-item-option elements that are added to the DOM + * while updateOptions is running and before the MutationObserver + * has been initialized. + */ this.mutationObserver = watchForOptions(el, 'ion-item-option', async () => { await this.updateOptions(); }); + await this.updateOptions(); + this.gesture = (await import('../../utils/gesture')).createGesture({ el, gestureName: 'item-swipe',