Skip to content

perf: run the islands on preact instead of react - #54

Merged
banteg merged 3 commits into
mainfrom
perf/preact
Oct 30, 2026
Merged

banteg merged 3 commits into
mainfrom
perf/preact

Conversation

@banteg

@banteg banteg commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

The interactive parts (header and player, comic reader, comics list, gallery) use only plain hooks and context. Preact runs those as is, with React's runtime replaced by one about a tenth the size.

JavaScript each page loads (gzipped, all chunks it imports)

Page React Preact
Home, FAQ 78.7 KB 18.7 KB
Comics list 79.8 KB 19.7 KB
Comic reader 83.7 KB 23.0 KB
Tribute hall 81.4 KB 20.7 KB

PhotoSwipe still loads only when a viewer opens.

Why Preact and not Solid or Svelte: those would also cut the runtime to a few KB. But they'd mean rewriting about 900 lines of reader and player logic into a different reactivity model (scroll tracking, resume, focus return, drag), and re-debugging all of it. Preact gets the same savings with these small changes:

  • hooks come from preact/hooks and types from preact;
  • the seek and volume sliders listen to input, since Preact's onChange is the native event that fires only on release;
  • useEffectEvent, which Preact keeps in its compat layer, is a 10-line helper here (src/utils/useEffectEvent.ts);
  • ESLint keeps rules-of-hooks and exhaustive-deps. The hooks plugin's other rules check code for the React Compiler and don't recognise Preact's refs. @eslint-react now knows the import source is Preact.

Tested in the browser:

  • Info menu: opens, closes on Escape, and returns focus.
  • Player: play, next track, seek and volume while dragging, dragging the panel.
  • Navigation: audio keeps playing across pages.
  • Reader: resume, pages mode, page select, arrow keys, scroll mode tracking the page, text toggles.
  • Zoom: opens, viewer keys move the reader along, closes.
  • Gallery: viewer with captions.
  • Comics list: reading progress.
  • Console: no errors.

Lint, astro check and the build pass.

- in pages mode, space on a focused button, link or toggle presses it
  instead of turning the page; arrows still turn pages
- the info menu scrolls when a short screen can't fit it
- a zoom click made while the viewer is still loading opens once it is
  ready, and opens the image itself if the viewer fails to load
- the background video pauses on comic pages, which cover it, and for
  visitors who ask for less motion
- phones no longer preload the comic art below their first screen
- homepage images take their real sizes from the files at build time
the header, comic reader, comics list and gallery only use plain hooks
and context, which preact runs as is. react-dom was about 66 KB gzipped
of the 79 KB every page loaded; with preact the homepage loads 19 KB and
a comic page 23 KB.

- hooks import from preact/hooks, types from preact
- the sliders listen to input rather than change, which preact fires
  only on release
- useEffectEvent, which preact keeps in its compat layer, is a small
  helper here
- eslint keeps the rules of hooks; the react compiler rules don't apply
  and don't know preact's hooks
@socket-security

socket-security Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​astrojs/​preact@​6.1.11001008196100
Addedpreact@​11.1.010010010098100

View full report

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Deploy preview for y-fu ready!

Project:y-fu
Status: ✅  Deploy successful!
Preview URL:https://y-m3em0graa-yearn.vercel.app
Latest Commit:23a3653

Deployed with vercel-action

@banteg
banteg deleted the branch fix/review-findings October 30, 2026 16:07
@banteg banteg closed this Oct 30, 2026
@banteg banteg reopened this Oct 30, 2026
@banteg
banteg changed the base branch from fix/review-findings to main October 30, 2026 16:08
@banteg
banteg merged commit e2de1d6 into main Oct 30, 2026
3 checks passed
@banteg
banteg deleted the perf/preact branch October 30, 2026 16:11

This branch was successfully deployed

1 active deployment
preview — 23a36537 Deployed Oct 30, 2026 by github-actions[bot]
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