fix(home): discover showcase screenshots via a build-time virtual module - #652
Merged
Conversation
The homepage showcase carousel rendered nothing in production: no slides,
the container collapsed to 2px, and the screenshot preloads were reported as
unused. The testimonial carousel on the same page was fine.
Not a swiper problem. `AppShowcaseSlider` built its slide list with
import.meta.glob('~~/public/img/screenshots/*.(png|jpe?g|webp)')
and glob cannot see into `public/`: Vite deliberately keeps that directory
out of the module graph. The dev server resolves such patterns off the
filesystem, so it looked correct locally, while the deployed bundle shows
the call compiled down to
Object.keys(Object.assign({}))
an empty object, so `images` was `[]` and the carousel had nothing to render.
It only started failing with the vite 8 upgrade; vite 7 still resolved it.
Replaces the glob with an `app-screenshots` module that reads the directory
at build time and exposes it as `virtual:app-screenshots`, keeping the list
auto-discovered rather than hand-maintained. Files are sorted naturally so
`10-…` would follow `9-…`, only files directly in the folder count (the
`responsive/` subfolder holds width variants of the first slide, not slides),
and the dev server invalidates the module when a screenshot is added or
removed. If the folder is ever empty the build warns rather than silently
shipping an empty carousel, which is what made this so quiet.
Verified against a production build: the client and server bundles now both
contain all 7 screenshot paths, where the deployed ones contain none, and
`Object.assign({})` is gone. Confirmed in the browser: 7 slides, carousel
792px tall, first screenshot visible.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #652 +/- ##
==========================================
+ Coverage 27.92% 27.93% +0.01%
==========================================
Files 391 391
Lines 12456 12449 -7
Branches 1732 1732
==========================================
Hits 3478 3478
+ Misses 8879 8872 -7
Partials 99 99
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The homepage showcase carousel renders nothing in production: no slides, the container collapsed to 2px, and the screenshot preloads reported as "preloaded but not used". The testimonial carousel on the same page, using the same swiper version, is fine.
Not swiper
AppShowcaseSliderbuilt its slide list withimport.meta.globcannot see intopublic/— Vite deliberately keeps that directory out of the module graph. The dev server resolves such patterns off the filesystem, so it looks correct locally; the build has nothing to enumerate.From the currently deployed bundle (
AppShowcaseSlider-579d3be2.dAERDHky.js):The glob compiled to
Object.assign({})— an empty object. Soimageswas[]and the carousel had no slides to render. Vite 7 still resolved the pattern, which is why this only appeared with the vite 8 upgrade (#649).Fix
An
app-screenshotsNuxt module reads the directory at build time and exposes it asvirtual:app-screenshots, so the list stays auto-discovered rather than becoming a hand-maintained array someone has to remember to update.localeCompare(..., { numeric: true }), so a future10-…sorts after9-…instead of after1-….responsive/subfolder holds pre-generated width variants of the first slide, not slides of its own.Alt text stays in the component, keyed by filename, since it is copy rather than build data.
Verification
Against a real production build, comparing bundles:
Object.assign({})empty-globAnd in the browser: 7 slides, carousel 792px tall (was 2px), first screenshot visible, pagination and arrows working. Testimonial carousel unaffected at 14 slides.
typecheck clean, lint clean (68 pre-existing warnings, 0 errors), 502 tests pass.
Note for reviewers
pnpm generatecurrently fails on my machine with a nitro CSS-chunk placeholder error (Could not resolve "./entry-styles-3.mjs-<buildId>.!~{003}~.js"). That reproduces on unmodifiedmaintoo and does not happen in CI, so it is environmental and unrelated to this change — but worth knowing if you hit it locally.