Skip to content

Load KaTeX on demand to prevent first-paint blocking#748

Merged
jaberjaber23 merged 1 commit intoRightNow-AI:mainfrom
lc-soft:fix/katex-load
Mar 20, 2026
Merged

Load KaTeX on demand to prevent first-paint blocking#748
jaberjaber23 merged 1 commit intoRightNow-AI:mainfrom
lc-soft:fix/katex-load

Conversation

@lc-soft
Copy link
Contributor

@lc-soft lc-soft commented Mar 19, 2026

Summary

This PR fixes first-paint blocking caused by globally loading KaTeX assets in the dashboard.
In some regions, loading assets from cdn.jsdelivr.net can be very slow or even time out, which may leave the page blank until those requests complete.
KaTeX is now loaded only when math content is actually present, so regular pages/chats render faster and are no longer blocked by KaTeX CDN fetches.

Changes

  • Removed global KaTeX CSS/JS includes from the dashboard head.
  • Extracted KaTeX logic into a dedicated katex.js module.
  • Added on-demand loading for KaTeX CSS, core JS, and auto-render JS.
  • Added math-delimiter detection so KaTeX loads only when LaTeX content is detected.
  • Kept chat math rendering behavior intact after dynamic load.

Testing

  • cargo clippy --workspace --all-targets -- -D warnings passes
  • cargo test --workspace passes
  • Live integration tested (if applicable)

Security

  • No new unsafe code
  • No secrets or API keys in diff
  • User input validated at boundaries

Copy link
Member

@jaberjaber23 jaberjaber23 left a comment

Choose a reason for hiding this comment

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

Good improvement. Moves KaTeX from blocking head tags to on-demand loading with proper dedup via shared promise. Correct error recovery (retry on failure). renderLatex() interface preserved. Insertion point in webchat.rs is correct.

@jaberjaber23 jaberjaber23 merged commit 63f4bef into RightNow-AI:main Mar 20, 2026
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.

2 participants