feat: @pracht/image with responsive images and pluggable optimization loaders - #192
Open
JoviDeCroock wants to merge 6 commits into
Open
feat: @pracht/image with responsive images and pluggable optimization loaders#192JoviDeCroock wants to merge 6 commits into
JoviDeCroock wants to merge 6 commits into
Conversation
JoviDeCroock
force-pushed
the
claude/pracht-image
branch
2 times, most recently
from
July 9, 2026 05:19
8127f01 to
df1a0a3
Compare
… loaders
New package providing next/image-quality image handling for pracht apps:
- <Image> Preact component: required width/height (or fill) for CLS
safety with dev warnings, srcset across configurable device-size
breakpoints (w descriptors with sizes/fill, snapped 1x/2x otherwise),
lazy + async decoding by default, priority -> eager + fetchpriority,
next/image-style fill styling. Renders plain <img>; zero client runtime.
- Pluggable loaders ({ src, width, quality }) => string: defaultLoader
(pracht endpoint), cloudflareLoader (/cdn-cgi/image/...), vercelLoader
(/_vercel/image), passthroughLoader. Global configureImage() plus a
per-component loader prop.
- @pracht/image/node: createImageHandler(), a sharp-backed (optional peer
dependency with an install hint) optimization endpoint mounted as the
src/api/_pracht/image.ts API route so it works in pracht dev and on
every adapter. Same-origin sources only unless remotePatterns allows,
width allowlist + max cap, redirect re-validation, Accept-negotiated
WebP/AVIF, immutable cache headers, SVG/GIF passthrough.
- Example usage in examples/basic (gallery route + endpoint + banner),
e2e coverage in node-build, 41 unit tests, docs/IMAGES.md, changeset.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
JoviDeCroock
force-pushed
the
claude/pracht-image
branch
from
July 9, 2026 05:37
df1a0a3 to
5d6fe8f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@pracht/imagebringing next/image-quality image handling to pracht apps, mirroring next/image's loader architecture:<Image>Preact component — requireswidth+height(orfill) so space is always reserved (dev-modeconsole.errorwhen missing), generatessrcsetacross a configurable device-size breakpoint list (wdescriptors withsizes/fill, cache-friendly snapped1x/2xotherwise),loading="lazy"+decoding="async"by default with apriorityprop switching to eager +fetchpriority="high",quality(default 75), and next/image-style absolute-inset styling forfill. Renders a plain<img>— SSR-safe, zero client runtime.({ src, width, quality }) => string):defaultLoader(pracht endpoint),cloudflareLoader(/cdn-cgi/image/width=,quality=,format=auto/<src>),vercelLoader(/_vercel/image?url=&w=&q=),passthroughLoader(static hosts; srcset omitted). Configured globally viaconfigureImage()and overridable per component via theloaderprop.createImageHandler()from@pracht/image/node, mounted as thesrc/api/_pracht/image.tsAPI route (the least invasive wiring: it rides the existing API-route auto-discovery, so it works identically inpracht devand on every adapter with a Node-compatible runtime, no vite-plugin or adapter changes). Usessharpas an optional peer dependency with a clear install hint when missing. Security: same-origin (relative) sources only unlessremotePatternsallowlists hosts, redirect re-validation, width allowlist +maxWidthcap so caches can't be filled with arbitrary variants, source size cap,image/*content-type enforcement, SVG served withContent-Disposition: attachment. Negotiates WebP (AVIF opt-in) viaAcceptand answers withCache-Control: public, max-age=31536000, immutable+Vary: Accept.examples/basic:/galleryroute (priority, fixed, and fill images), the mounted endpoint, andpublic/banner.jpg; the node-build e2e now exercises the endpoint against the built server (webp output, immutable headers, 403 for non-allowlisted remote sources).docs/IMAGES.md(linked from the README repo map), package README,docs/WORKSPACE.md+VISION_MVP.mdpackage enumerations updated, root build filter + tsconfig paths wired.Follow-ups intentionally out of scope for v1:
placeholder="blur").Testing
pnpm e2e(60 passed, including new node-build assertions for the image endpoint)pnpm formatpnpm lintpnpm test(411 passed; 41 new tests for srcset generation, priority, fill, loader selection, and the endpoint's validation/allowlist/format negotiation)pnpm typecheckpracht devsmoke test inexamples/basic:/galleryrenders,/api/_pracht/image?url=%2Fbanner.jpg&w=640&q=75returns webp with immutable cache headers, remote sources are denied with 403Checklist
docs/IMAGES.md, README repo map,docs/WORKSPACE.md,VISION_MVP.md)/add-imagesskill is a possible follow-up).changeset/pracht-image-package.md, minor for@pracht/image)🤖 Generated with Claude Code