Skip to content

Settle a finished block to a plain render, and stop bundling tippy's stylesheet - #2

Merged
olibaron merged 3 commits into
mainfrom
fix/settled-blocks-and-tippy-stylesheet
Sep 11, 2026
Merged

olibaron merged 3 commits into
mainfrom
fix/settled-blocks-and-tippy-stylesheet

Conversation

@olibaron

Copy link
Copy Markdown
Contributor

Fixed

A finished block now settles to a plain render once, after the fade it started has run. A streamed block wore the animated shape for its whole life, and the closed render then replaced it with markup carrying no animation at all. The words had finished fading, so they did not move — but everything else did: the code gutter was rebuilt from scratch with every line number restarting its fade, and a table's last row jumped from partial opacity to full in a single frame.

Each block kind now books one settled pass, a second after it closes, which is when its fade has finished and the swap is therefore invisible:

  • MarkdownCode schedules the pass instead of swapping children inside render(), and a flag — not the children — decides whether it has been applied, so a settle that produced nothing to adopt cannot re-arm it; reset() cancels one that is still booked;
  • the pass is skipped when the animation is off, where the closed shape is already the plain one;
  • line numbers are handed the code cache's tally in both phases, since the settled tree holds the same lines, and remember the last tally, so a caller that withdraws it can no longer collapse the gutter and remount every entry;
  • tables and markup take the same pass from the renderer, rebuilt from a cache of its own so a later block cannot race it;
  • a finished block carries no data-animate-word, data-animate-key or data-animate-marker, and its frame is byte-identical to the same document streamed with animation: false. Blocks already settled are never re-passed when new ones stream.

Toolbar tooltip CSS is no longer bundled. tippy.js became an optional peer so a consumer that never renders a toolbar would not pay for it, but the stylesheet still inlined tippy's base CSS — so every consumer shipped it — and the build then needed the package installed, which nothing did, which meant npm run build could not pass from a clean npm ci.

The main stylesheet now carries only the toolbar skin and no longer imports from node_modules. A host that renders toolbars imports tippy's own sheet beside the one it already imports for KaTeX:

import "tippy.js/dist/tippy.css";

Documented in styling.md and the README, and applied to the site demo, the playground and the example page. The built dist/hypermarkdown.css drops by the 1.4 kB tippy sheet (46 478 → 45 064 bytes), and the assertion in build-css.mjs still guards the skin. tippy.js stays a peer and a devDependency, exactly as KaTeX does: tsc needs its types and the tooltip loader test needs the runtime.

The word and marker fades also drop will-change: opacity, which promoted a compositor layer per word for no measured gain.

Verification

  • npm run lint, npm run typecheck (React 18 and 19), npm run test:coverage, npm run test:coverage:unit and npm run build all pass; coverage is 100% statements, branches, functions and lines, and the new guards are covered.
  • npm pack --dry-run: 72 files, 355 kB.
  • A mounted-tree harness streams the same document with the animation on and off and asserts the settled markup is byte-identical, with no animation attributes left in prose, lists, tables, code or diagrams.

Compatibility

No API change. A host that renders block toolbars needs one extra stylesheet import; without it the toolbars still work and the tips simply lose their positioning and sizing. Patch release.

A streamed block wore the animated shape for its whole life, and the closed
render then replaced it with markup that carried no animation at all. For the
words that was invisible — they had finished fading — but the swap itself was
not. The code gutter was rebuilt from scratch, every entry restarting its
fade, and a table's last row jumped from partial opacity to full in a single
frame.

Every block kind now makes that swap once, after the fade it started has run,
one pass per closed block:

- `MarkdownCode` books the pass on a timer instead of swapping children
  during render, and the guard is a flag rather than the children, so a
  settle that produced nothing to adopt cannot re-arm it;
- the pass is skipped when the animation is off, where the closed shape is
  already the plain one, and `reset()` cancels one that is still booked;
- line numbers take the code cache's tally in both phases — the settled tree
  holds the same lines — and remember the last tally, so a caller that
  withdraws it can no longer collapse the gutter and remount every entry;
- tables and markup get the same pass from the renderer, rebuilt from a cache
  of its own so a later block cannot race it;
- a finished block carries no `data-animate-word`, `data-animate-key` or
  `data-animate-marker`: its frame is byte-identical to the same document
  streamed with the animation off, and blocks already settled are never
  re-passed when new ones stream.

Coverage stays at 100%, including the guards these passes added.
tippy.js became an optional peer so that a consumer which never renders a
toolbar would not pay for it, but the stylesheet still inlined tippy's base
CSS: every consumer shipped it, and the build in turn needed the package
installed, which nothing did — so `npm run build` could not pass from a clean
`npm ci`.

The main stylesheet now carries only the toolbar skin and no longer imports
from `node_modules`. A host that renders toolbars imports tippy's own sheet
beside the one it already imports for KaTeX:

    import "tippy.js/dist/tippy.css";

Documented in `styling.md` and the README, and applied to the site demo, the
playground and the example page. The built stylesheet drops by the 1.4 kB
tippy sheet, and the build assertion still guards the skin. tippy.js stays a
peer and a devDependency, exactly as KaTeX does: `tsc` needs its types and
the tooltip loader test needs the runtime.

Also comments out `will-change: opacity` on the word and marker fades, which
promoted a compositor layer per word for no measured gain.
@github-actions

Copy link
Copy Markdown

Coverage Report for Unit

Status Category Percentage Covered / Total
🟢 Lines 100% (🎯 100%) 780 / 780
🟢 Statements 100% (🎯 100%) 790 / 790
🟢 Functions 100% (🎯 100%) 80 / 80
🟢 Branches 100% (🎯 100%) 571 / 571
File CoverageNo changed files found.
Generated in workflow #49 for commit 1a4ef93 by the Vitest Coverage Report Action

@github-actions

Copy link
Copy Markdown

Coverage Report for All

Status Category Percentage Covered / Total
🟢 Lines 100% (🎯 100%) 3144 / 3144
🟢 Statements 100% (🎯 100%) 3179 / 3179
🟢 Functions 100% (🎯 100%) 494 / 494
🟢 Branches 100% (🎯 100%) 1954 / 1954
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
lib/renderer.tsx 100% 100% 100% 100%
lib/code/index.tsx 100% 100% 100% 100%
lib/code/line-numbers.tsx 100% 100% 100% 100%
Generated in workflow #49 for commit 1a4ef93 by the Vitest Coverage Report Action

@olibaron
olibaron merged commit 9b56cfc into main Sep 11, 2026
6 checks passed
@olibaron
olibaron deleted the fix/settled-blocks-and-tippy-stylesheet branch September 11, 2026 09:35
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