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

Add workaround for font-optical-sizing issue in Safari 16 #11503

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-colts-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Added workaround for `font-optical-sizing` issue in Safari 16
6 changes: 6 additions & 0 deletions polaris-react/src/components/AppProvider/AppProvider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ button::-moz-focus-inner,
[type='submit']::-moz-focus-inner {
border-style: none;
}

// stylelint-disable-next-line selector-no-qualifying-type -- Workaround for `font-optical-sizing` issue in Safari 16 (Adapted from https://clagnut.com/blog/2423)
html[class~='Polaris-Safari-16-Font-Optical-Sizing-Patch'] {
// Inter's "opsz" axis ranges from 14 to 32. This patch optimizes for smaller and less legible text by setting "opsz" 14 for all font sizes.
font-variation-settings: 'opsz' 14;
}
13 changes: 13 additions & 0 deletions polaris-react/src/components/AppProvider/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ export class AppProvider extends Component<AppProviderProps, State> {
this.stickyManager.setContainer(document);
this.setBodyStyles();
this.setRootAttributes();

const isSafari16 =
navigator.userAgent.includes('Safari') &&
!navigator.userAgent.includes('Chrome') &&
(navigator.userAgent.includes('Version/16.1') ||
Copy link
Member

Choose a reason for hiding this comment

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

Is there not a v16.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue started in v16.1

navigator.userAgent.includes('Version/16.2') ||
navigator.userAgent.includes('Version/16.3'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Assume this is fixed in Safari 16.4 and above? If so, this is fine with me for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, to my understanding 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Reference links:

Blog post

Update: as of Safari 16.4, this bug has been fixed.

WebKit PR

also means we are going
fast enough that we can enable optical sizing on every font - because doing so is just an
attribute in a dictionary, rather than creating a whole new CTFont. That is the fix for this
bug: enabling optical sizing on all fonts.


if (isSafari16) {
document.documentElement.classList.add(
'Polaris-Safari-16-Font-Optical-Sizing-Patch',
);
}
}
measureScrollbars();
}
Expand Down
Loading