-
Notifications
You must be signed in to change notification settings - Fork 2k
Consolidate client user agent parsing #103048
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
base: trunk
Are you sure you want to change the base?
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~391 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~13002 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~4392 bytes removed 📉 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3,7 +3,7 @@ import clsx from 'clsx'; | |||
import { useTranslate } from 'i18n-calypso'; | |||
import { useRef } from 'react'; | |||
import { connect } from 'react-redux'; | |||
import userAgent from 'calypso/lib/user-agent'; | |||
import { isMobile } from 'calypso/lib/user-agent'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this will require separate testing and deploying of the notifications app.
See PCYsg-elI-p2 and PCYsg-OT6-p2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this will require separate testing and deploying of the notifications app.
@tyxla It's not entirely clear to me from those resources: Is it on me to see through the deployment of that application with these changes, or will it be included in some regular future deployment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, if you merge a change that touches a specific app, you should also smoke test and deploy that app. That's something that's often overlooked, as we don't currently have a mechanism to nudge or force people to do it.
client/lib/user-agent/get-os-name.ts
Outdated
@@ -0,0 +1,6 @@ | |||
import { once } from 'lodash'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above wrt lodash
.
jest.mock( '../get-os-name', () => jest.fn() ); | ||
jest.mock( '../get-device-type', () => jest.fn() ); | ||
|
||
describe( 'user-agent', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thorough tests!
@@ -25,7 +25,7 @@ export function useIsBigSkyEligible( flowName?: string ) { | |||
const { isOwner } = useIsSiteOwner(); | |||
const site = useSite(); | |||
const product_slug = site?.plan?.product_slug || ''; | |||
const onSupportedDevice = userAgent.isTablet || userAgent.isDesktop; | |||
const onSupportedDevice = isTablet() || isDesktop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our life would be easier if isDesktop
didn't exist: because ua-parser-js
doesn't support it. For good reasons, the UA string never really says that it's coming from a desktop device.
Looking at #95965 and guessing @dereksmart's intent back then, it seems that ! isMobile()
is the right check we want to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the reasons for the isMobile
check in #95965:
The UX can now handle narrow viewports, but the mobile keyboard still gets in the way.
it seems that we want to decide according the screen size and avoid screens that are too narrow. For that, we have isMobile
check from @automattic/viewport
:
import { isMobile } from '@automattic/viewport';
This is used at many places in the Calypso codebase, and the check is based on screen width: <480px
is considered mobile. In this case that's a better fit than a UA check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use the isMobile
viewport helper in b8d8dd5.
Separately, I wonder if it would be clearer to distinguish the name of these, e.g. isMobileViewport
and/or isMobileUserAgent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separately, I wonder if it would be clearer to distinguish the name of these, e.g.
isMobileViewport
and/orisMobileUserAgent
.
Although I think "mobile viewport" could be a misnomer to begin with, and we should probably refer to viewports as sizes (small, medium, large, etc.).
I see this is handled a bit better with the useViewportMatch
hook in @wordpress/compose
.
See: https://github.com/Automattic/wp-calypso/pull/103048/files#r2071536519 isMobile() && ! isOS() should not infer that it's Android
Related to #103023 (in turn, #102984 (comment))
Proposed Changes
ua-parser-js
)Why are these changes being made?
Testing Instructions
Verify that relevant components using parsed user agent details continue to behave as expected.
Verify that newly-added tests pass:
yarn test-client client/lib/user-agent/test
Pre-merge Checklist