Skip to content

Commit

Permalink
Inject ElementInternals polyfill where needed (#20818)
Browse files Browse the repository at this point in the history
  • Loading branch information
steverep authored May 23, 2024
1 parent 7d2cee6 commit e0062cf
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 27 deletions.
21 changes: 20 additions & 1 deletion build-scripts/babel-plugins/custom-polyfill-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ import defineProvider from "@babel/helper-define-polyfill-provider";

// List of polyfill keys with supported browser targets for the functionality
const PolyfillSupport = {
// Note states and shadowRoot properties should be supported.
"element-internals": {
android: 90,
chrome: 90,
edge: 90,
firefox: 126,
ios: 17.4,
opera: 76,
opera_mobile: 64,
safari: 17.4,
samsung: 15.0,
},
fetch: {
android: 42,
chrome: 42,
Expand Down Expand Up @@ -33,7 +45,12 @@ const polyfillMap = {
Proxy: { key: "proxy", module: "proxy-polyfill" },
fetch: { key: "fetch", module: "unfetch/polyfill" },
},
instance: {},
instance: {
attachInternals: {
key: "element-internals",
module: "element-internals-polyfill",
},
},
static: {},
};

Expand All @@ -49,7 +66,9 @@ export default defineProvider(
if (polyfill && shouldInjectPolyfill(polyfill.desc.key)) {
debug(polyfill.desc.key);
utils.injectGlobalImport(polyfill.desc.module);
return true;
}
return false;
},
};
}
Expand Down
7 changes: 6 additions & 1 deletion build-scripts/bundle.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ module.exports.babelOptions = ({ latestBuild, isProdBuild, isTestBuild }) => ({
{ method: "usage-global" },
],
],
exclude: /\/node_modules\/(?:unfetch|proxy-polyfill)\//,
exclude: [
"@webcomponents/scoped-custom-element-registry",
"element-internals-polyfill",
"proxy-polyfill",
"unfetch",
].map((p) => new RegExp(`/node_modules/${p}/`)),
},
{
// Use unambiguous for dependencies so that require() is correctly injected into CommonJS files
Expand Down
1 change: 0 additions & 1 deletion src/components/chips/ha-assist-chip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "element-internals-polyfill";
import { MdAssistChip } from "@material/web/chips/assist-chip";
import { css, html } from "lit";
import { customElement, property } from "lit/decorators";
Expand Down
1 change: 0 additions & 1 deletion src/components/chips/ha-chip-set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "element-internals-polyfill";
import { MdChipSet } from "@material/web/chips/chip-set";
import { customElement } from "lit/decorators";

Expand Down
1 change: 0 additions & 1 deletion src/components/chips/ha-filter-chip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "element-internals-polyfill";
import { MdFilterChip } from "@material/web/chips/filter-chip";
import { css, html } from "lit";
import { customElement, property } from "lit/decorators";
Expand Down
1 change: 0 additions & 1 deletion src/components/chips/ha-input-chip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "element-internals-polyfill";
import { MdInputChip } from "@material/web/chips/input-chip";
import { css } from "lit";
import { customElement } from "lit/decorators";
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-circular-progress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "element-internals-polyfill";
import { MdCircularProgress } from "@material/web/progress/circular-progress";
import { PropertyValues, css } from "lit";
import { customElement, property } from "lit/decorators";
Expand Down
3 changes: 1 addition & 2 deletions src/components/ha-list-item-new.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { MdListItem } from "@material/web/list/list-item";
import { css } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-list-item-new")
export class HaListItemNew extends MdListItem {
Expand Down
3 changes: 1 addition & 2 deletions src/components/ha-list-new.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { MdList } from "@material/web/list/list";
import { css } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-list-new")
export class HaListNew extends MdList {
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-menu-item.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MdMenuItem } from "@material/web/menu/menu-item";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";

Expand Down
5 changes: 2 additions & 3 deletions src/components/ha-menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { css } from "lit";
import { MdMenu } from "@material/web/menu/menu";
import { css } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-menu")
export class HaMenu extends MdMenu {
Expand Down
3 changes: 1 addition & 2 deletions src/components/ha-outlined-button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MdOutlinedButton } from "@material/web/button/outlined-button";
import { css } from "lit";
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { MdOutlinedButton } from "@material/web/button/outlined-button";

@customElement("ha-outlined-button")
export class HaOutlinedButton extends MdOutlinedButton {
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-outlined-field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MdOutlinedField } from "@material/web/field/outlined-field";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";
import { literal } from "lit/static-html";
Expand Down
3 changes: 1 addition & 2 deletions src/components/ha-outlined-icon-button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MdOutlinedIconButton } from "@material/web/iconbutton/outlined-icon-button";
import { css } from "lit";
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { MdOutlinedIconButton } from "@material/web/iconbutton/outlined-icon-button";

@customElement("ha-outlined-icon-button")
export class HaOutlinedIconButton extends MdOutlinedIconButton {
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-outlined-text-field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MdOutlinedTextField } from "@material/web/textfield/outlined-text-field";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";
import { literal } from "lit/static-html";
Expand Down
1 change: 0 additions & 1 deletion src/components/ha-ripple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AttachableController } from "@material/web/internal/controller/attachable-controller";
import { MdRipple } from "@material/web/ripple/ripple";
import "element-internals-polyfill";
import { css } from "lit";
import { customElement } from "lit/decorators";

Expand Down
3 changes: 1 addition & 2 deletions src/components/ha-slider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { MdSlider } from "@material/web/slider/slider";
import { css } from "lit";
import { customElement } from "lit/decorators";
import { mainWindow } from "../common/dom/get_main_window";

@customElement("ha-slider")
Expand Down
5 changes: 2 additions & 3 deletions src/components/ha-sub-menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { css } from "lit";
import { MdSubMenu } from "@material/web/menu/sub-menu";
import { css } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-sub-menu")
export class HaSubMenu extends MdSubMenu {
Expand Down

0 comments on commit e0062cf

Please sign in to comment.