Skip to content

Commit 386b8ba

Browse files
authored
Move compatibility to static polyfill handling (#24775)
* Move compatibility to static polyfill handling * Move compatibility to static polyfill handling * Prettier
1 parent e27b97a commit 386b8ba

File tree

12 files changed

+14
-36
lines changed

12 files changed

+14
-36
lines changed

build-scripts/bundle.cjs

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports.sourceMapURL = () => {
1818
module.exports.ignorePackages = () => [];
1919

2020
// Files from NPM packages that we should replace with empty file
21-
module.exports.emptyPackages = ({ latestBuild, isHassioBuild }) =>
21+
module.exports.emptyPackages = ({ isHassioBuild }) =>
2222
[
2323
// Contains all color definitions for all material color sets.
2424
// We don't use it
@@ -28,12 +28,6 @@ module.exports.emptyPackages = ({ latestBuild, isHassioBuild }) =>
2828
require.resolve("@polymer/font-roboto/roboto.js"),
2929
require.resolve("@vaadin/vaadin-material-styles/typography.js"),
3030
require.resolve("@vaadin/vaadin-material-styles/font-icons.js"),
31-
// Compatibility not needed for latest builds
32-
latestBuild &&
33-
// wrapped in require.resolve so it blows up if file no longer exists
34-
require.resolve(
35-
path.resolve(paths.polymer_dir, "src/resources/compatibility.ts")
36-
),
3731
// Icons in supervisor conflict with icons in HA so we don't load.
3832
isHassioBuild &&
3933
require.resolve(

build-scripts/gulp/gather-static.js

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ function copyPolyfills(staticDir) {
5959
npmPath("@webcomponents/webcomponentsjs/webcomponents-bundle.js.map"),
6060
staticPath("polyfills/")
6161
);
62+
// Lit polyfill support
63+
fs.copySync(
64+
npmPath("lit/polyfill-support.js"),
65+
path.join(staticPath("polyfills/"), "lit-polyfill-support.js")
66+
);
6267

6368
// dialog-polyfill css
6469
copyFileDir(

build-scripts/rspack.cjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ const createRspackConfig = ({
155155
},
156156
}),
157157
new rspack.NormalModuleReplacementPlugin(
158-
new RegExp(
159-
bundle.emptyPackages({ latestBuild, isHassioBuild }).join("|")
160-
),
158+
new RegExp(bundle.emptyPackages({ isHassioBuild }).join("|")),
161159
path.resolve(paths.polymer_dir, "src/util/empty.js")
162160
),
163161
!isProdBuild && new LogStartCompilePlugin(),

demo/src/ha-demo.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Compat needs to be first import
2-
import "../../src/resources/compatibility";
31
import { customElement } from "lit/decorators";
42
import { isNavigationClick } from "../../src/common/dom/is-navigation-click";
53
import { navigate } from "../../src/common/navigate";

hassio/src/entrypoint.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Compat needs to be first import
2-
import "../../src/resources/compatibility";
31
import "./hassio-main";
42

53
import("../../src/resources/ha-style");
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export const webComponentsSupported =
2-
"customElements" in window && "content" in document.createElement("template");
1+
export const webComponentsSupported = "attachShadow" in Element.prototype;

src/entrypoints/app.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Compat needs to be first import
2-
import "../resources/compatibility";
31
import "@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min";
42
import "../layouts/home-assistant";
53

src/entrypoints/authorize.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Compat needs to be first import
2-
import "../resources/compatibility";
31
import "../auth/ha-authorize";
42

53
import("../resources/ha-style");

src/entrypoints/custom-panel.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Compat needs to be first import
2-
import "../resources/compatibility";
3-
41
import type { CSSResult } from "lit";
52
import { fireEvent } from "../common/dom/fire_event";
63
import { isNavigationClick } from "../common/dom/is-navigation-click";
@@ -67,9 +64,10 @@ function initialize(
6764
let start: Promise<unknown> = Promise.resolve();
6865

6966
if (!webComponentsSupported) {
70-
start = start.then(() =>
71-
loadJS(`${__STATIC_PATH__}polyfills/webcomponents-bundle.js`)
72-
);
67+
start = start.then(() => {
68+
loadJS(`${__STATIC_PATH__}polyfills/webcomponents-bundle.js`);
69+
loadJS(`${__STATIC_PATH__}polyfills/lit-polyfill-support.js`);
70+
});
7371
}
7472

7573
if (__BUILD__ === "legacy") {

src/entrypoints/onboarding.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Compat needs to be first import
2-
import "../resources/compatibility";
31
import "../onboarding/ha-onboarding";
42

53
import("../resources/ha-style");

src/html/_js_base.html.template

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
return document.head.appendChild(script);
99
}
1010
window.polymerSkipLoadingFontRoboto = true;
11-
if (
12-
!(
13-
"customElements" in window &&
14-
"content" in document.createElement("template")
15-
)
16-
) {
11+
if (!("attachShadow" in Element.prototype)) {
1712
_ls("/static/polyfills/webcomponents-bundle.js", true);
13+
_ls("/static/polyfills/lit-polyfill-support.js", true);
1814
}
1915
// Modern browsers are detected primarily using the user agent string.
2016
// A feature detection which roughly lines up with the modern targets is used

src/resources/compatibility.ts

-2
This file was deleted.

0 commit comments

Comments
 (0)