Repository navigation
🚨 unwelcome pr from bot 🚨 - #2382
Closed
officialasishkumar wants to merge 1 commit into
Closed
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
`<NuxtImg>` can show a low quality placeholder while the real image is loading, but `<NuxtPicture>` had no equivalent, so the logic was limited to a single component. `<NuxtPicture>` now accepts the same `placeholder` values as `<NuxtImg>` (boolean, number, `[w, h, q, b]` tuple or a custom URL) plus `placeholderClass`: - While the placeholder is shown, a plain `<img>` is rendered without any `<source>`, so the browser never fetches the real formats early. A generated placeholder uses the legacy format (jpeg/png) so it works everywhere. - On mount the real image is loaded off-screen through a detached `<picture>` using the very same `<source>` candidates, so the browser picks the same format and size it would pick for the final markup. When it has loaded (and decoded; a failed decode does not block the swap) the sources are rendered, the same `<img>` element is kept, and `load` is emitted. A load failure emits `error`. - SVG sources are never given a placeholder, and the generated placeholder is prerendered with the rest of the images. The parsing of the `placeholder` prop is extracted into a shared `resolvePlaceholder()` helper that `<NuxtImg>` now uses too, without any behaviour change. Tests cover the markup before/after load, all accepted placeholder values, the legacy format, `placeholderClass`, error/decode failure handling, SVG and the unchanged default markup. Docs describe both props. The bundle size snapshot is bumped for the added runtime code. Resolves nuxt#1160
Contributor
nuxt.com previewA maintainer can add the |
Contributor
|
We've flagged this as a potential contribution without a human behind it. We welcome the thoughtful use of AI tools when contributing, but ask all contributors to follow two core principles:
Please review these AI-assisted contribution guidelines and update this contribution if needed. We're closing this for now as the account looks automated. If we got that wrong, please just reopen the PR and we'll take another look. |
placeholder and placeholderClass props
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.
🔗 Linked issue
Resolves #1160
❓ Type of change
📚 Description
<NuxtPicture>now supports the sameplaceholdervalues as<NuxtImg>(boolean, number,[w, h, q, b]or a custom URL) andplaceholderClass.<img>is rendered with no<source>elements, so the real formats are not fetched early. A generated placeholder uses the legacy format.<picture>with the same<source>candidates, so the browser picks the same format/size as it would for the final markup. Once loaded (a faileddecode()doesn't block the swap) the sources are rendered, the same<img>element is kept, andloadis emitted; failures emiterror.resolvePlaceholder()helper, also used by<NuxtImg>(no behaviour change).Tests and docs are included. The bundle size snapshot is bumped (+~1.1k measured locally) for the added runtime code; the exact rounded value may need adjusting if CI differs slightly.