Skip to content

Commit

Permalink
refactor: remove shadowSupportMode = 'any' (#3953)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsjtu authored Jan 29, 2024
1 parent 8e90e92 commit b99008b
Show file tree
Hide file tree
Showing 24 changed files with 30 additions and 110 deletions.
1 change: 0 additions & 1 deletion packages/@lwc/engine-core/src/framework/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ function createComponentDef(Ctor: LightningElementConstructor): ComponentDef {

if (
!isUndefined(ctorShadowSupportMode) &&
ctorShadowSupportMode !== ShadowSupportMode.Any &&
ctorShadowSupportMode !== ShadowSupportMode.Default &&
ctorShadowSupportMode !== ShadowSupportMode.Native
) {
Expand Down
32 changes: 10 additions & 22 deletions packages/@lwc/engine-core/src/framework/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export const enum ShadowMode {
}

export const enum ShadowSupportMode {
Any = 'any',
Default = 'reset',
Native = 'native',
}
Expand Down Expand Up @@ -509,35 +508,24 @@ function computeShadowMode(def: ComponentDef, owner: VM | null, renderer: Render
const { isSyntheticShadowDefined } = renderer;

let shadowMode;
// If ENABLE_FORCE_SHADOW_MIGRATE_MODE is true, then ShadowMode.Synthetic here will mean "force-migrate" mode.
if (isSyntheticShadowDefined || lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
if (def.renderMode === RenderMode.Light) {
// ShadowMode.Native implies "not synthetic shadow" which is consistent with how
// everything defaults to native when the synthetic shadow polyfill is unavailable.
shadowMode = ShadowMode.Native;
} else if (
lwcRuntimeFlags.ENABLE_MIXED_SHADOW_MODE ||
def.shadowSupportMode === ShadowSupportMode.Native
) {
if (
def.shadowSupportMode === ShadowSupportMode.Any ||
def.shadowSupportMode === ShadowSupportMode.Native
) {
} else if (def.shadowSupportMode === ShadowSupportMode.Native) {
shadowMode = ShadowMode.Native;
} else {
const shadowAncestor = getNearestShadowAncestor(owner);
if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === ShadowMode.Native) {
// Transitive support for native Shadow DOM. A component in native mode
// transitively opts all of its descendants into native.
shadowMode = ShadowMode.Native;
} else {
const shadowAncestor = getNearestShadowAncestor(owner);
if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === ShadowMode.Native) {
// Transitive support for native Shadow DOM. A component in native mode
// transitively opts all of its descendants into native.
shadowMode = ShadowMode.Native;
} else {
// Synthetic if neither this component nor any of its ancestors are configured
// to be native.
shadowMode = ShadowMode.Synthetic;
}
// Synthetic if neither this component nor any of its ancestors are configured
// to be native.
shadowMode = ShadowMode.Synthetic;
}
} else {
shadowMode = ShadowMode.Synthetic;
}
} else {
// Native if the synthetic shadow polyfill is unavailable.
Expand Down
1 change: 0 additions & 1 deletion packages/@lwc/features/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { FeatureFlagMap, FeatureFlagName, FeatureFlagValue } from './types';
const features: FeatureFlagMap = {
PLACEHOLDER_TEST_FLAG: null,
ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST: null,
ENABLE_MIXED_SHADOW_MODE: null,
DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE: null,
ENABLE_WIRE_SYNC_EMIT: null,
DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
Expand Down
6 changes: 0 additions & 6 deletions packages/@lwc/features/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ export interface FeatureFlagMap {
*/
PLACEHOLDER_TEST_FLAG: FeatureFlagValue;

/**
* LWC engine flag to enable mixed shadow mode. Setting this flag to `true` enables usage of
* native shadow DOM even when the synthetic shadow polyfill is applied.
*/
ENABLE_MIXED_SHADOW_MODE: FeatureFlagValue;

/**
* LWC engine flag to force native shadow mode for mixed shadow mode testing.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, setFeatureFlagForTest } from 'lwc';
import { createElement } from 'lwc';
import { extractDataIds } from 'test-utils';
import Basic from 'x/basic';
import Other from 'x/other';
Expand All @@ -8,14 +8,6 @@ import ShadowWithScoped from 'x/shadowWithScoped';
import PseudoParent from 'x/pseudoParent';

describe('Light DOM scoped CSS', () => {
beforeAll(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
});

afterAll(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
});

it('should scope scoped CSS and allow unscoped CSS to leak out', () => {
const basicElement = createElement('x-basic', { is: Basic });
const otherElement = createElement('x-other', { is: Other });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, setFeatureFlagForTest } from 'lwc';
import { createElement } from 'lwc';
import { isNativeShadowRootInstance, isSyntheticShadowRootInstance } from 'test-utils';

import Invalid from 'x/invalid';
Expand All @@ -19,29 +19,6 @@ describe('shadowSupportMode static property', () => {
});
});

describe('ENABLE_MIXED_SHADOW_MODE', () => {
beforeEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
});

it('should be configured as "any" (sanity)', () => {
expect(Valid.shadowSupportMode === 'any').toBeTrue();
});

it('should enable mixed shadow mode', () => {
const elm = createElement('x-valid', { is: Valid });
if (process.env.NATIVE_SHADOW_ROOT_DEFINED) {
expect(isNativeShadowRootInstance(elm.shadowRoot)).toBeTrue();
} else {
expect(isSyntheticShadowRootInstance(elm.shadowRoot)).toBeTrue();
}
});

afterEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
});
});

describe('ENABLE_NATIVE_SHADOW_MODE', () => {
it('should be configured as "native" (sanity)', () => {
expect(NativeOnly.shadowSupportMode === 'native').toBeTrue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { LightningElement, api } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';

@api
setInnerHtmlOnShadowRoot() {
this.template.innerHTML = '<div></div>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { createElement, setFeatureFlagForTest } from 'lwc';
import { createElement } from 'lwc';
import Test from 'x/test';

describe('scoped-ids', () => {
beforeAll(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
});

afterAll(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
});

it('should entrust id scoping to native shadow (static)', () => {
const elm = createElement('x-test', { is: Test });
document.body.appendChild(elm);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';

get yamanashi() {
return 'yamanashi';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class Child extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, setFeatureFlagForTest } from 'lwc';
import { createElement } from 'lwc';
import { extractDataIds, isNativeShadowRootInstance } from 'test-utils';
import ParentAnyChildAny from 'x/parentAnyChildAny';
import ParentAnyChildReset from 'x/parentAnyChildReset';
Expand All @@ -17,13 +17,6 @@ import GrandparentResetParentResetChildReset from 'x/grandparentResetParentReset

if (!process.env.NATIVE_SHADOW) {
describe('synthetic behavior', () => {
beforeEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
});
afterEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
});

const scenarios = [
{
Component: ParentAnyChildAny,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, setFeatureFlagForTest } from 'lwc';
import { createElement } from 'lwc';
import { isNativeShadowRootInstance, isSyntheticShadowRootInstance } from 'test-utils';

import ResetExtendsAny from 'x/resetExtendsAny';
Expand All @@ -14,19 +14,14 @@ function assertNativeShadowRootWhenPossible(elm) {
}

if (!process.env.NATIVE_SHADOW) {
describe('when root component shadowSupportMode="any"', () => {
describe('when root component shadowSupportMode="native"', () => {
let elm;

beforeEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
elm = createElement('x-native-container', { is: NativeContainer });
document.body.appendChild(elm);
});

afterAll(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
});

it('should attach a native shadow root when possible', () => {
assertNativeShadowRootWhenPossible(elm);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, setFeatureFlagForTest } from 'lwc';
import { createElement } from 'lwc';
import { extractDataIds } from 'test-utils';
import Container from 'x/container';
import Escape from 'x/escape';
Expand All @@ -19,13 +19,6 @@ import PreserveComments from 'x/preserveComments';

if (!process.env.NATIVE_SHADOW) {
describe('Mixed mode for static content', () => {
beforeEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', true);
});
afterEach(() => {
setFeatureFlagForTest('ENABLE_MIXED_SHADOW_MODE', false);
});

['native', 'synthetic'].forEach((firstRenderMode) => {
it(`should set the tokens for synthetic shadow when it renders first in ${firstRenderMode}`, () => {
const elm = createElement('x-container', { is: Container });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';

export default class Native extends LightningElement {
static shadowSupportMode = 'any';
static shadowSupportMode = 'native';
}

0 comments on commit b99008b

Please sign in to comment.