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: font size syncing #142

Merged
merged 2 commits into from
Nov 24, 2021
Merged

fix: font size syncing #142

merged 2 commits into from
Nov 24, 2021

Conversation

devpow112
Copy link
Contributor

We are grabbing the font size from the body element but setting it on the root document element. This means if the body in the FRA has d2l-typography applied then the font size is double scaled down (the root document font size was around 17.1px, since the LMS side root is 20px but the body has d2l-typography so the body computed size if 17.1px)

We are grabbing the font size from the body element but setting it on the root
document element. This means if the body in the FRA has `d2l-typography` applied
then the font size is double scaled down.
@devpow112
Copy link
Contributor Author

devpow112 commented Nov 24, 2021

I'm a bit concerned about keeping backwards compatibility with this. I could detect if the body in the FRA has d2l-typography applied and if not just set the root as before so it's scaled down. If the FRA body has d2l-typography then set the root to the new sizeRoot and just don't use size to stop the double scaling down of font size. Let me know what you think. This came up when looking at some other stuff in portfolio (folio-app).

@grant-cleary
Copy link
Contributor

I'm a bit concerned about keeping backwards compatibility with this. I could detect if the body in the FRA has d2l-typography applied and if not just set the root as before so it's scaled down. If the FRA body has d2l-typography then set the root to the new sizeRoot and just don't use size to stop the double scaling down of font size. Let me know what you think. This came up when looking at some other stuff in portfolio (folio-app).

I feel like this should be reasonably safe? FRAs would need to update their clients to get the new client-side behaviour, while it still looks like the client should be backwards-compatible - i.e. The host is providing a new-new property that older clients just won't know about.

@devpow112
Copy link
Contributor Author

devpow112 commented Nov 24, 2021

I'm a bit concerned about keeping backwards compatibility with this. I could detect if the body in the FRA has d2l-typography applied and if not just set the root as before so it's scaled down. If the FRA body has d2l-typography then set the root to the new sizeRoot and just don't use size to stop the double scaling down of font size. Let me know what you think. This came up when looking at some other stuff in portfolio (folio-app).

I feel like this should be reasonably safe? FRAs would need to update their clients to get the new client-side behaviour, while it still looks like the client should be backwards-compatible - i.e. The host is providing a new-new property that older clients just won't know about.

@grant-cleary I'm more concerned that people are relying on the font size being smaller then it should be in current FRA's (root html font size being 17.1px vs 20px). This current change will mean that font sizes will "get bigger" if d2l-typography isn't applied to the FRA's body class. Could cause stylistic changes that aren't desired. Although that would only happen if they update the ifrau client in their FRA.

@devpow112
Copy link
Contributor Author

FYI, @jameswklassen.

@@ -1,5 +1,5 @@
export function clientSyncFont(client) {
return client.request('font').then(font => {
document.documentElement.style.fontSize = font.size;
document.documentElement.style.fontSize = font.sizeRoot ?? font.size;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kinda thinking this might want to be

if (document.body.classList.contains('d2l-typography')) {
  document.documentElement.style.fontSize = font.sizeRoot ?? font.size;
} else {
  document.documentElement.style.fontSize = font.size;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@grant-cleary I'm more concerned that people are relying on the font size being smaller then it should be in current FRA's (root html font size being 17.1px vs 20px). This current change will mean that font sizes will "get bigger" if d2l-typography isn't applied to the FRA's body class. Could cause stylistic changes that aren't desired. Although that would only happen if they update the ifrau client in their FRA.

Ah, fair. Yeah, I'm always a bit less concerned when teams need to make a conscious choice to upgrade, as (hopefully) they would look at the changes to figure out whether this would impact them. But you're right that in that case this would be an impactful change, so I'm also not at all opposed to your proposed solution of checking specifically for d2l-typography as a safeguard.

@@ -1,10 +1,13 @@
export function hostSyncFont(host) {
host.onRequest('font', () => {
const computedStyle = window.getComputedStyle(document.body);
Copy link
Member

Choose a reason for hiding this comment

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

To me, this seems like the bug right here? Like in our LMS pages, we output this:

html {
    font-size: 20px;
}

And that value changes when the user changes their font size preference in account settings. So could we just always grab it from the root and always set it on the root and ignore the body completely?

Copy link

@jameswklassen jameswklassen Nov 24, 2021

Choose a reason for hiding this comment

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

Yeah, this is what started the font syncing discussion. In Portfolio we want to reflect the font size preference inside our iFrame.

We weren't sure if others depend on the current behaviour (getting computed style from <body> rather than <html>).

If it makes sense that the style comes right from <html> (and it doesn't break existing usage), then it might be cleanest to always get the computed style from the root

const computedStyle = window.getComputedStyle(document.documentElement);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm ok with treating this as a bug. I'm less worried after thinking about the fact that teams have to upgrade to get the new version of ifrau anyways and would hopefully test and see the difference. I can make the adjust to just grab the html font size and not introduce the new sizeRoot stuff if that works for everyone.

family: computedStyle.fontFamily,
size: computedStyle.fontSize,
visualRedesign: visualRedesign
family: bodyComputedStyle.fontFamily,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still using body to grab the font family. Isn't used but have it for compatibility.

@devpow112 devpow112 merged commit e664489 into master Nov 24, 2021
@devpow112 devpow112 deleted the depowell/fix-font-size-syncing branch November 24, 2021 18:23
@ghost
Copy link

ghost commented Nov 24, 2021

🎉 This PR is included in version 0.39.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants