fix(font-loading): enhance font loading mechanism with stylesheet readiness and improved error handling - #156
Conversation
…diness and improved error handling
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bda610840c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const link = document.querySelector("link[data-ratex-fonts-stylesheet]"); | ||
| if (!link || link.sheet) return Promise.resolve({ ok: true, href: link && link.href }); | ||
|
|
||
| return new Promise((resolve) => { | ||
| link.addEventListener("load", () => resolve({ ok: true, href: link.href }), { once: true }); | ||
| link.addEventListener("error", () => resolve({ ok: false, href: link.href }), { once: true }); |
There was a problem hiding this comment.
Preserve failures that occur before stylesheet listeners attach
When the homepage font stylesheet fails before gallery.js runs, link.sheet remains null but the link's one-shot error event may already have fired; attaching listeners here then leaves this promise pending forever. In that scenario the hero playground waits indefinitely instead of reporting the font failure, so the direct stylesheet needs a readiness promise installed when it is created or another way to recognize an already-completed failure.
Useful? React with 👍 / 👎.
| if (stylesheet && stylesheet.ok === false) { | ||
| throw new Error("Failed to load the RaTeX font stylesheet: " + stylesheet.href); | ||
| } | ||
| if (!document.fonts || typeof document.fonts.load !== "function") { | ||
| throw new Error("This browser does not support the CSS Font Loading API."); |
There was a problem hiding this comment.
Report font-loading rejections in gallery initialization
When the stylesheet fails or the CSS Font Loading API is unavailable, these new throws reject loadFonts(), but the gallery path awaits it outside its existing error handler and every page invokes RaTeXGallery.init() without awaiting or catching the returned promise. The gallery therefore remains at “Loading fonts…” with an unhandled rejection; catch this failure in init() and update the visible status before returning.
Useful? React with 👍 / 👎.
No description provided.