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

Inject ResizeObserver polyfill where needed #20754

Merged
merged 1 commit into from
May 24, 2024
Merged

Conversation

steverep
Copy link
Member

@steverep steverep commented May 7, 2024

Proposed change

Inject polyfill for ResizeObserver using Babel plugin and remove manual loads. Feature detection is simplified and a top level await is used to only load it when needed.

I made sure there were no errors, but since functionally the observer callbacks mostly do visual stuff, please double check the areas where we use them. Note it's easy to force both the polyfill just by changing the feature detection to if (true), and the legacy build can be forced just by editing index.html to remove the scripts that do imports.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Added support for the ResizeObserver polyfill, ensuring compatibility with older browsers.
  • Refactor

    • Simplified the initialization process for ResizeObserver across multiple components by removing the loadPolyfillIfNeeded function calls.
  • Chores

    • Updated the polyfill management system to prevent self-injection and streamline polyfill handling.

These changes improve the performance and maintainability of the application while ensuring better cross-browser compatibility.

@github-actions github-actions bot added the Build Related to building the code label May 7, 2024
@steverep
Copy link
Member Author

steverep commented May 7, 2024

@bramkragten the small overall bundle increases are because this now polyfills dependencies that use ResizeObserver, which we were not doing before. These include mwc-linear-progress, codemirror, vis-network, vaadin and charjs. At a glance, most of them guard against it not being available, so the polyfill is optional. Presumably, it would be better to polyfill for a better UX, so I let it be. Thoughts on that?

@steverep steverep marked this pull request as ready for review May 8, 2024 12:25
@steverep steverep force-pushed the inject-resize-observer branch from 3e24278 to 26ae02b Compare May 24, 2024 04:13
Copy link
Contributor

coderabbitai bot commented May 24, 2024

Walkthrough

Walkthrough

The updates primarily focus on integrating a resize-observer polyfill and removing redundant polyfill loading calls. The custom-polyfill-plugin.js script now includes the resize-observer polyfill, while several components and scripts have been streamlined by eliminating the loadPolyfillIfNeeded function call. This enhances efficiency by centralizing polyfill management and reducing repeated polyfill checks across the codebase.

Changes

File Path Change Summary
build-scripts/babel-plugins/custom-polyfill-plugin.js Added resize-observer polyfill support with browser version targets. Updated polyfillMap to include ResizeObserver with its module path.
build-scripts/bundle.cjs Adjusted plugin injection logic in Babel options to exclude specific polyfills and paths, preventing self-injection.
src/components/map/ha-map.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HaMap class.
src/resources/compatibility.ts Removed import and assignment of ResizeObserver from @lit-labs/virtualizer/polyfills/resize-observer-polyfill/ResizeObserver.
src/resources/polyfills/resize-observer.ts Introduced resize-observer polyfill, assigning it to window.ResizeObserver if not already available.
src/resources/virtualizer.ts Removed loadPolyfillIfNeeded function call from loadVirtualizer function.
src/panels/lovelace/cards/hui-calendar-card.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiCalendarCard class.
src/panels/lovelace/cards/hui-media-control-card.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiMediaControlCard class.
src/panels/lovelace/cards/hui-weather-forecast-card.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiWeatherForecastCard class.
src/panels/lovelace/components/hui-energy-period-selector.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiEnergyPeriodSelector class.
src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiInputNumberEntityRow class.
src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiMediaPlayerEntityRow class.
src/panels/lovelace/entity-rows/hui-number-entity-row.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in HuiNumberEntityRow class.
src/state-summary/state-card-input_number.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in StateCardInputNumber class.
src/state-summary/state-card-number.ts Removed loadPolyfillIfNeeded function call from _attachObserver method in StateCardNumber class.

Tip

New Features and Improvements

Review Settings

Introduced new personality profiles for code reviews. Users can now select between "Chill" and "Assertive" review tones to tailor feedback styles according to their preferences. The "Assertive" profile posts more comments and nitpicks the code more aggressively, while the "Chill" profile is more relaxed and posts fewer comments.

AST-based Instructions

CodeRabbit offers customizing reviews based on the Abstract Syntax Tree (AST) pattern matching. Read more about AST-based instructions in the documentation.

Community-driven AST-based Rules

We are kicking off a community-driven initiative to create and share AST-based rules. Users can now contribute their AST-based rules to detect security vulnerabilities, code smells, and anti-patterns. Please see the ast-grep-essentials repository for more information.

New Static Analysis Tools

We are continually expanding our support for static analysis tools. We have added support for biome, hadolint, and ast-grep. Update the settings in your .coderabbit.yaml file or head over to the settings page to enable or disable the tools you want to use.

Tone Settings

Users can now customize CodeRabbit to review code in the style of their favorite characters or personalities. Here are some of our favorite examples:

  • Mr. T: "You must talk like Mr. T in all your code reviews. I pity the fool who doesn't!"
  • Pirate: "Arr, matey! Ye must talk like a pirate in all yer code reviews. Yarrr!"
  • Snarky: "You must be snarky in all your code reviews. Snark, snark, snark!"

Revamped Settings Page

We have redesigned the settings page for a more intuitive layout, enabling users to find and adjust settings quickly. This change was long overdue; it not only improves the user experience but also allows our development team to add more settings in the future with ease. Going forward, the changes to .coderabbit.yaml will be reflected in the settings page, and vice versa.

Miscellaneous

  • Turn off free summarization: You can switch off free summarization of PRs opened by users not on a paid plan using the enable_free_tier setting.
  • Knowledge-base scope: You can now set the scope of the knowledge base to either the repository (local) or the organization (global) level using the knowledge_base setting. In addition, you can specify Jira project keys and Linear team keys to limit the knowledge base scope for those integrations.
  • High-level summary placement: You can now customize the location of the high-level summary in the PR description using the high_level_summary_placeholder setting (default @coderabbitai summary).
  • Revamped request changes workflow: You can now configure CodeRabbit to auto-approve or request changes on PRs based on the review feedback using the request_changes_workflow setting.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits Files that changed from the base of the PR and between 80c7fd2 and 26ae02b.
Files selected for processing (16)
  • build-scripts/babel-plugins/custom-polyfill-plugin.js (2 hunks)
  • build-scripts/bundle.cjs (1 hunks)
  • src/components/map/ha-map.ts (2 hunks)
  • src/components/media-player/ha-media-player-browse.ts (2 hunks)
  • src/panels/lovelace/cards/hui-calendar-card.ts (2 hunks)
  • src/panels/lovelace/cards/hui-media-control-card.ts (2 hunks)
  • src/panels/lovelace/cards/hui-weather-forecast-card.ts (2 hunks)
  • src/panels/lovelace/components/hui-energy-period-selector.ts (2 hunks)
  • src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts (2 hunks)
  • src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts (2 hunks)
  • src/panels/lovelace/entity-rows/hui-number-entity-row.ts (2 hunks)
  • src/resources/compatibility.ts (1 hunks)
  • src/resources/polyfills/resize-observer.ts (1 hunks)
  • src/resources/virtualizer.ts (1 hunks)
  • src/state-summary/state-card-input_number.ts (2 hunks)
  • src/state-summary/state-card-number.ts (2 hunks)
Additional Context Used
Biome (149)
src/components/map/ha-map.ts (20)

9-9: Do not shadow the global "Map" property.


131-131: Forbidden non-null assertion.


154-154: Forbidden non-null assertion.


176-176: Forbidden non-null assertion.


177-177: Forbidden non-null assertion.


178-178: Forbidden non-null assertion.


185-185: Forbidden non-null assertion.


189-189: Forbidden non-null assertion.


224-228: Prefer for...of instead of forEach.


231-235: Prefer for...of instead of forEach.


231-231: Unexpected any. Specify a different type.


257-257: Prefer for...of instead of forEach.


262-262: Forbidden non-null assertion.


263-265: Prefer for...of instead of forEach.


301-301: Prefer for...of instead of forEach.


312-379: Prefer for...of instead of forEach.


326-326: Forbidden non-null assertion.


326-326: Forbidden non-null assertion.


331-331: Forbidden non-null assertion.


347-347: Forbidden non-null assertion.

src/components/media-player/ha-media-player-browse.ts (12)

204-204: Forbidden non-null assertion.


217-217: Forbidden non-null assertion.


261-261: Do not use template literals if interpolation and special-character handling are not needed.


624-624: Forbidden non-null assertion.


686-686: Forbidden non-null assertion.


720-720: Unexpected any. Specify a different type.


740-740: Unexpected any. Specify a different type.


785-785: Unexpected any. Specify a different type.


849-849: This variable implicitly has the any type.


9-17: Some named imports are only used as types.


32-39: Some named imports are only used as types.


707-707: Reassigning a function parameter is confusing.

src/panels/lovelace/cards/hui-calendar-card.ts (12)

89-89: Forbidden non-null assertion.


136-136: Forbidden non-null assertion.


162-162: Forbidden non-null assertion.


181-181: Forbidden non-null assertion.


191-191: Forbidden non-null assertion.


192-192: Forbidden non-null assertion.


197-197: Forbidden non-null assertion.


204-204: Forbidden non-null assertion.


217-217: Forbidden non-null assertion.


2-9: Some named imports are only used as types.


13-13: All these imports are only used as types.


17-21: Some named imports are only used as types.

src/panels/lovelace/cards/hui-media-control-card.ts (20)

170-170: Template literals are preferred over string concatenation.


243-243: Forbidden non-null assertion.


244-244: Forbidden non-null assertion.


244-244: Forbidden non-null assertion.


280-280: Forbidden non-null assertion.


473-473: Forbidden non-null assertion.


489-489: Forbidden non-null assertion.


499-499: Forbidden non-null assertion.


506-506: Forbidden non-null assertion.


510-510: Forbidden non-null assertion.


519-519: Forbidden non-null assertion.


520-520: Forbidden non-null assertion.


521-521: Forbidden non-null assertion.


529-529: Forbidden non-null assertion.


534-534: Forbidden non-null assertion.


534-534: Forbidden non-null assertion.


538-538: Forbidden non-null assertion.


547-547: Forbidden non-null assertion.


547-547: Forbidden non-null assertion.


549-549: Forbidden non-null assertion.

src/panels/lovelace/cards/hui-weather-forecast-card.ts (20)

85-85: Forbidden non-null assertion.


85-85: Forbidden non-null assertion.


108-108: Forbidden non-null assertion.


109-109: Forbidden non-null assertion.


110-110: Forbidden non-null assertion.


191-191: Forbidden non-null assertion.


192-192: Forbidden non-null assertion.


244-244: Forbidden non-null assertion.


245-245: Forbidden non-null assertion.


302-302: Forbidden non-null assertion.


323-323: Forbidden non-null assertion.


344-344: Forbidden non-null assertion.


345-345: Forbidden non-null assertion.


349-349: Forbidden non-null assertion.


352-352: Forbidden non-null assertion.


361-361: Forbidden non-null assertion.


362-362: Forbidden non-null assertion.


368-368: Forbidden non-null assertion.


369-369: Forbidden non-null assertion.


377-377: Forbidden non-null assertion.

src/panels/lovelace/components/hui-energy-period-selector.ts (17)

293-293: Forbidden non-null assertion.


293-293: Forbidden non-null assertion.


350-350: Forbidden non-null assertion.


350-350: Forbidden non-null assertion.


430-431: Forbidden non-null assertion.


439-440: Forbidden non-null assertion.


451-451: Forbidden non-null assertion.


475-476: Forbidden non-null assertion.


532-533: Forbidden non-null assertion.


541-542: Forbidden non-null assertion.


558-559: Forbidden non-null assertion.


572-573: Forbidden non-null assertion.


588-589: Forbidden non-null assertion.


25-25: All these imports are only used as types.


26-33: Some named imports are only used as types.


56-56: Some named imports are only used as types.


58-58: All these imports are only used as types.

src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts (7)

155-155: Forbidden non-null assertion.


174-174: Forbidden non-null assertion.


174-174: Forbidden non-null assertion.


178-178: Forbidden non-null assertion.


2-9: Some named imports are only used as types.


16-16: All these imports are only used as types.


20-20: All these imports are only used as types.

src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts (20)

147-147: Do not use template literals if interpolation and special-character handling are not needed.


157-157: Do not use template literals if interpolation and special-character handling are not needed.


168-168: Do not use template literals if interpolation and special-character handling are not needed.


320-320: Forbidden non-null assertion.


320-320: Forbidden non-null assertion.


322-322: Forbidden non-null assertion.


326-326: Forbidden non-null assertion.


332-332: Forbidden non-null assertion.


332-332: Forbidden non-null assertion.


341-341: Forbidden non-null assertion.


342-342: Forbidden non-null assertion.


347-347: Forbidden non-null assertion.


348-348: Forbidden non-null assertion.


353-353: Forbidden non-null assertion.


354-354: Forbidden non-null assertion.


359-359: Forbidden non-null assertion.


360-360: Forbidden non-null assertion.


365-365: Forbidden non-null assertion.


366-366: Forbidden non-null assertion.


371-371: Forbidden non-null assertion.

src/panels/lovelace/entity-rows/hui-number-entity-row.ts (8)

161-161: Forbidden non-null assertion.


180-180: Forbidden non-null assertion.


180-180: Forbidden non-null assertion.


183-183: Forbidden non-null assertion.


183-183: Forbidden non-null assertion.


2-9: Some named imports are only used as types.


16-16: All these imports are only used as types.


20-20: All these imports are only used as types.

src/resources/compatibility.ts (4)

7-28: Prefer for...of instead of forEach.


18-23: Prefer for...of instead of forEach.


6-29: This function expression can be turned into an arrow function.


48-48: Reassigning a function parameter is confusing.

src/resources/polyfills/resize-observer.ts (1)

10-10: All exports are only types and should thus use export type.

src/state-summary/state-card-input_number.ts (5)

126-126: Forbidden non-null assertion.


147-147: Forbidden non-null assertion.


2-2: All these imports are only used as types.


3-3: Some named imports are only used as types.


11-11: All these imports are only used as types.

src/state-summary/state-card-number.ts (3)

103-103: Forbidden non-null assertion.


3-3: Some named imports are only used as types.


8-8: All these imports are only used as types.

Path-based Instructions (1)
build-scripts/bundle.cjs (1)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
Additional comments not posted (5)
src/resources/virtualizer.ts (1)

1-3: The changes in loadVirtualizer are clean and straightforward, aligning well with the PR's objectives.

src/resources/polyfills/resize-observer.ts (2)

1-9: The conditional polyfill loading for ResizeObserver is implemented correctly. It ensures the polyfill is only loaded if necessary, which is efficient.


9-9: Change the empty export to export type to clarify that no concrete values are being exported.

- export {};
+ export type {};

Likely invalid or redundant comment.

build-scripts/babel-plugins/custom-polyfill-plugin.js (1)

Line range hint 2-65: The implementation of the custom Babel plugin for polyfill management is well-structured and correctly uses path operations to manage dependencies dynamically.

build-scripts/bundle.cjs (1)

150-166: Ensure correct exclusion of polyfills to prevent self-injection.

The configuration for Babel includes a custom polyfill plugin with specific exclusions to prevent self-injection of polyfills. Verify that these exclusions correctly match the intended directories and modules to ensure that no unnecessary code is included in the build.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (32)
src/resources/compatibility.ts (3)

Line range hint 7-28: Consider using for...of instead of forEach for better performance and readability in polyfill implementations.

- arr.forEach((item) => {
+ for (const item of arr) {

Line range hint 6-29: Convert the function expression to an arrow function for consistency with modern JavaScript practices.

- (function (arr) {
+ ((arr) => {

Line range hint 48-48: Avoid reassigning function parameters as it can lead to confusion. Consider using a different variable.

- force = !!force;
+ const coercedForce = !!force;
src/state-summary/state-card-input_number.ts (2)

Line range hint 126-126: Avoid using non-null assertions. Consider using optional chaining or proper checks before accessing properties.

- this.shadowRoot!.querySelector(".state")
+ this.shadowRoot?.querySelector(".state")

Also applies to: 147-147


Line range hint 2-2: Ensure that imports used only as types are correctly marked with import type.

- import { HassEntity } from "home-assistant-js-websocket";
+ import type { HassEntity } from "home-assistant-js-websocket";

Also applies to: 3-3, 11-11

src/state-summary/state-card-number.ts (2)

Line range hint 103-103: Avoid using non-null assertions. Consider using optional chaining or proper checks before accessing properties.

- this.shadowRoot!.querySelector(".state")
+ this.shadowRoot?.querySelector(".state")

Line range hint 3-3: Ensure that imports used only as types are correctly marked with import type.

- import { HomeAssistant } from "../types";
+ import type { HomeAssistant } from "../types";

Also applies to: 8-8

src/panels/lovelace/entity-rows/hui-input-number-entity-row.ts (3)

Line range hint 155-155: Avoid using non-null assertions without checking for null or undefined.

Consider adding a null check before using the ! operator to ensure that the object is not null or undefined. This will prevent potential runtime errors.


Line range hint 174-174: Avoid repeated non-null assertions.

You've used the non-null assertion operator multiple times on the same line. Ensure that the object is not null or undefined before using it, or refactor the code to perform the check once.

Also applies to: 174-174, 178-178


Line range hint 2-9: Optimize imports by removing unused ones.

You have several imports that are only used as types. These can be imported using import type to make it clear that they are only used for type checking and not included in the JavaScript output.

- import { CSSResultGroup, LitElement, PropertyValues, css, html, nothing } from "lit";
+ import type { CSSResultGroup, LitElement, PropertyValues } from "lit";
+ import { css, html, nothing } from "lit";
- import { customElement, property, state } from "lit/decorators";
+ import type { customElement, property, state } from "lit/decorators";
- import { HomeAssistant } from "../../../types";
+ import type { HomeAssistant } from "../../../types";

Also applies to: 16-16, 20-20

src/panels/lovelace/entity-rows/hui-number-entity-row.ts (3)

Line range hint 161-161: Avoid using non-null assertions without checking for null or undefined.

Consider adding a null check before using the ! operator to ensure that the object is not null or undefined. This will prevent potential runtime errors.


Line range hint 180-180: Avoid repeated non-null assertions.

You've used the non-null assertion operator multiple times on the same line. Ensure that the object is not null or undefined before using it, or refactor the code to perform the check once.

Also applies to: 180-180, 183-183, 183-183


Line range hint 2-9: Optimize imports by removing unused ones.

You have several imports that are only used as types. These can be imported using import type to make it clear that they are only used for type checking and not included in the JavaScript output.

- import { CSSResultGroup, LitElement, PropertyValues, css, html, nothing } from "lit";
+ import type { CSSResultGroup, LitElement, PropertyValues } from "lit";
+ import { css, html, nothing } from "lit";
- import { customElement, property, state } from "lit/decorators";
+ import type { customElement, property, state } from "lit/decorators";
- import { HomeAssistant } from "../../../types";
+ import type { HomeAssistant } from "../../../types";

Also applies to: 16-16, 20-20

src/panels/lovelace/cards/hui-calendar-card.ts (2)

Line range hint 89-89: Avoid using non-null assertions without checking for null or undefined.

Multiple lines in your code use the non-null assertion operator without prior null checks. This can lead to runtime errors if the objects are actually null or undefined. Consider adding appropriate checks or handling potential null values gracefully.

Also applies to: 136-136, 162-162, 181-181, 191-191, 192-192, 197-197, 204-204, 217-217


Line range hint 2-9: Optimize imports by removing unused ones.

Several imports in your file are only used for type checking. You can optimize these imports by using import type, which will not include them in the JavaScript output, reducing the bundle size.

- import { css, CSSResultGroup, html, LitElement, PropertyValues, nothing } from "lit";
+ import type { CSSResultGroup, LitElement, PropertyValues } from "lit";
+ import { css, html, nothing } from "lit";
- import { customElement, property, state } from "lit/decorators";
+ import type { customElement, property, state } from "lit/decorators";
- import type { HomeAssistant } from "../../../types";
+ import { HomeAssistant } from "../../../types";
- import { Calendar, CalendarEvent, fetchCalendarEvents } from "../../../data/calendar";
+ import type { Calendar, CalendarEvent } from "../../../data/calendar";
+ import { fetchCalendarEvents } from "../../../data/calendar";

Also applies to: 13-13, 17-21

src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts (2)

Line range hint 147-147: Avoid unnecessary template literals.

You have used template literals in several places where simple strings would suffice. This is unnecessary and can be simplified.

- .label=${this.hass.localize(`ui.card.media_player.media_play`)}
+ .label=${this.hass.localize("ui.card.media_player.media_play")}
- .label=${this.hass.localize(`ui.card.media_player.media_pause`)}
+ .label=${this.hass.localize("ui.card.media_player.media_pause")}
- .label=${this.hass.localize(`ui.card.media_player.media_stop`)}
+ .label=${this.hass.localize("ui.card.media_player.media_stop")}

Also applies to: 157-157, 168-168


Line range hint 320-320: Avoid using non-null assertions without checking for null or undefined.

Multiple lines in your code use the non-null assertion operator without prior null checks. This can lead to runtime errors if the objects are actually null or undefined. Consider adding appropriate checks or handling potential null values gracefully.

Also applies to: 320-320, 322-322, 326-326, 332-332, 332-332, 341-341, 342-342, 347-347, 348-348, 353-353, 354-354, 359-359, 360-360, 365-365, 366-366, 371-371

src/components/map/ha-map.ts (5)

Line range hint 9-9: Consider renaming the Map type from leaflet to avoid shadowing the global Map object.

- import type { Map } from "leaflet";
+ import type { Map as LeafletMap } from "leaflet";

Line range hint 131-131: Avoid using non-null assertions without checking for null or undefined.

- this.leafletMap!.setZoom(this.zoom);
+ if (this.leafletMap) {
+   this.leafletMap.setZoom(this.zoom);
+ }

Also applies to: 154-154, 176-176, 177-177, 178-178, 185-185, 189-189


Line range hint 224-228: Consider using for...of loops instead of forEach for better readability and potential performance benefits.

- this._mapItems.forEach((marker) => marker.remove());
+ for (const marker of this._mapItems) {
+   marker.remove();
+ }

Also applies to: 231-235, 257-257, 263-265, 301-301, 312-379


Line range hint 231-231: Specify a more precise type instead of any.

- this.layers?.forEach((layer: any) => {
+ this.layers?.forEach((layer: Layer) => {

Line range hint 262-262: Ensure elements are not null before accessing them to avoid runtime errors.

- const map = this.renderRoot.querySelector("#map");
+ const map = this.renderRoot.querySelector("#map");
+ if (!map) return;

Also applies to: 326-326, 331-331, 347-347

src/panels/lovelace/components/hui-energy-period-selector.ts (2)

Line range hint 25-25: Optimize imports by marking type-only imports explicitly.

- import type { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
- import type { UnsubscribeFunc } from "home-assistant-js-websocket";
- import type { DateRangePickerRanges } from "../../../components/ha-date-range-picker";
- import type { EnergyData, getEnergyDataCollection } from "../../../data/energy";
+ import { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
+ import { UnsubscribeFunc } from "home-assistant-js-websocket";
+ import { DateRangePickerRanges } from "../../../components/ha-date-range-picker";
+ import { EnergyData, getEnergyDataCollection } from "../../../data/energy";

Also applies to: 26-33, 56-56, 58-58


Line range hint 293-293: Avoid non-null assertions to ensure robust error handling.

Consider adding null checks or using optional chaining (?.) to handle potential null or undefined values safely.

Also applies to: 350-350, 430-431, 439-440, 451-451, 475-476, 532-533, 541-542, 558-559, 572-573, 588-589

src/panels/lovelace/cards/hui-weather-forecast-card.ts (1)

Line range hint 85-85: Avoid non-null assertions to ensure robust error handling.

Consider adding null checks or using optional chaining (?.) to handle potential null or undefined values safely.

Also applies to: 108-108, 109-109, 110-110, 191-191, 192-192, 244-244, 245-245, 302-302, 323-323, 344-344, 345-345, 349-349, 352-352, 361-361, 362-362, 368-368, 369-369, 377-377

src/panels/lovelace/cards/hui-media-control-card.ts (2)

Line range hint 170-170: Prefer template literals over string concatenation for better readability and maintainability.

- "background-image": `linear-gradient(to right, ${this._backgroundColor}, ${this._backgroundColor + "00"})`,
+ "background-image": `linear-gradient(to right, ${this._backgroundColor}, ${this._backgroundColor}00)`,

Line range hint 243-243: Consider verifying object existence before usage to avoid potential runtime errors from non-null assertions.

- this._config!.entity
+ this._config?.entity ?? throw new Error("Configuration is undefined.")

Apply similar checks for other non-null assertions throughout the file.

Also applies to: 244-244, 280-280, 473-473, 489-489, 499-499, 506-506, 510-510, 519-519, 520-520, 521-521, 529-529, 534-534, 538-538, 547-547, 549-549

src/components/media-player/ha-media-player-browse.ts (5)

Line range hint 9-17: Consider removing unused type imports to clean up the code.

- import type { LitVirtualizer } from "@lit-labs/virtualizer";
- import type { MediaPlayerItem } from "../../data/media-player";
- import type { HomeAssistant } from "../../types";

These imports are only used for type annotations and can be safely removed if they are not used elsewhere in the code.

Also applies to: 32-39


Line range hint 204-204: Avoid using non-null assertions unless absolutely necessary.

Using non-null assertions (!) bypasses TypeScript's strict null checks, which can lead to runtime errors if the assumptions about non-nullability are incorrect. Consider adding proper checks or handling potential null values gracefully.

Also applies to: 217-217, 624-624, 686-686


Line range hint 261-261: Use simple strings instead of template literals when not needed.

- backgroundImage = `none`;
+ backgroundImage = "none";

Template literals are unnecessary here since there is no dynamic content being interpolated.


Line range hint 707-707: Avoid reassigning parameters as it can lead to confusing behaviors.

- const item = (ev.currentTarget as any).item;
+ const { item } = ev.currentTarget as any;

This change avoids direct reassignment and makes the code cleaner by using destructuring.


Line range hint 720-720: Specify explicit types instead of using any.

Using any type defeats the purpose of TypeScript's static typing. It's better to specify explicit types for better type safety and code clarity.

- const item = (ev.currentTarget as any).item;
+ const item = (ev.currentTarget as HTMLElement & { item: MediaPlayerItem }).item;

Adjust the type annotations to reflect the actual expected types.

Also applies to: 740-740, 785-785, 849-849

@silamon
Copy link
Contributor

silamon commented May 24, 2024

Visually no differences on legacy build with polyfill. It just needs the open question to be addressed to merge.

@steverep
Copy link
Member Author

Actually, thinking about it more, it would not make sense to limit where the polyfill gets injected. Since The polyfill sets a global object, that would lead to inconsistent usage depending on how things are bundled or which pages the user decides to visit.

@steverep steverep merged commit 41e34c0 into dev May 24, 2024
13 checks passed
@steverep steverep deleted the inject-resize-observer branch May 24, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Related to building the code cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants