Skip to content

fix(MarkdownKaTeX): load styles lazily - #6673

Closed
ernestt wants to merge 1 commit into
markdown-upgrade/17-shikifrom
markdown-upgrade/18-katex-lazy-styles
Closed

ernestt wants to merge 1 commit into
markdown-upgrade/17-shikifrom
markdown-upgrade/18-katex-lazy-styles

Conversation

@ernestt

@ernestt ernestt commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Consumers can typecheck and server-render the optional KaTeX adapter without resolving its stylesheet eagerly, while displayed equations retain readable block rhythm after loading.

Problem and solution fit

A top-level stylesheet side-effect crossed the optional adapter's import boundary and failed source-mapped consumer typechecks before the renderer mounted. Moving CSS beside the lazy engine import restores the boundary; the adapter also owns its display-math spacing.

Expected behavior and authority

AST-039's lazy optional-peer boundary and the Markdown math-renderer fallback contract. Pinned source.

Smallest restoration

Load KaTeX CSS and the engine together after mount, add the package-local CSS declaration, and give block output token-based vertical rhythm. SSR/loading/failure still preserve source.

Evidence

Real-browser evidence

KaTeX block rhythm before and after

Measured block margin: 0px before → 16px after; SSR/loading/failure still retain delimiter-bearing source.

  • Representative unchanged paths are covered by focused regression tests.
  • Mutation-sensitive proof is included with the implementation.

Scope

  • One defect is restored.
  • Separable tagalongs were removed or split into adjacent stack entries.
  • No unrelated API or visual change is hidden under the bug-fix label.
  • Public text and artifacts contain no internal context.

Testing

  • Focused: KaTeX unit/integration tests, Core and Storybook typechecks, SSR/loading fallback, production build, and real-browser spacing measurement.
  • Stack head: pnpm exec vitest run packages/core/src/Markdown packages/core/src/CodeBlock — 37 files, 760 tests.
  • Stack head: pnpm --filter @astryxdesign/core typecheck.
  • Repository checks: pnpm check:repo.

Stack

Previous: #6672 · Next: #6674 · Each PR is intentionally one commit and one primary intent.

@vercel

vercel Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 26, 2026 3:45pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 26, 2026
@astracat-bot

astracat-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
📝 Draft — not reviewed automatically (for maintainers only) Sep 28, 2026, 8:41 PM UTC

Summary:
Load the optional KaTeX stylesheet together with the engine after mount instead of exposing an untyped static CSS side-effect import to source-mapped consumers. Keep display expressions separated with adapter-owned block rhythm.

Test Plan:
- pnpm exec vitest run packages/core/src/Markdown/katex/MarkdownKaTeX.test.tsx packages/core/src/Markdown/katex/MarkdownKaTeX.integration.test.tsx --root .
- pnpm --filter @astryxdesign/core typecheck
- pnpm --filter @astryxdesign/storybook typecheck
- pnpm --filter @astryxdesign/storybook build
@ernestt

ernestt commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@cixzhang — I’d appreciate your feedback on this draft.

Focus: Consumers can typecheck and server-render the optional KaTeX adapter without resolving its stylesheet eagerly, while displayed equations retain readable block rhythm after loading.

This is PR 18/20 in the linked Markdown stack. It is intentionally one commit and one primary intent; the description includes matched before/after screenshots and previous/next links, so you can review just this PR’s delta.

@humbertovirtudes humbertovirtudes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes two observable behaviours, deferred KaTeX stylesheet loading and display-math spacing, but adds no regression test. The current tests remain green if either the dynamic CSS import or marginBlock is removed. Please add focused evidence that the stylesheet stays out of the eager path and loads with the renderer, plus a StyleX declaration assertion for block versus inline spacing.

@ernestt
ernestt added this pull request to stack #6700 September 28, 2026 18:03
github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook and Sandbox are not both ready on the exact-head Vercel preview. CI concluded failure.

Modified Components

Outline (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 719 -
Complexity N/A High (28) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

3 of 422 shot(s) changed. View the report

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Markdown Default probe dark 29,661
Markdown Default probe light 29,652
SideNav Resizable in AppShell probe dark 3,208
Markdown — Default — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
Markdown — Default — probe light
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
SideNav — Resizable in AppShell — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

Generated by PR Enrichment workflow | View full report

@ernestt ernestt closed this Oct 9, 2026
@github-actions
github-actions Bot deleted the markdown-upgrade/18-katex-lazy-styles branch October 10, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 5f0d5eb8 Deployed Sep 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants