Skip to content

Commit 392af26

Browse files
authoredAug 18, 2023
feat(config): add experimentalSlotFixes config value (#4652)
This adds a new configuration option inside of the `extras` object called `experimentalSlotFixes`. If this is set to `true` then all slot fix configuration options will be automatically set to `true` as well. Furthermore, when new slot fixes are added in the future they'll be automatically enabled if you have this flag enabled.
1 parent 0e94772 commit 392af26

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
 

‎src/compiler/config/test/validate-config.spec.ts

+25
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,31 @@ describe('validation', () => {
394394
expect(config.extras.tagNameTransform).toBe(false);
395395
});
396396

397+
it('should set slot config based on `experimentalSlotFixes`', () => {
398+
userConfig.extras = {};
399+
userConfig.extras.experimentalSlotFixes = true;
400+
const { config } = validateConfig(userConfig, bootstrapConfig);
401+
expect(config.extras.appendChildSlotFix).toBe(true);
402+
expect(config.extras.cloneNodeFix).toBe(true);
403+
expect(config.extras.slotChildNodesFix).toBe(true);
404+
expect(config.extras.scopedSlotTextContentFix).toBe(true);
405+
});
406+
407+
it('should override slot fix config based on `experimentalSlotFixes`', () => {
408+
userConfig.extras = {
409+
appendChildSlotFix: false,
410+
slotChildNodesFix: false,
411+
cloneNodeFix: false,
412+
scopedSlotTextContentFix: false,
413+
};
414+
userConfig.extras.experimentalSlotFixes = true;
415+
const { config } = validateConfig(userConfig, bootstrapConfig);
416+
expect(config.extras.appendChildSlotFix).toBe(true);
417+
expect(config.extras.cloneNodeFix).toBe(true);
418+
expect(config.extras.slotChildNodesFix).toBe(true);
419+
expect(config.extras.scopedSlotTextContentFix).toBe(true);
420+
});
421+
397422
it('should set taskQueue "async" by default', () => {
398423
const { config } = validateConfig(userConfig, bootstrapConfig);
399424
expect(config.taskQueue).toBe('async');

‎src/compiler/config/validate-config.ts

+12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ export const validateConfig = (
111111
validatedConfig.extras.slotChildNodesFix = !!validatedConfig.extras.slotChildNodesFix;
112112
validatedConfig.extras.initializeNextTick = !!validatedConfig.extras.initializeNextTick;
113113
validatedConfig.extras.tagNameTransform = !!validatedConfig.extras.tagNameTransform;
114+
// TODO(STENCIL-914): remove `experimentalSlotFixes` when it's the default behavior
115+
validatedConfig.extras.experimentalSlotFixes = !!validatedConfig.extras.experimentalSlotFixes;
116+
117+
// if the user has set `extras.experimentalSlotFixes` then we turn on all of
118+
// the slot-related fixes automatically.
119+
// TODO(STENCIL-914): remove `experimentalSlotFixes` when it's the default behavior
120+
if (validatedConfig.extras.experimentalSlotFixes) {
121+
validatedConfig.extras.appendChildSlotFix = true;
122+
validatedConfig.extras.cloneNodeFix = true;
123+
validatedConfig.extras.slotChildNodesFix = true;
124+
validatedConfig.extras.scopedSlotTextContentFix = true;
125+
}
114126

115127
validatedConfig.buildEs5 =
116128
validatedConfig.buildEs5 === true || (!validatedConfig.devMode && validatedConfig.buildEs5 === 'prod');

‎src/declarations/stencil-public-compiler.ts

+7
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ export interface ConfigExtras {
368368
* can be customized at runtime. Defaults to `false`.
369369
*/
370370
tagNameTransform?: boolean;
371+
372+
// TODO(STENCIL-914): remove `experimentalSlotFixes` when it's the default behavior
373+
/**
374+
* Enables all slot-related fixes such as {@link slotChildNodesFix}, and
375+
* {@link scopedSlotTextContentFix}.
376+
*/
377+
experimentalSlotFixes?: boolean;
371378
}
372379

373380
export interface Config extends StencilConfig {

0 commit comments

Comments
 (0)
Please sign in to comment.