Repository navigation
perf(docsite): serve template preview images through the image optimizer - #11320
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
Template and block previews load their photos as the full-size PNG and JPEG files under public/template-assets. The first screen of /templates downloads 28.9 MB of them. A Webpack loader now addresses each of those files by its /_next/image URL in the modules a preview renders: page templates, and the block copies under src/generated. The optimizer returns the same picture in the format the browser accepts, at its own pixel size up to 1920 pixels wide. Template sources, the code the site shows, the shadcn registry, and `astryx template` output keep their /template-assets/ paths. Vector images, video, and paths with no file stay as written.
f705e75 to
0044a9c
Compare
There was a problem hiding this comment.
Changes requested. The loader cuts preview image weight as described, and every surface that hands out source keeps its /template-assets/ paths. Three things need fixing before approval:
apps/docsite/scripts/template-image-loader.mjs:24-26adds a second fixture-reference scanner beside the CLI'sreplaceDemoMediainpackages/cli/foundation/discovery/template-adapter.mjs, and the two already disagree (a?v=2query or an upper-case.PNGcounts as a fixture on copy but is left unoptimized in previews), so please export the CLI scanner as a mapper and call it from the loader, the waytemplate-icon-loader.mjsreuses the CLI's icon rewrite.- The Authority section says no spec record governs docsite preview assets, but
spec:AST-028FR4–FR6 govern them (andspec:AST-033FR23 governs the surfaces that hand out source), so please cite those claims and say how the loader meets each. - The verification for
spec:AST-028FR4–FR6 calls for real request checks on the pull-request preview, so please state that/templates, theproduct-gallerydialog andlogin-ssoon this head's Vercel preview load every fixture from/_next/imagewith status 200.
CI has not run on this head yet, because CI admission reported CI full, so a re-run is also needed.
Claims and files checked
- Previews today load each full-size fixture file: verified.
- First-screen bytes, timings and landing-page transfer: measurements, not reproduced.
- The 99 raster fixtures total 111.0 MB: verified; the optimized 5.7 MB total was not reproduced.
- Template sources, displayed code, the shadcn registry and
astryx templateoutput keep their paths: verified. - Each preview photo is a 0.5–1.2 MB PNG: approximately true (64 of the 77 referenced photos;
building.pngis 4.2 MB). - One loader rewrites only page templates and the generated block copies: verified.
- The optimizer returns the same picture as WebP at its own size and never enlarges: not checked against the Next.js source; consistent with the 92/7 split.
- No spec record governs docsite preview assets: false (
spec:AST-028FR4–FR6). - The loader follows the icon-loader precedent: partly; both rewrite preview modules only, but the icon loader reuses the CLI's rewrite.
- 92 of 99 fixtures keep their pixel size, and seven come back 1920 px wide: verified.
- Vector images, video and missing files stay as written, and the two fallback fixtures still fail: verified.
- The shadcn output and the generated registries contain no optimizer URL: verified by how they are written.
- No fixture PNG or JPEG request remains on the listed pages: browser measurement, not reproduced.
- WebP at quality 75 is slightly softer: consistent with the quality setting.
- One width per image, so at most 99 transformations per cache period: verified.
- The new test file covers what the description lists: verified.
- Test, typecheck, build and pre-review results: not reproduced; the Vercel build of this head succeeded.
apps/docsite/scripts/template-image-loader.mjs: finding (shared scanner).apps/docsite/next.config.mjs: clear.apps/docsite/README.md: clear.apps/docsite/src/__tests__/template-image-loader.test.ts: clear, apart from its part in the shared-scanner finding.apps/docsite/src/__tests__/template-icon-loader.test.ts: clear.
The image loader had its own pattern for fixture references, and it disagreed with the scanner a copy uses: a reference with a query, or an upper-case suffix, was a fixture on copy but not in a preview. The CLI's scanner now takes the replacement as a function (`mapFixtureRefs`). A copy passes its placeholders, as before. The image loader passes the optimizer URL for a PNG or JPEG value that the docsite serves, and keeps every other reference as written.
There was a problem hiding this comment.
Thanks for moving the loader onto the CLI's fixture scanner: a preview and a copy now agree on what a fixture reference is, which settles the earlier scanner comment. Changes are still requested for these points:
- The description's Authority section says no spec record governs docsite preview assets, but
docs/specs/AST-028/spec.mdFR4–FR6 governs maintainer previews, including the docsite and pull-request previews, anddocs/specs/AST-033/spec.mdFR23 governs the source surfaces, so please cite them and say how the loader meets each. - Miss:
apps/docsite/README.mdlines 113–114, and the description, say the filesastryx templatecopies keep their/template-assets/paths, buttemplate copy,template showand the shadcn registry replace every fixture with a placeholder (AST-028 FR7), so please say that the template sources and the code the site shows keep their paths while copies still use placeholders. - AST-028's verification for FR4–FR6 names real request checks on the pull-request preview, and the description says the deployed optimizer was not tested, so please load
/templates, theproduct-gallerydialog andlogin-ssoon this head's preview and state that every/_next/imagerequest for a template fixture returns 200 with an image.
Claims and files checked
- Claim, previews load the full-size committed files today: verified (the base has no rewrite).
- Claim, the loader rewrites served PNG and JPEG fixtures only in page templates and the generated block copies: verified (
next.config.mjs:47-48; testtemplate-image-loader.test.ts:164-184). - Claim, the optimizer returns the same picture at its own size, never enlarged, up to 1920 px: verified against Next's defaults and the files; 92 of 99 keep their size, and six
@2xphotos andbuilding.pngare capped at 1920 px. - Claim, template sources and the code the site shows keep their paths: verified.
- Claim, the shadcn registry and
astryx templateoutput keep their/template-assets/paths: false; both carry placeholders. - Claim, vector images, video and missing files stay as written, and the Avatar fallback fixtures still fail: verified (
template-image-loader.mjs:53-61; tests:51-55,:70-79). - Claim,
public/shadcnand the generated registries contain no optimizer URL: verified by reading; they are written from disk, not through Webpack. - Claim, no spec record governs docsite preview assets: false (AST-028 FR4).
- Claim, the 99 files total 111.0 MB before: the committed total is 111.0 MiB (116.4 MB); the optimized total and the timings are the author's measurements and were not reproduced.
- Claim, each preview photo is a 0.5–1.2 MB PNG: roughly; 64 of 99 files are in that range and some referenced files are larger (
building.pngis 4.2 MB). - Claim, at most 99 transformations per cache period: holds for browsers that accept WebP (one width, default formats).
- Claim, the tests cover the rewrite, untouched references, catalog coverage, cache dependencies, the rule's reach and the allowed width and quality: verified by reading.
- Changeset claim, the scanner takes the replacement as a function and no command's output changes: verified (
replaceDemoMediareturns the same placeholders and count). - File
.changeset/cli-fixture-reference-mapper.md: clear. - File
apps/docsite/README.md: finding at lines 113–114. - File
apps/docsite/next.config.mjs: clear. - File
apps/docsite/scripts/template-image-loader.mjs: clear. - File
apps/docsite/src/__tests__/template-icon-loader.test.ts: clear. - File
apps/docsite/src/__tests__/template-image-loader.test.ts: clear. - File
packages/cli/foundation/discovery/template-adapter.fixture-refs.test.mjs: clear. - File
packages/cli/foundation/discovery/template-adapter.mjs: clear.
There was a problem hiding this comment.
Approved. The README now says copies still use placeholders, the description cites docs/specs/AST-028/spec.md FR4–FR6 and docs/specs/AST-033/spec.md FR23 accurately, and it reports the pull-request-preview check that AST-028 asks for, so the three points from the last review are settled.
Claims and files checked
- Claim, each preview photo loads today as the full-size committed file: verified (the base config has no image rule).
- Claim, the byte and timing reductions in the measurement table: the author's measurements, not reproduced; the committed folder holds 99 PNGs totalling 111.0 MiB (116.4 MB).
- Claim, template sources do not change and the code the site shows keeps its fixture paths: verified (
next.config.mjs:47-48; shown source is read from disk into the registries). - Claim,
astryx templateand the shadcn Install item still replace each fixture with a placeholder, with unchanged output: verified (replaceDemoMediapasses the same placeholders and count,template-adapter.mjs:360-365). - Claim, each preview photo is a 0.5–1.2 MB PNG and a gallery screen shows about 30: roughly; 58 of the 77 referenced PNGs are in that range and 14 are larger, and the preview table counts 31 fixture requests on
/templates. - Claim, the loader rewrites PNG and JPEG fixture references only in page templates and the generated block copies: verified (
next.config.mjs:47-48,:195-207; testtemplate-image-loader.test.ts:164-184). - Claim, the optimizer returns the same picture as WebP at its own size, never enlarged, up to 1920 px: verified against Next's defaults and the files.
- Claim, the loader uses the CLI's scanner through
mapFixtureRefs, with no CLI behavior change and unchanged CLI tests: verified (template-adapter.mjs:391-421; the existing tests are untouched). - Changeset claim, the scanner takes the replacement as a function and no command's output changes: verified.
- Claim, the rewrite meets AST-028 FR4 by happening only in the build's copy of a module: verified.
- Claim, each optimizer URL is deterministic, meeting AST-028 FR5: verified (
template-image-loader.mjs:35-37). - Claim, a missing file keeps its path, a refused reference fails the build naming it, and video and vector images are not rewritten, meeting AST-028 FR6: verified (
template-image-loader.mjs:53-60;template-adapter.mjs:1035,:1125). - Claim, surfaces that hand out source are unchanged, meeting AST-033 FR23: verified (CI's docsite build of this head has no optimizer URL in the shadcn output or the generated registries).
- Claim, the loader follows
template-icon-loader.mjs, which also reuses CLI code: verified. - Claim, 92 of the 99 raster files keep their size and six
@2xphotos andbuilding.pngcome back 1920 px wide: verified from the file headers. - Claim, vector images, video and missing paths stay as written and the two Avatar fallback fixtures still fail to load: verified (tests
:51-55,:70-79; CI's docsite build). - Claim, the loader rewrites 170 references in 47 modules and refuses none: not reproduced exactly; consistent with CI's passing docsite build, which addresses 77 distinct fixtures.
- Claim, no direct fixture PNG request remains on the named pages and console output is unchanged: the author's local measurement; consistent with CI's docsite build.
- Claim, WebP at quality 75 is slightly softer when enlarged: the author's crops; not reproduced.
- Claim, at most 99 transformations per cache period: holds per output format, since one width is requested.
- Claim, the new tests cover the rewrite, untouched references, catalog coverage, cache dependencies, the rule's reach and the allowed width and quality, and the CLI test adds two
mapFixtureRefstests: verified by reading. - Claim, on the pull-request preview every fixture request goes through
/_next/imageand returns 200 as WebP, with no direct PNG request: the author's statement for the previous commit, whose built code equals this head's (the later commit edits only the docsite README). - Claim, the second commit does not change which references are rewritten: consistent with the shared scanner and the catalog test.
- File
.changeset/cli-fixture-reference-mapper.md: clear. - File
apps/docsite/README.md: clear. - File
apps/docsite/next.config.mjs: clear. - File
apps/docsite/scripts/template-image-loader.mjs: clear. - File
apps/docsite/src/__tests__/template-icon-loader.test.ts: clear. - File
apps/docsite/src/__tests__/template-image-loader.test.ts: clear. - File
packages/cli/foundation/discovery/template-adapter.fixture-refs.test.mjs: clear. - File
packages/cli/foundation/discovery/template-adapter.mjs: clear.
Primary intent
Serve the photos in template and block previews through the Next.js image optimizer. This is a docsite performance change: it restores no broken behavior and adds no capability, so the other templates do not fit.
User or maintainer impact
Anyone who opens
/templates, the landing page, or a component page with photo examples. Previews render real templates, and each photo loads as the full-size PNG or JPEG underpublic/template-assets, whatever its size on screen.Measured in headless Chromium on a production build (
next start), 1440×900:/templatesfirst screen, image bytes (45 requests)/templatesfirst screen, six tiles rendered, 4× CPU, 10 Mbps / 40 ms (2 runs)public/template-assets, fetched once eachTemplate sources do not change, and the code the site shows keeps its
/template-assets/paths.astryx templateand the shadcn Install item still replace each fixture with a placeholder (spec:AST-028FR7); their output is unchanged.Problem and solution fit
/templatesand the landing page are where people first see the templates.One delta: a Webpack loader (
scripts/template-image-loader.mjs) rewrites each PNG or JPEG fixture reference to its/_next/imageURL, in the modules a preview renders only: page templates, and the block copies undersrc/generated/showcasesandsrc/generated/examples. The optimizer returns the same picture as WebP at its own pixel size. It never enlarges, so a request at 1920 pixels wide keeps every image that is not wider.The loader finds references with the CLI's own scanner, so a preview and a copy agree on what a fixture reference is. To share it,
replaceDemoMediainpackages/cli/foundation/discovery/template-adapter.mjsnow runs onmapFixtureRefs(source, map), which takes the replacement as a function. No behavior change in the CLI: a copy passes the same placeholders, and its tests are unchanged and pass. The Changeset is[chore] Internal.Not in this PR: a
srcsetthat matches the size of the scaled tile. A prototype took the same first screen to 0.25 MB, but it needs a replacement<img>component for template sources and the tile's scale passed to it. That is a separate decision.Authority
spec:AST-028FR4 (previews show the real fixture; a rewrite leaves the portable template source unchanged): the optimizer serves the same picture from the same file, and the rewrite happens in the build's copy of the module. Template sources underpackages/cli/assets/templates/are not edited.spec:AST-028FR5 (references stay deterministic and never resolve to an unrelated file): each URL names its fixture path (/_next/image?url=%2Ftemplate-assets%2F<file>) with one fixed width and quality.spec:AST-028FR6 (a missing or unsupported fixture fails visibly): the loader rewrites a reference only whenpublicserves a file at the path. A missing file keeps its path, so the browser's failed request still names it, as today. A reference that the scanner cannot replace safely fails the build with the reference in the message, as it fails a copy. Video and vector images are not rewritten, so no fixture renders as another media kind.spec:AST-033FR23 (surfaces that hand out source): the Webpack rule matches only modules that render. The Code tab, Open in Playground, the Sandbox code view, MCPget(), and the shadcn registry read template source through other paths, and their output is unchanged.scripts/template-icon-loader.mjs, which also rewrites preview modules with the CLI's own rewrite.Change and evidence
@2xproduct photos (2048 px) andbuilding.png(6000 px) are wider than 1920 px and come back 1920 px wide.does-not-exist-*.jpgfallback fixtures on/components/Avatarstill fail to load, as they do today.public/shadcnand the generated registries contain no/_next/imageURL.Nature-1.mp4and the two missing fallback fixtures as written./template-assets/PNG or JPEG remains on/templates, theproduct-gallerydialog,/components/Avatar(except the two fixtures) or/components/AspectRatio. Console output is unchanged.Cost: each image is transformed once per format and then cached. This PR requests one width per image, so at most 99 transformations per cache period.
Scope
Components: docsite build configuration, docsite template previews
Testing
template-image-loader.test.tschecks the rewrite, a reference with a query or an upper-case suffix, the references it leaves alone, that no served PNG or JPEG in the template catalog is left out, the build-cache dependencies, the Webpack rule's reach, and that the width and quality are ones the optimizer allows.template-adapter.fixture-refs.test.mjsadds two tests formapFixtureRefs.pnpm review:prereports 0 findings.The byte and timing figures above come from a local production build of the first commit. The second commit changes how references are found, not which of the existing references are rewritten (170 before and after).
Preview deployment of this head (
abf73d3b0d, deploymentdpl_BUrX94Nv5YmWw4TbrrBmeLx8Mcgj), headless Chromium at 1440×900, every image request recorded (spec:AST-028FR4–FR6 verification):/_next/image/template-assets/PNG or JPEG requests/templatesimage/webp/templates?preview=product-gallery(dialog open)image/webp/templates?preview=login-sso(dialog open, CSS background)image/webpThe dialog pages include the gallery tiles behind the dialog. In the
product-gallerydialog all six images load through the optimizer; five reuse a URL that a tile already loaded, so the page makes one more request. In thelogin-ssodialog the one fixture, a CSS background (building.png), loads through the optimizer.Not tested: Safari.