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

Use modern build for ipad os 15 and macos 11 #21695

Closed
wants to merge 1 commit into from

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Aug 14, 2024

Proposed change

Following #16506

Partially fixes home-assistant/iOS#2908

The user agent from the iPadOS app or macOS app doesn't contain Safari version so it's ignored by browserlist.

As the app adds the os version in the user agent, I wrote a additional regex to have support for modern build for iPadOS >= 15 and macOS >= 11 (because they use Safari 16.6 engine).

@steverep Let me know if it's ok for you

Example of user agent from the app :

  • Mac OS app : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Home Assistant/2024.7 (io.robbie.HomeAssistant; build:2024.730; macOS 14.5.0) Mobile/HomeAssistant, like Safari
  • iPadOS app : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Home Assistant/2024.7 (io.robbie.HomeAssistant; build:2024.730; iPadOS 17.5.1) Mobile/HomeAssistant, like Safari

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:

Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

Walkthrough

The recent changes to the entry-html.js file enhance user agent detection capabilities, specifically for iPadOS and macOS. By introducing a new regex for these operating systems, the modifications aim to improve the rendering process for devices running these systems, ensuring compatibility and a consistent user experience across platforms.

Changes

Files Change Summary
build-scripts/gulp/entry-html.js Introduced a new regex for iPadOS and macOS. Modified renderTemplate function to utilize this regex for improved user agent detection and rendering accuracy.

Assessment against linked issues

Objective Addressed Explanation
Rendering consistency in iPadOS (iOS companion app) (Issue #2908)
Improved user agent handling for better compatibility (Issue #2908)

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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.

@github-actions github-actions bot added the Build Related to building the code label Aug 14, 2024
@bgoncal
Copy link
Member

bgoncal commented Aug 14, 2024

iPadOS >= 15 right?

@@ -10,20 +10,29 @@ import { htmlMinifierOptions, terserOptions } from "../bundle.cjs";
import env from "../env.cjs";
import paths from "../paths.cjs";

// Regex to match iPadOS >= 15 and macOS >= 11 (app web view) because browserlist is not capable of this
const ipadMacOSRegex =
/\b(iPadOS\s*(1[5-9]|[2-9]\d)(?:\.\d+)?(?:\.\d+)?)|(macOS\s*(1[1-9]|[2-9]\d)(?:\.\d+)?(?:\.\d+)?)\b/;
Copy link
Member

Choose a reason for hiding this comment

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

We cannot hard code the versions because they can change with time and/or usage stats. I'm looking into the best solution here.

Copy link
Member Author

Choose a reason for hiding this comment

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

May be we should also put Safari 16 in browserlist file to have the same target in browserlist. I agree it's not perfect but I didn't find another solution 😢

Let's me know if you find something better!

Copy link
Member

Choose a reason for hiding this comment

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

I've put in many hours researching this now, and the only solid conclusion I've got is that Apple needs to do better. 😞

For iPad, I think home-assistant/iOS#2918 is the best solution (and looks like @bgoncal just merged it as I'm typing so 🥳). There's no reason we need to allow the app to spoof the user agent to pretend it's a Mac because it won't affect the frontend result at all. So the current regex will work now for iPad at least.

For the Mac app, that's a complete mess. I had a discussion with @bgoncal and continued to research, and the only version provided by Apple's API is the OS version (i.e. there's no way to query what WebKit or Safari version gets used by the web view). And it's not provided in the default user agent string either. So the only choice is to map it ourselves. The only question for me becomes: should the MacOS version map to the Safari version it's shipped with, or the latest version it supports? Based on my research, I think the former is correct, but I'm not 100% sure on that.

I started looking into how to automate this similar to the way browserslist-useragent-regexp works, and I think I could probably throw that together without too much trouble. It's late here now so I'll do that tomorrow.

Regarding putting more Safari versions in the browserslist config, I agree. Currently, modern is served to iOS 15.6+ and Safari 17+, which doesn't make much sense from a transpilation/polyfilling perspective. That's just reflecting that iPhones are way more popular than Macs. We can hard code a sync for now and maybe I'll do another PR to browserslist for a nicer solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree! Thank you for the research! 🙂
That was more or less my conclusion too.

Copy link
Member

Choose a reason for hiding this comment

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

Opened browserslist/browserslist#838. I'll work on the change for Mac in a bit.

@steverep
Copy link
Member

Closing in favor of #21724 (and since it's already fixed for iPad via home-assistant/iOS#2918)

@steverep steverep closed this Aug 17, 2024
@steverep steverep deleted the modern-build-ipad-os-mac-os branch August 17, 2024 19:14
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.

iPadOS Card rendering issue since HA 2024.8.0
3 participants