Repository navigation
perf(docsite): load the /themes showcase photos through the image optimizer, ahead of a theme switch - #11369
perf(docsite): load the /themes showcase photos through the image optimizer, ahead of a theme switch#11369nynexman4464 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
Generated by PR Enrichment workflow | View current CI run |
There was a problem hiding this comment.
Changes requested: one fix is needed before approval. The rest of the change matches its description: the photo URLs, the shared URL helper (the template loader's output is unchanged), the data-saving and 2G checks, and the unmount cleanup.
apps/docsite/src/components/themeShowcaseWarmup.tslines 54-59 re-implementwhenIdlefromapps/docsite/src/lib/searchWarmup.ts, so please build the cancel fromwhenIdle(load, …)and delete the local copy, which keeps the docsite on one idle scheduler (the hero reel's photo warm-up inHeroThemeReel.tsxcould share the same helper).
Non-blocking: the header of themeShowcaseWarmup.ts says the 30 photos are about 0.7 MB in all, while the description and commit message say about 0.6 MB.
Claims and files checked
- Claim: the showcase PNGs are 0.5 to 1.2 MB each and 700 to 1029 px wide. Verified: 559 KB to 1.19 MB; 700, 704 and 1029 px.
- Claim: one theme switch requests 3.7 to 6.7 MB of PNG today. Verified approximately: the six files total 3.8 to 6.8 MB per theme.
- Claim: each photo is named by an optimizer URL at 828 px, so 700 px photos keep their size and Matcha comes back 828 wide. Verified in code (
themeShowcaseContent.tslines 28-32); the served widths were not observed. - Claim: one function writes the optimizer URL and
templateImageUrlgives the same output. Verified:optimizedImageUrl.mjslines 24-26 andtemplate-image-loader.mjslines 38-40 produce the same string as before. - Claim: the warm-up requests every bespoke photo once in idle time and the page holds the images while mounted. Verified:
themeShowcaseWarmup.tslines 46-59 andThemePackagePage.tsxlines 459-467. - Claim: the warm-up does nothing in a data-saving mode or on 2G. Verified:
themeShowcaseWarmup.tslines 22-28 and the new test. - Claim: unmounting cancels a warm-up that has not started. Verified:
ThemePackagePage.tsxlines 463-466. - Claim: the warm-up is 591 KB in all and a data-saving switch costs 68 to 182 KB. Consistent: a quality-75 WebP re-encode at 828 px totals about 588 KiB, 70 to 187 KB per theme.
- Claim: the warm-up costs less than one photo does today. Mostly true: it is below 28 of the 30 PNGs; two Gothic photos are 559 KB and 591 KB.
- Claim: switch timings, zero photo requests after the warm-up, and WebP responses with status 200. Not reproduced.
- Claim: the Neutral defaults, picker thumbnails and
@2xfiles are unchanged. Verified: none is referenced by the diff. - Claim: the docsite spec has no rule on loading these photos, and the template fixture rules do not cover them. Verified.
- Claim: the new Effect names the system it syncs and cleans up. Verified; the cited runtime record covers the component packages, not the docsite.
- Claim: the docsite build, typecheck, tests and pre-review check pass. Not reproduced; CI has not run on this draft head.
- File
apps/docsite/src/components/themeShowcaseWarmup.ts: blocking finding above, plus the size note. - File
apps/docsite/src/components/ThemePackagePage.tsx: clear. - File
apps/docsite/src/components/themeShowcaseContent.ts: clear. - File
apps/docsite/src/lib/optimizedImageUrl.mjs: clear. - File
apps/docsite/scripts/template-image-loader.mjs: clear. - File
apps/docsite/src/__tests__/theme-showcase-photos.test.ts: clear. - File
apps/docsite/src/__tests__/theme-showcase-warmup.test.ts: clear; it would need its timer-fallback case updated with the scheduler change.
| if (typeof window.requestIdleCallback === 'function') { | ||
| const handle = window.requestIdleCallback(load); | ||
| return {images, cancel: () => window.cancelIdleCallback(handle)}; | ||
| } | ||
| const handle = window.setTimeout(load, 200); | ||
| return {images, cancel: () => window.clearTimeout(handle)}; |
There was a problem hiding this comment.
These lines re-implement whenIdle from apps/docsite/src/lib/searchWarmup.ts (idle callback with its cancel, else a timer with its cancel), which the search warm-up already uses. Please build the cancel from it and drop the local branches, for example return {images, cancel: whenIdle(load, 200)};. Note that whenIdle also caps the idle wait at twice the fallback delay, so pick the fallback with that in mind.
…imizer, ahead of a theme switch A theme switch on /themes swaps in six product photos. Each one is a PNG of 0.5 to 1.2 MB under `public/images/<theme>/`, and the page requests it only when the theme renders, so the product cards stay empty while 3.7 to 6.7 MB arrive. The photos now load through the image optimizer, as the template fixtures do. One function writes the optimizer URL for both. The page also requests every theme's photos in idle time, about 0.6 MB in all, and holds them, so a theme switch needs no request. It skips that for a visitor in a data-saving mode or on a 2G link.
d237024 to
9420780
Compare
Primary intent
Make a theme switch on
/themesshow its product photos at once. 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 picks a theme on
/themes. The showcase swaps in six product photos for the theme. Each one is a PNG of 0.5 to 1.2 MB underpublic/images/<theme>/, and the page requests it only when the theme renders. The product cards stay empty until the files arrive.Headless Chromium at 1512×882, device scale 2. "Before" is the live site, "after" is a local production build (
next start) of this branch. Times run from the click on a theme to the moment the three visible photos are complete.The warm-up requests the 30 photos of the five themes with bespoke content once, in idle time: 591 KB in all. That is less than one photo costs today.
Problem and solution fit
public/images/<theme>/, 700 to 1029 pixels wide, for a card that shows them about 280 CSS pixels wide./template-assets/. These photos are docsite content thatthemeShowcaseContent.tspasses to the showcase template through itsimagesprop.Every delta maps to that:
themeShowcaseContent.tsnames each photo by its image optimizer URL at 828 pixels wide. The optimizer does not enlarge, so the 700-pixel photos keep their pixel size, and the Matcha photos (1029 pixels) come back 828 wide.src/lib/optimizedImageUrl.mjswrites the optimizer URL. The template image loader from perf(docsite): serve template preview images through the image optimizer #11320 now calls it too, so the URL form has one definition.templateImageUrlkeeps itswidthparameter from perf(docsite): render the landing templates card previews at build time #11292 and gives the same output as before, so the landing preview generator's URLs do not change.themeShowcaseWarmup.tsrequests every bespoke photo once the page is idle and returns the images.ThemePackagePageholds them in a ref while it is mounted, so a theme switch finds them in the browser's cache and sends no request. It does nothing when the browser reports a data-saving mode or a 2G link, and it cancels a warm-up that has not started when the page unmounts.Not changed: the Neutral defaults (template fixtures, already optimized by #11320), the theme picker thumbnails, and the unused
@2xfiles.Authority
spec:AST-033governs the docsite. It has no requirement on how/themesloads its showcase photos, and this changes no behavior it describes: the same photos show for the same theme.spec:AST-028FR4 to FR6 govern template fixtures under/template-assets/. These photos are not template fixtures. The showcase template and its fixture references are not edited.architecture:react-component-runtimeINV3 and INV5: the one new Effect names the system it syncs (the browser's image cache), and its cleanup cancels the pending warm-up and releases the held images.Change and evidence
navigator.connection.saveDataset, the page requests no photo ahead of time, and a switch requests the theme's six photos through the optimizer (68 to 182 KB).image/webpwith status 200. The photos are 700 or 704 pixels wide as before, and 828 for Matcha.Preview deployment of
d237024a36, the same measurement, the five themes in each row. That commit is this change before its rebase onto #11292; the rebase only resolvedtemplateImageUrl, and the same measurement on the rebased head follows.image/webp, status 200Scope
Components: docsite /themes showcase content, docsite ThemePackagePage, docsite template image loader
Testing
theme-showcase-photos.test.tschecks that each of the 30 photos is an optimizer URL for a file thatpublicserves, at a width and quality the optimizer allows, and that the warm-up list holds each photo once.theme-showcase-warmup.test.tschecks that the warm-up waits for idle time, requests every photo, can be cancelled, does nothing in a data-saving mode or on 2G, and falls back to a timer withoutrequestIdleCallback.pnpm review:prereports 0 findings.Not tested: Safari and Firefox.