Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(config): mark cssVarsShim as deprecated #3894

Merged
merged 5 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver
* [`dist-custom-elements` Type Declarations](#dist-custom-elements-type-declarations)
* [Legacy Browser Support Fields Deprecated](#legacy-browser-support-fields-deprecated)
* [`dynamicImportShim`](#dynamicimportshim)
* [`cssVarShim`](#cssvarshim)
* [Deprecated `assetsDir` Removed from `@Component()` decorator](#deprecated-assetsdir-removed-from-component-decorator)
* [Drop Node 12 Support](#drop-node-12-support)
* [Strongly Typed Inputs](#strongly-typed-inputs)
Expand Down Expand Up @@ -98,6 +99,25 @@ export const config: Config = {
};
```

##### `cssVarShim`

`extras.cssVarShim` causes Stencil to include a polyfill for [CSS
variables](https://developer.mozilla.org/en-US/docs/Web/CSS/--*). For Stencil
v3.0.0 this field is renamed to `__deprecated__cssVarsShim`. To retain the
previous behavior the new option can be set in your project's
`stencil.config.ts`:

```ts
// stencil.config.ts
import { Config } from '@stencil/core';

export const config: Config = {
extras: {
__deprecated__cssVarsShim: true
}
};
```

#### Deprecated `assetsDir` Removed from `@Component()` decorator
The `assetsDir` field was [deprecated in Stencil v2.0.0](#componentassetsdir), but some backwards compatibility was retained with a warning message.
It has been fully removed in Stencil v3.0.0 in favor of `assetsDirs`.
Expand Down
1 change: 1 addition & 0 deletions src/app-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const BUILD: BuildConditionals = {
propBoolean: true,
propNumber: true,
propString: true,
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
cssVarShim: false,
constructableCSS: true,
cmpShouldUpdate: true,
Expand Down
2 changes: 2 additions & 0 deletions src/client/client-patch-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ export const patchBrowser = (): Promise<d.CustomElementsDefineOptions> => {
consoleDevInfo('Running in development mode.');
}

// TODO(STENCIL-659): Remove code implementing the CSS variable shim
if (BUILD.cssVarShim) {
// shim css vars
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
plt.$cssShim$ = (win as any).__cssshim;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, may be worth marking src/declarations/stencil-private.ts:1697 (where we declare the PlatformRuntime.$cssShim$ field) with the TODO as well. IDK where quite where to draw the line, I called that out since it's a property declaration that's related to this shim, but by that logic perhaps __cssshim should be commented too 🤔 I don't know where we'd place that comment though, https://github.com/ionic-team/stencil/pull/3894/files#diff-6bbf75caec42d0737e4145ca2fe04c8a15b0a4c81f93d9614d73224241fbb27cL5 seems like the only write of the field, but that's adequately covered (IMO) 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll call it out. Worst case, when we circle around to actually delete the code we decide some parts have to be left in for some reason and delete / change some comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to note references to plt.$cssShim$ as well as references to the CssVarShim interface

}

Expand Down
2 changes: 2 additions & 0 deletions src/client/client-patch-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { CSS, plt, promiseResolve, win } from '@platform';

export const patchEsm = () => {
// NOTE!! This fn cannot use async/await!
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
// @ts-ignore
if (BUILD.cssVarShim && !(CSS && CSS.supports && CSS.supports('color', 'var(--c)'))) {
// @ts-ignore
return import(/* webpackChunkName: "polyfills-css-shim" */ './polyfills/css-shim.js').then(() => {
if ((plt.$cssShim$ = (win as any).__cssshim)) {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
return plt.$cssShim$.i();
} else {
// for better minification
Expand Down
1 change: 1 addition & 0 deletions src/client/client-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type * as d from '../declarations';

export const win = typeof window !== 'undefined' ? window : ({} as Window);

// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export const CSS = BUILD.cssVarShim ? (win as any).CSS : null;

export const doc = win.document || ({ head: {} } as Document);
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/css-parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
/*
Extremely simple css parser. Intended to be not more than what we need
and definitely not necessarily correct =).
Expand Down
2 changes: 2 additions & 0 deletions src/client/polyfills/css-shim/custom-style.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { CssVarShim } from '../../../declarations';
import { CSSScope } from './interfaces';
import { addGlobalLink, loadDocument, startWatcher } from './load-link-styles';
import { addGlobalStyle, parseCSS, reScope, updateGlobalScopes } from './scope';
import { getActiveSelectors, resolveValues } from './selectors';
import { executeTemplate } from './template';

// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export class CustomStyle implements CssVarShim {
private count = 0;
private hostStyleMap = new WeakMap<HTMLElement, HTMLStyleElement>();
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { CustomStyle } from './custom-style';

(function (win: any) {
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export type CSSVariables = { [prop: string]: string };
export type CSSEval = (p: CSSVariables) => string;
export type CSSSegment = string | CSSEval;
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/load-link-styles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { CSSScope } from './interfaces';
import { addGlobalStyle, updateGlobalScopes } from './scope';

Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/regex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export const VAR_USAGE_START = /\bvar\(/;
export const VAR_ASSIGN_START = /\B--[\w-]+\s*:/;

Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/scope.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { parse } from './css-parser';
import { CSSScope } from './interfaces';
import { getSelectors, getSelectorsForScopes, resolveValues } from './selectors';
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { StyleNode, types } from './css-parser';
import { CSSScope, CSSSelector, CSSTemplate, Declaration } from './interfaces';
import { compileTemplate, executeTemplate } from './template';
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/template.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { CSSTemplate, CSSVariables } from './interfaces';
import { COMMENTS, TRAILING_LINES, VAR_ASSIGN_START, VAR_USAGE_START } from './regex';
import { findRegex } from './utils';
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/test/compiler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { compileTemplate, compileVar, executeTemplate, findVarEndIndex, parseVar } from '../template';

describe('compiler', () => {
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/test/css-shim.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { mockWindow } from '@stencil/core/testing';

import { CustomStyle } from '../custom-style';
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/test/init-css-shim.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { fixRelativeUrls, hasCssVariables, hasRelativeUrls } from '../load-link-styles';

describe('hasCssVariables', () => {
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/test/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
import { CSSSelector, Declaration } from '../interfaces';
import { parseCSS } from '../scope';
import { getDeclarations, normalizeValue, resolveValues } from '../selectors';
Expand Down
1 change: 1 addition & 0 deletions src/client/polyfills/css-shim/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export const GLOBAL_SCOPE = ':root';

export function findRegex(regex: RegExp, cssText: string, offset: number) {
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/app-core/app-polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const getAppBrowserCorePolyfills = async (config: d.Config, compilerCtx:
// read all the polyfill content, in this particular order
const polyfills = INLINE_POLYFILLS.slice();

if (config.extras.cssVarsShim) {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
if (config.extras.__deprecated__cssVarsShim) {
polyfills.push(INLINE_CSS_SHIM);
}

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/config/test/validate-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ describe('validation', () => {
const { config } = validateConfig(userConfig, bootstrapConfig);
expect(config.extras.appendChildSlotFix).toBe(false);
expect(config.extras.cloneNodeFix).toBe(false);
expect(config.extras.cssVarsShim).toBe(false);
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
expect(config.extras.__deprecated__cssVarsShim).toBe(false);
// TODO(STENCIL-661): Remove code related to the dynamic import shim
expect(config.extras.__deprecated__dynamicImportShim).toBe(false);
expect(config.extras.lifecycleDOMEvents).toBe(false);
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/config/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const validateConfig = (
validatedConfig.extras = validatedConfig.extras || {};
validatedConfig.extras.appendChildSlotFix = !!validatedConfig.extras.appendChildSlotFix;
validatedConfig.extras.cloneNodeFix = !!validatedConfig.extras.cloneNodeFix;
validatedConfig.extras.cssVarsShim = !!validatedConfig.extras.cssVarsShim;
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
validatedConfig.extras.__deprecated__cssVarsShim = !!validatedConfig.extras.__deprecated__cssVarsShim;
// TODO(STENCIL-661): Remove code related to the dynamic import shim
validatedConfig.extras.__deprecated__dynamicImportShim = !!validatedConfig.extras.__deprecated__dynamicImportShim;
validatedConfig.extras.lifecycleDOMEvents = !!validatedConfig.extras.lifecycleDOMEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const getHydrateBuildConditionals = (cmps: d.ComponentCompilerMeta[]) =>
build.slotRelocation = true;
build.lazyLoad = true;
build.hydrateServerSide = true;
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
build.cssVarShim = false;
build.hydrateClientSide = true;
build.isDebug = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const getLazyBuildConditionals = (

build.lazyLoad = true;
build.hydrateServerSide = false;
build.cssVarShim = config.extras.cssVarsShim;
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
build.cssVarShim = config.extras.__deprecated__cssVarsShim;
build.transformTagName = config.extras.tagNameTransform;
build.asyncQueue = config.taskQueue === 'congestionAsync';
build.taskQueue = config.taskQueue !== 'immediate';
Expand Down
3 changes: 3 additions & 0 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export interface BuildConditionals extends Partial<BuildFeatures> {
cssAnnotations?: boolean;
lazyLoad?: boolean;
profile?: boolean;
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
cssVarShim?: boolean;
constructableCSS?: boolean;
appendChildSlotFix?: boolean;
Expand Down Expand Up @@ -1079,6 +1080,7 @@ export interface HostRuleHeader {
value?: string;
}

// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export interface CssVarShim {
i(): Promise<any>;
addLink(linkEl: HTMLLinkElement): Promise<any>;
Expand Down Expand Up @@ -1694,6 +1696,7 @@ export interface HostRef {
}

export interface PlatformRuntime {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
$cssShim$?: CssVarShim;
$flags$: number;
$orgLocNodes$?: Map<string, RenderNode>;
Expand Down
6 changes: 5 additions & 1 deletion src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,15 @@ export interface ConfigExtras {
*/
cloneNodeFix?: boolean;

// TODO(STENCIL-659): Remove code implementing the CSS variable shim
/**
* Include the CSS Custom Property polyfill/shim for legacy browsers. ESM builds will
* not include the css vars shim. Defaults to `false`
*
* @deprecated Since Stencil v3.0.0. IE 11, Edge <= 18, and old Safari
* versions are no longer supported.
*/
cssVarsShim?: boolean;
__deprecated__cssVarsShim?: boolean;

// TODO(STENCIL-661): Remove code related to the dynamic import shim
/**
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/disconnected-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const disconnectedCallback = (elm: d.HostElement) => {
}

// clear CSS var-shim tracking
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
if (BUILD.cssVarShim && plt.$cssShim$) {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
plt.$cssShim$.removeHost(elm);
}

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export const addStyle = (
// This is only happening on native shadow-dom, do not needs CSS var shim
styleElm.innerHTML = style;
} else {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
if (BUILD.cssVarShim && plt.$cssShim$) {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
styleElm = plt.$cssShim$.createHostStyle(
hostElm,
scopeId,
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/update-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ const updateComponent = async (hostRef: d.HostRef, instance: any, isInitialLoad:
} else {
callRender(hostRef, instance, elm);
}
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
if (BUILD.cssVarShim && plt.$cssShim$) {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
plt.$cssShim$.updateHost(elm);
}
if (BUILD.isDev) {
Expand Down
1 change: 1 addition & 0 deletions src/testing/platform/testing-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const setPlatformHelpers = (helpers: {
Object.assign(plt, helpers);
};

// TODO(STENCIL-659): Remove code implementing the CSS variable shim
export const cssVarShim: d.CssVarShim = false as any;
export const supportsListenerOptions = true;
export const supportsConstructableStylesheets = false;
Expand Down