Skip to content

Commit 5cf84ee

Browse files
rwaskiewicztanner-reitsliamdebeasiTanner ReitsthetaPC
authored
refactor(config): enable stencil's experimental slot fixes (#28995)
Issue number: N/A --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> 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? <!-- Please describe the behavior or changes that are being added by this PR. --> 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 <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer for more information. --> ## 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? <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: Tanner Reits <[email protected]> Co-authored-by: Liam DeBeasi <[email protected]> Co-authored-by: Tanner Reits <[email protected]> Co-authored-by: Maria Hutt <[email protected]>
1 parent 77e275c commit 5cf84ee

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

core/src/components/buttons/buttons.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export class Buttons implements ComponentInterface {
3434
[mode]: true,
3535
['buttons-collapse']: this.collapse,
3636
}}
37-
></Host>
37+
>
38+
<slot></slot>
39+
</Host>
3840
);
3941
}
4042
}

core/src/components/label/label.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export class Label implements ComponentInterface {
107107
[`label-no-animate`]: this.noAnimate,
108108
'label-rtl': document.dir === 'rtl',
109109
})}
110-
></Host>
110+
>
111+
<slot></slot>
112+
</Host>
111113
);
112114
}
113115
}

core/src/utils/slot-mutation-controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export const createSlotMutationController = (
5050

5151
hostMutationObserver.observe(el, {
5252
childList: true,
53+
/**
54+
* This fixes an issue with the `ion-input` and
55+
* `ion-textarea` not re-rendering in some cases
56+
* when using the label slot functionality.
57+
*
58+
* HTML element patches in Stencil that are enabled
59+
* by the `experimentalSlotFixes` flag in Stencil v4
60+
* result in DOM manipulations that won't trigger
61+
* the current mutation observer configuration and
62+
* callback.
63+
*/
64+
subtree: true,
5365
});
5466
}
5567

core/stencil.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,18 @@ export const config: Config = {
257257
globalScript: 'src/global/ionic-global.ts',
258258
enableCache: true,
259259
transformAliasedImportPaths: true,
260+
extras: {
261+
/**
262+
* `experimentalSlotFixes` is necessary in Stencil v4 until the fixes described in
263+
* {@link https://stenciljs.com/docs/config-extras#experimentalslotfixes the Stencil docs for the flag} are the
264+
* default behavior (slated for a future Stencil major version).
265+
*/
266+
experimentalSlotFixes: true,
267+
/**
268+
* `experimentalScopedSlotChanges` is necessary in Stencil v4 until the fixes described in
269+
* {@link https://stenciljs.com/docs/config-extras#experimentalscopedslotchanges the Stencil docs for the flag} are
270+
* the default behavior (slated for a future Stencil major version).
271+
*/
272+
experimentalScopedSlotChanges: true,
273+
}
260274
};

0 commit comments

Comments
 (0)