From 5cf84eea59741140d35b37505d6cbc9de2da0e26 Mon Sep 17 00:00:00 2001 From: Ryan Waskiewicz Date: Tue, 12 Mar 2024 16:08:14 -0400 Subject: [PATCH] refactor(config): enable stencil's experimental slot fixes (#28995) Issue number: N/A --------- ## What is the current behavior? the stencil team has been working on fixing multiple issues with slots elements in the stencil code base. to make these changes backwards compatible and communicate that they were volatile, we added two configuration flags for these fixes that were prefixed with the word "experimental". now that the effort to provide these fixes has largely solidified, the features behind these flags are slightly less volatile. while the "experimental" aspect still technically holds true, we've requested the Framework team to enable these flags in a v8 beta. the stencil team expects these flags to be set to `true` by default in stencil v5, which ought to help prepare for future migrations the ionic framework has to undergo. Previously, Stencil would allow content to project through to a component even when a slot was not present. However, with the changes in `extras.experimentalScopedSlotChanges`, this behavior was changed to hide elements without a destination slot - matching the behavior of a shadow encapsulated component. As such, elements projected through the `ion-label` or `ion-buttons` components would no longer be visible in rendered output. ## What is the new behavior? This commit adds an explicit `slot` tag to components in core leveraging "scoped" encapsulation with no rendered content (i.e. elements with only a `Host` tag and styles). `subtree` was added to a mutation observer. This fixes an issue with the `ion-input` component not re-rendering in some cases when using the label slot functionality. HTML element patches in Stencil that are enabled by the `experimentalSlotFixes` flag result in DOM manipulations that won't trigger the current mutation observer configuration and callback. ## Does this introduce a breaking change? - [] Yes - [x] No ## Other information Would you like us to update the commit message to include the `BREAKING CHANGE:` comment? Unsure of the actual impact on end users here. Similarly, would you like us to update the commit message here from `chore()` to something else? --------- Co-authored-by: Tanner Reits <47483144+tanner-reits@users.noreply.github.com> Co-authored-by: Liam DeBeasi Co-authored-by: Tanner Reits Co-authored-by: Maria Hutt --- core/src/components/buttons/buttons.tsx | 4 +++- core/src/components/label/label.tsx | 4 +++- core/src/utils/slot-mutation-controller.ts | 12 ++++++++++++ core/stencil.config.ts | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/src/components/buttons/buttons.tsx b/core/src/components/buttons/buttons.tsx index e826ec7633..7cf672d7bd 100644 --- a/core/src/components/buttons/buttons.tsx +++ b/core/src/components/buttons/buttons.tsx @@ -34,7 +34,9 @@ export class Buttons implements ComponentInterface { [mode]: true, ['buttons-collapse']: this.collapse, }} - > + > + + ); } } diff --git a/core/src/components/label/label.tsx b/core/src/components/label/label.tsx index 1cfe88ffb7..6f8ad05a4a 100644 --- a/core/src/components/label/label.tsx +++ b/core/src/components/label/label.tsx @@ -107,7 +107,9 @@ export class Label implements ComponentInterface { [`label-no-animate`]: this.noAnimate, 'label-rtl': document.dir === 'rtl', })} - > + > + + ); } } diff --git a/core/src/utils/slot-mutation-controller.ts b/core/src/utils/slot-mutation-controller.ts index 3827c28f9f..c07f2da5f2 100644 --- a/core/src/utils/slot-mutation-controller.ts +++ b/core/src/utils/slot-mutation-controller.ts @@ -50,6 +50,18 @@ export const createSlotMutationController = ( hostMutationObserver.observe(el, { childList: true, + /** + * This fixes an issue with the `ion-input` and + * `ion-textarea` not re-rendering in some cases + * when using the label slot functionality. + * + * HTML element patches in Stencil that are enabled + * by the `experimentalSlotFixes` flag in Stencil v4 + * result in DOM manipulations that won't trigger + * the current mutation observer configuration and + * callback. + */ + subtree: true, }); } diff --git a/core/stencil.config.ts b/core/stencil.config.ts index 78a3697a07..2485eafb23 100644 --- a/core/stencil.config.ts +++ b/core/stencil.config.ts @@ -257,4 +257,18 @@ export const config: Config = { globalScript: 'src/global/ionic-global.ts', enableCache: true, transformAliasedImportPaths: true, + extras: { + /** + * `experimentalSlotFixes` is necessary in Stencil v4 until the fixes described in + * {@link https://stenciljs.com/docs/config-extras#experimentalslotfixes the Stencil docs for the flag} are the + * default behavior (slated for a future Stencil major version). + */ + experimentalSlotFixes: true, + /** + * `experimentalScopedSlotChanges` is necessary in Stencil v4 until the fixes described in + * {@link https://stenciljs.com/docs/config-extras#experimentalscopedslotchanges the Stencil docs for the flag} are + * the default behavior (slated for a future Stencil major version). + */ + experimentalScopedSlotChanges: true, + } };