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

Fix issues with retina devices #6630

Closed
wants to merge 5 commits into from
Closed

Conversation

wordpressfan
Copy link
Contributor

Description

Fixes #6628

Documentation

User documentation

Explain how this code impacts users.

Technical documentation

Explain how this code works. Diagram & drawings are welcomed.

Type of change

Delete options that are not relevant.

  • New feature (non-breaking change which adds functionality).
  • Bug fix (non-breaking change which fixes an issue).
  • Enhancement (non-breaking change which improves an existing functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as before).

New dependencies

List any new dependencies that are required for this change.

Risks

List possible performance & security issues or risks, and explain how they have been mitigated.

Checklists

Feature validation

  • I validated all the Acceptance Criteria. If possible, provide sreenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Documentation

  • I prepared the user documentation for the feature/enhancement and shared it in the PR or the GitHub issue.
  • The user documentation covers new/changed entry points (endpoints, WP hooks, configuration files, ...).
  • I prepared the technical documentation if needed, and shared it in the PR or the GitHub issue.

Code style

  • I wrote self-explanatory code about what it does.
  • I wrote comments to explain why it does it.
  • I named variables and functions explicitely.
  • I protected entry points against unexpected inputs.
  • I did not introduce unecessary complexity.
  • I listed the introduced external dependencies explicitely on the PR.
  • I validated the repo-specific guidelines from CONTRIBUTING.md.

Observability

  • I handled errors when needed.
  •  I wrote user-facing messages that are understandable and provide actionable feedbacks.
  • I prepared ways to observe the implemented system (logs, data, etc.).

Risks

  •  I explicitely mentioned performance risks in the PR.
  • I explicitely mentioned security risks in the PR.

@wordpressfan wordpressfan self-assigned this May 13, 2024
Copy link

codacy-production bot commented May 13, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for c7a71491 (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c7a7149) Report Missing Report Missing Report Missing
Head commit (b7f76d3) 37183 14401 38.73%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6630) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@Mai-Saad
Copy link

Mai-Saad commented May 14, 2024

@wordpressfan Thanks for the PR, Can see the manual visit of mobile /desktop is added to atf now. however, during exploratory test, warmup after clear critical images is adding only the mobile version to ATF, is this something we will handle here? @piotrbak
with trunk
Screenshot from 2024-05-14 11-20-33
with PR
Screenshot from 2024-05-14 11-19-19

@piotrbak
Copy link
Contributor

@Mai-Saad Could you check if visits from the saas are being made to the desktop? If so, it means that the PR brings regression

@Mai-Saad
Copy link

@piotrbak While RUCSS is on, on trunk we are adding both desktop/mobile to ATF while on PR only mobile

@MathieuLamiot
Copy link
Contributor

@wordpressfan I see in your latest version that you are using screen.width rather than innerWidth and pixel ratio. Can you elaborate on why?
I am afraid this will cause issues:

  • with SaaS, we control the display size, not the screen size. Hence, probably why we have the regression spotted by @Mai-Saad.
  • with human visits, screen.width will return the size of the actual physical screen I believe. If the viewport is smaller (window is made smaller by the user, or there are many toolbars at the top of the browser for instance), the website might display smaller but we would still account for the full screensize.

Should we try with the earlier version?
return ( window.innerWidth || document.documentElement.clientWidth ) / ( window.devicePixelRatio || 1 );

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented May 14, 2024

EDIT: very quick test with commit c35559c seems working.

  • SaaS visits trigger a row in DB with Mobile & Desktop
  • Manual visit with a mobile trigger a row in the DB as well

@wordpressfan can you elaborate on cases that did not work with devicePixelRatio?

Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for c7a71491 (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c7a7149) Report Missing Report Missing Report Missing
Head commit (f4887d0) 37183 14401 38.73%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#6630) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@wordpressfan
Copy link
Contributor Author

Yes it was working in some cases, but with me it wasn't properly working because of the threshold wasn't valid in this case, for example when u visit from Iphone SE with width 375px and height 667px, with the new code:

window.devicePixelRatio = 2
window.innerWidth = 375
New final width = 187.5

and this is out of our threshold, so I think we may need to think again about threshold values.

You can use the dev tools mobile view to check that.

I reverted the code back to this commit.

@Mai-Saad
Copy link

Mai-Saad commented May 14, 2024

Can confirm that saas visits are working now as on trunk. while manual mobile visits still not working for some like iPhone SE @wordpressfan mentioned above while for Samsung Galaxy S8+ it's working and adding to DB

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented May 14, 2024

I think there is a misunderstansing here.
innerWidth returns CSS pixels. The devicePixelRatio can be used to go from CSS pixels to Physical pixels.

So for Iphone SE, there are 375 CSS pixels and 750 physical pixels.

The formula might be inverted?

That being said I would advise not.to apply the threshold on the physical resolution butnon the CSS one. @piotrbak @DahmaniAdame
Maybe we should just keep innerWidth and adjust thresholds?

Do we have the values for the failing cases originally reported by Mai?

@wordpressfan
Copy link
Contributor Author

@MathieuLamiot u mean use multiply by not divided by, correct?

I played with this also but Yes we may need to change the threshold also.

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented May 14, 2024

Here are the details for a Samsung Galaxy s8+ as mentioned by @Mai-Saad
The CSS resolution should be OK with our threshold. We should be getting 360 and a bit less than 740 as values to compare with the thresholds
https://www.webmobilefirst.com/en/devices/samsung-galaxy-s8-plus/

@MathieuLamiot
Copy link
Contributor

@wordpressfan @Mai-Saad
To know exactly what to do, we need to pick a phone model, get its online specs (CSS pixel and screen size) from the website I shared above for instance.
Then, check the returned value for this model in innerWidth.

Based on this, we'll know what to do

@wordpressfan
Copy link
Contributor Author

all sizes are available in dev tools:

Screenshot from 2024-05-14 13-23-30

We only need to know which ones we need to support and which we don't, because even with the old code because of the threshold, we ignore some devices like ipad which is a mobile but sizes are like the desktop.

@Khadreal
Copy link
Contributor

@wordpressfan @Mai-Saad To know exactly what to do, we need to pick a phone model, get its online specs (CSS pixel and screen size) from the website I shared above for instance. Then, check the returned value for this model in innerWidth.

Based on this, we'll know what to do

Are there device size that we shouldn't be bothered with or we need to support all device size ?

@MathieuLamiot
Copy link
Contributor

The specification is always the same: for mobile devices, anything bigger than 393x830 must be discarded.
It means a Samsung Galaxy s8+ of 360x740 must be accepted. the issue reported by Mai is that it is not accepted according to her test. However, I can't reproduce. I'm started to think the develop branch is already correct 🤔
I'll try on e2e @Mai-Saad

Enregistrement de l’écran 2024-05-14 à 12.34.42

@Mai-Saad
Copy link

@MathieuLamiot on trunk both Samsung Galaxy s8+ and iPhone SE are not added to the database. on PR, Samsung Galaxy s8+ is working while iPhone SE is not. (theoretically any mobile dimensions <= 393x830 shall work as per our test cases)

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented May 14, 2024

Ok, I managed to reproduce and this is much more tricky, but does not seem related to the script.

Using dev tools to fake a Galaxy S8+, the innerHeight returned is not the same depending on the page!

http://mathieu.e2e.rocketlabsqa.ovh/lcp_bg_samestyle_template/ I get 2015, so the physical pixel size. Which is rejected by the script.

http://mathieu.e2e.rocketlabsqa.ovh/ I get 740, the expected value.

Enregistrement.de.l.ecran.2024-05-14.a.12.44.13.mov

This happens even without WP Rocket installed.

@MathieuLamiot
Copy link
Contributor

This seem to happen on our templates. I can't reproduce on my personal website. I am wondering if the template loader plugin could be the cause of this as we interefere with the template_include hook

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented May 14, 2024

I think I got it. When loading most WordPress sites, I can see this in the :
<meta name="viewport" content="width=device-width, initial-scale=1.0">

But this is not in the templates we use for e2e website. I guess it is added by WordPress in its default templates, maybe as part of wp_head action? If I manually add it to our templates, everything works as expected.

@MathieuLamiot
Copy link
Contributor

Closing the PR for now as we don't want to change anything compared to the current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mobile manual visit isnot added to ATF table when meta viewport header is missing
5 participants