Skip to content

fix(font-loading): enhance font loading mechanism with stylesheet readiness and improved error handling - #156

Merged
erweixin merged 1 commit into
mainfrom
fix-website
Sep 4, 2026
Merged

erweixin merged 1 commit into
mainfrom
fix-website

Conversation

@erweixin

@erweixin erweixin commented Sep 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T01:47:54.459162Z bda6108 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread website/public/gallery.js
Comment on lines +201 to +206
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 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread website/public/gallery.js
Comment on lines +215 to +219
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.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@erweixin
erweixin merged commit c902516 into main Sep 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant