Open Bug 1831949 Opened 3 years ago Updated 1 year ago

Evite invitations sometimes render with the wrong font or linewrapping (due to evite assuming document.fonts.values() is iterable, and it's not in Firefox)

Categories

(Web Compatibility :: Site Reports, defect, P3)

Tracking

(Webcompat Priority:P3, Webcompat Score:3)

Webcompat Priority P3
Webcompat Score 3

People

(Reporter: dholbert, Unassigned)

References

(Depends on 1 open bug, )

Details

(Keywords: webcompat:needs-contact, webcompat:platform-bug, webcompat:site-report)

User Story

platform:windows,mac,linux,android
impact:significant-visual
configuration:general
affects:all
user-impact-score:40

Attachments

(5 files)

STR:

  1. Load http://evite.me/5pDuxKK7Sq

EXPECTED RESULTS:
The "Please join us" text should all be on one line and should render with a hand-drawn-looking font.

ACTUAL RESULTS:

  • Sometimes that text renders with the wrong font (with substantially larger characters), with "us!" on its own line.
  • Sometimes the text renders with the correct font but with "us!" at precisely that same lower position.

This text is actually a data URI transparent PNG, presumably rendered via a canvas in the background during pageload.

Essentially: it seems likely that there's a race condition (maybe on evite's side) where they probably:
(a) set the font
(b) measure the text to decide on a layout
(c) render strings of text at the positions using the layout that they decided on.

If the font doesn't load by the time we get to (c), then we get the rendering with the entirely wrong font.
If the font loads between (b) and (c), then we get the rendering with the correct font but with the last word laid out on its own line.

(Note: in this screenshot and the previous one, the smaller text at the bottom also had a change in linewrapping -- the first line of the black text, "In a real evite, this would be the date/time info" line of text has a linewrap before "info", whereas in the "expected rendering" that I screenshotted, it didn't have a linewrap there.)

All of these screenshots were taken in Firefox Nightly 114.0a1 (2023-05-07) on linux. I've also confirmed it affects Firefox 112 release on Linux. And I've tested & reproduced in Nightly 114 on macOS (locally) and Firefox 112 release channel on Win10 via BrowserStack. So: all platforms are affected, and this isn't a regression on our end (at least not with respect to release 112).

Chrome reliably produces the expected rendering; I've never once hit this issue there after loading this evite a bunch of times.

Firefox usually produces one of the broken renderings. I've noticed it's often fixed after a reload, but often broken after a cache-skipping "ctrl+shift+r" reload.

I also tried reloading in safari a bunch (in some cases with "Disable Caches" ticked in devtools which emulates ctrl+shift+r there I think) and I haven't been able to repro the issue there at all.

So to the extent that there's a site bug here, it seems to be one that's easy to hit in Firefox vs. hard-or-impossible to hit in other browsers (for me so far).

FWIW in the "Edit Design" UI for this card, it shows the Text Style as Looking Flowers Caps and the Text Size as 120pt. (It's listed near the bottom of their Text Style dropdown-menu, 5th from the end -- its characters are very small so it's hard to read the title there if you don't know what you're looking for / where to look for it).

This is the font info from our font inspector (in the "All fonts on page" listing):

looking-flowers-caps
Looking Flowers Caps
@font-face {
  font-family: "looking-flowers-caps";
  src:
url("https://use.typekit.net/af/d6306b/00000000000000007735b630/30/l?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3")
    format("woff2"),
url("https://use.typekit.net/af/d6306b/00000000000000007735b630/30/d?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3")
    format("woff"),
url("https://use.typekit.net/af/d6306b/00000000000000007735b630/30/a?primer=7cdcb44be4a7db8877ffa5c0007b8dd865b3bbc383831fe2ea177f62257a9191&fvd=n4&v=3")
    format("opentype");

  font-style: normal;
  font-weight: 400;
  font-stretch: normal;
  font-display: auto;
}

This evite also reproduces the same bug with a different font/design: http://evite.me/jKdcvrhpGm

In this case the font is "Sen Extra Bold", in this case served by Google Fonts (according to our font devtools).

So I suspect this might be possible repro with ~any webfont that evite has available. It's just particularly noticeable when the chosen font/text are "just right" such that the text fits on one line using the chosen font, and the text does not fit when using whatever font gets used as a fallback.

(The "Looking Flowers Caps" font from my original testcase is just particularly good at satisfying those conditions, since its glyphs are much smaller than other fonts, for a given font-size, e.g. this particular evite design's default 120pt size).

Here's the same triplet of possible-renderings, but now for the new evite that I just linked.

(Expected rendering vs. wrong-font-and-layout vs. right-font-but-wrong-layout.)

ni=jfkthame since he sounded interested in looking into mitigations when we discussed this on slack. Though feel free to cancel/redirect the needinfo as-appropriate.

(Worst-case, if this is a site bug that we're unlucky enough to be getting the worst of & we don't have a good platform fix, we should probably do some sort of webcompat outreach here to help evite avoid tripping over this. I suspect evite has pretty high usage, and it's a bad look if their invitations render badly [in some cases unreadably] just-in-Firefox.)

Flags: needinfo?(jfkthame)

(Also FWIW: I can reproduce the "right font, wrong layout" bad rendering in Nightly 2020-01-01, v73.0a1. Builds much older than that (e.g. 3 months earlier 2019-09-01) don't show the card at all for some reason. So: in any case, we can safely consider this "not a regression" on our end.)

(In reply to Daniel Holbert [:dholbert] from comment #0)

STR:

  1. Load http://evite.me/5pDuxKK7Sq

One odd thing I'm seeing with this example is that if I repeatedly do a Cmd-R reload (so cached font resources should be used), the "PLEASE JOIN US" text consistently renders correctly, but the smaller text below ("In a real evite...") appears to alternate between the correct rendering (Josefin Sans webfont, as seen in your screenshots) and a fallback (Times Roman).

I'd have expected both webfonts to work consistently once they've been loaded, until the cache is cleared. No idea offhand why one of them seems to work, and the other alternately works/fails.

Flags: needinfo?(jfkthame)

As an experiment, I tried making the canvas SetFont method trigger loading of the font resource, in the hope that initiating this earlier might improve its chance of being available when needed, but this didn't make any visible difference.

It'd be interesting to know what blink/webkit-based browsers do here if the font resource is really slow to load, or fails altogether. Do they end up using a fallback, or are they blocking canvas text operations on the font load, potentially indefinitely?

I may have missed it, but I didn't see anywhere that the site is confirming the font resource is loaded (e.g. with document.fonts.check(...), or loading the resource with FontFace.load().then(...)) before calling measureText and fillText methods, so I suspect that in principle it's fragile -- but it seems that the other browsers are loading the fonts earlier, and/or waiting for the load to complete even without the page explicitly saying so. It'd be good to have a better understanding of what they're doing here.

Severity: -- → S3

I just ran into this again, with a different evite, FWIW (not too surprising, just a heads-up that it's still an issue).

Attachment #9357200 - Attachment description: image.png → screenshot of from October: Nightly on left, vs. Chrome on the right

(Still an issue in Nightly 129.0a1 (2024-06-28) (64-bit) FWIW.)

(In reply to Jonathan Kew [:jfkthame] from comment #13)

I may have missed it, but I didn't see anywhere that the site is confirming the font resource is loaded (e.g. with document.fonts.check(...), or loading the resource with FontFace.load().then(...)) before calling measureText and fillText methods, so I suspect that in principle it's fragile

I took the opportunity to look into this a bit more. I think evite is in fact doing some sort of awaiting for the font-load, at least when I view the site in Chrome -- specifically here (from Chrome devtools):

fabric.util.object.extend(fabric.Textbox, {
  async fromObject(object, callback) {
    const styles = fabric.util.stylesFromArray(object.styles, object.text);
    const objCopy = {...object, styles};

    try {
      const promises = Array.from(document.fonts.values())
        .filter(({family}) => family === object.fontFamily)
        .map((font) => font.load());
      await Promise.allSettled(promises);

That gets called with this backtrace:

fromObject (fonts.js:5)
(anonymous) (fabric.min.js:1)
enlivenObjects (fabric.min.js:1)
_enlivenObjects (fabric.min.js:1)
loadFromJSON (fabric.min.js:1)
t.useCanvas (useCanvas.js:43)
(anonymous) (useCanvasImage.js:11)
useMemo (react-dom.production.min.js:165)
t.useMemo (react.production.min.js:25)
t.useCanvasImage (useCanvasImage.js:9)
t.Card (Card.js:23)
[...SNIP...]
t.render (react-dom.production.min.js:290)

When Chrome gets here, Array.from(document.fonts.values()) is a 353-member array of FontFace objects. The 76th entry has the following JS properties defined -- it's the font used for the "Please join us" text on my my sample evite here:

family:  "looking-flowers-caps"
loaded: Promise {<pending>}
status: "unloaded"

Also: when I step through the above-quoted JS in Chrome, I definitely see the font request in the Network track when I reach the font.load() line.

Aha! So this is the key issue here, in the evite JS that I shared in comment 16:

      Array.from(document.fonts.values())

In Firefox, this^ expression always returns an empty array, even when document.fonts is very much not empty.

You can see this e.g. in devtools here at bugzilla, which has 10 fonts in document.fonts and yet we end up with an empty array:

>> document.fonts 
FontFaceSet { size: 10, [...]
>> document.fonts.values()
FontFaceSetIterator {  }
>> Array.from(document.fonts.values()) 
Array []
  length: 0
  <prototype>: Array []

Chrome ends up with a 10-entry array (as expected) if I do this^ in their DevTools.

This is essentially the same issue described in bug 1780657 (which is dependent-on and really a dupe of bug 1729089; which is itself probably a dupe of bug 1311198).

I'm going to morph this bug into a WebCompat::Site Report bug with a dependency on bug 1311198.

Component: Graphics: Canvas2D → Site Reports
Depends on: 1311198
Product: Core → Web Compatibility
Summary: Evite invitations sometimes render with the wrong font or linewrapping → Evite invitations sometimes render with the wrong font or linewrapping (due to evite assuming document.fonts.values() is iterable, and it's not in Firefox)

So, tl;dr,:

  • evite tries to gracefully wait for its fonts to load before it uses those fonts in displayed in an invitation, by awaiting font-load-promises that it gets from Array.from(document.fonts.values()).
  • But in Firefox, this graceful-waiting is ineffective because that JS expression always produces an empty array, due to bug 1311198 (as discussed in more detail in bug 1780657 which I've just duped to bug 1311198).
  • So evite accidentally goes ahead and starts measuring/drawing text onto a canvas with fonts that in fact are not-yet-loaded, and we end up with a broken rendering (only in Firefox) as a result.
Webcompat Priority: --- → P3
Webcompat Score: --- → 3
User Story: (updated)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: