Skip to content

perf(Icon): load the tooltip hover card only for icons that have one (3.0) - #374

Merged
lorant-one merged 3 commits into
feat/3-0-breaking-cleanupfrom
fix/icon-data-split
Oct 31, 2026
Merged

lorant-one merged 3 commits into
feat/3-0-breaking-cleanupfrom
fix/icon-data-split

Conversation

@lorant-one

Copy link
Copy Markdown
Member

Part of the bundle-size work from #359 and the Lighthouse audit, following #358.

Why

./components/Button measured 34.5 kB gzip in the new size gate. About a third of that came from Icon importing HoverCard for its tooltip prop. That pulled in Animation, CursorFollower, HoverCover and floating-ui with every component that draws an icon.

Change

  • The tooltip branch moved to IconTooltip.tsx, loaded with React.lazy and shown inside <Suspense fallback={icon}>.
  • Server rendering resolves the lazy component, so SSR pages keep their HTML while the chunk loads. Thanks to fix(providers): keep server HTML of lazy CodeBlocks and charts on mount (3.0) #364, the providers no longer drop that HTML during hydration. A client-only render shows the bare icon until the chunk arrives.
  • IconTooltip is not in the root barrel, so it does not become a public subpath.

Measured

I bundled src/components/Button.tsx with esbuild (minify, code splitting, React external):

gzip
Before 33.2 kB
After, eager 21.9 kB (Button 2.2 + shared chunk 19.7)
After, tooltip chunk (lazy) 12.0 kB

The rest is mostly the built-in icon data, about 10.9 kB gzip. Icons are looked up by name at runtime, so that data can't be split without changing the API. A more compact data format only saved 0.3 kB.

Checks

  • vitest run: 3903 passed, plus the new icon-tooltip-split.test.tsx.
  • tsc --noEmit is clean.
  • The existing tooltip and IconButton interaction tests pass.

Generated by Claude Code

…(3.0)

Icon imported HoverCard for its tooltip prop, so Animation and floating-ui
came with Button, IconButton and every component that draws an icon. The
hover card is now a lazy chunk; Button drops from about 33 to 22 kB gzip.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtxgzMmxuD2qeRfRW1z
The 300 ms timer read the global window when it fired. In CI it fired after
sortable.test.tsx's jsdom was torn down and threw 'window is not defined' as
an unhandled error, failing the run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016gNJtxgzMmxuD2qeRfRW1z

Copy link
Copy Markdown
Member Author

"Build, typecheck and test" failed on 16aed7b. All 3905 tests passed, but Vitest caught an unhandled ReferenceError: window is not defined at src/internal/sortable.ts:869, and an unhandled error fails the run. That line is the 300 ms timer that removes the keyup swallow after a keyboard drop. It reads the global window when the timer fires, and in this run that happened after sortable.test.tsx's jsdom had been torn down. Whether it fires in time depends on test file timing, which is why the base branch passed.

This PR doesn't touch that code, but the cause is real, so I fixed it in this PR: the cleanup now holds the window it was registered on. Browser behavior doesn't change. Locally, sortable.test passes on repeated runs. I couldn't reproduce the ordering here, so the next CI run is the check.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

The "Docs build" failure on a89e6d8 (React #418 on /form-controls/datePicker) isn't caused by this PR. I reproduced it locally on a build of the base branch at e207594 without this change. check-render moves the browser clock 25 hours ahead. For builds after 22:35 UTC on the 30th, that lands in November. A DatePicker with no value renders the build's month into the prerendered HTML, so hydration fails once the visitor's month is different. #375 fixes that, and once it merges I'll merge the base into this PR.


Generated by Claude Code

@lorant-one
lorant-one merged commit 16a11ae into feat/3-0-breaking-cleanup Oct 31, 2026
8 checks passed
lorant-one pushed a commit that referenced this pull request Oct 31, 2026
…chunks

Bundled without splitting, esbuild inlines each import() into the entry,
so the gate counted Icon's lazy tooltip card in every component that
draws an icon. With splitting, an entry costs itself and the chunks it
imports statically. Re-recorded on the 3.0 branch with #374 in it:
Button 35.3 -> 24.1 KB, Icon 31.3 -> 19.8 KB, ./code 49.0 -> 25.0 KB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YJHdG7ZbpQS64MtL5PVbT1
lorant-one added a commit that referenced this pull request Oct 31, 2026
* ci(core): bundle-size gate for every export entry

scripts/bundle-size.mjs bundles each JS entry in core's exports (98 of
them, the per-component subpaths included) the way an app would:
minified, peers external, CSS modules counted. It also measures the two
stylesheets, gzipped. Sizes are compared with bundle-size.json, and the
step fails when an entry grows by more than 5% and 512 B. Record an
intended growth with --update. It runs as a step in the existing build
job and takes a few seconds. esbuild 0.27.7 is already in the lockfile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YJHdG7ZbpQS64MtL5PVbT1

* fix(bundle-size): measure what an entry loads up front, not its lazy chunks

Bundled without splitting, esbuild inlines each import() into the entry,
so the gate counted Icon's lazy tooltip card in every component that
draws an icon. With splitting, an entry costs itself and the chunks it
imports statically. Re-recorded on the 3.0 branch with #374 in it:
Button 35.3 -> 24.1 KB, Icon 31.3 -> 19.8 KB, ./code 49.0 -> 25.0 KB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YJHdG7ZbpQS64MtL5PVbT1

---------

Co-authored-by: Claude <[email protected]>
@lorant-one
lorant-one deleted the fix/icon-data-split branch October 31, 2026 21:34
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