Skip to content

🚨 unwelcome pr from bot 🚨 - #2382

Closed
officialasishkumar wants to merge 1 commit into
nuxt:mainfrom
officialasishkumar:feat/nuxt-picture-placeholder
Closed

officialasishkumar wants to merge 1 commit into
nuxt:mainfrom
officialasishkumar:feat/nuxt-picture-placeholder

Conversation

@officialasishkumar

Copy link
Copy Markdown

🔗 Linked issue

Resolves #1160

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

<NuxtPicture> now supports the same placeholder values as <NuxtImg> (boolean, number, [w, h, q, b] or a custom URL) and placeholderClass.

  • While the placeholder is shown, a plain <img> is rendered with no <source> elements, so the real formats are not fetched early. A generated placeholder uses the legacy format.
  • On mount the real image is loaded off-screen through a detached <picture> with the same <source> candidates, so the browser picks the same format/size as it would for the final markup. Once loaded (a failed decode() doesn't block the swap) the sources are rendered, the same <img> element is kept, and load is emitted; failures emit error.
  • SVGs get no placeholder; generated placeholders are prerendered with the other images.
  • The prop parsing is extracted to a shared 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.

`<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
@github-actions

Copy link
Copy Markdown
Contributor

nuxt.com preview

A maintainer can add the preview:enabled label to preview this pull request on nuxt.com.

@github-actions

Copy link
Copy Markdown
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:

  1. Never let an LLM speak for you - all comments, issues, and PR descriptions should be written in your own words, reflecting your own understanding.
  2. Never let an LLM think for you - only submit contributions you fully understand and can explain.

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.

@github-actions github-actions Bot changed the title feat(nuxt-picture): support placeholder and placeholderClass props 🚨 unwelcome pr from bot 🚨 Nov 11, 2026
@github-actions github-actions Bot closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Placeholder for NuxtPicture

1 participant