nuxt / nuxt/image

Attributes (`href`, `imagesrcset`) not properly encoded in `link` `preload` tags (leading to `unrecognized-char-ref` errors in Nuxt Hints)

Open
#2,178 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
331
Avg merge
19h 52m
Merged PRs (30d)
9

Description

Consider this usage of NuxtImg:

<NuxtImg
  src="/my-image.png"
  :modifiers="{ w: 200, q: 10 }"
  preload
/>

This results in the following link tag in the html head:

<link
  rel="preload"
  as="image"
  href="/_ipx/w_200&q_10/coopsman.png"
  imagesrcset="/_ipx/w_200&q_10/coopsman.png 1x, /_ipx/w_200&q_10/coopsman.png 2x"
/>

The ampersand in the URLs should be encoded as &amp; and Nuxt Hints (via the html-validate package) lists this as an error:
hints:htmlValidate:warn [html-validate] unrecognized-char-ref at inline:39:24 - Unrecognized character reference "&q"

Reproduction:
https://stackblitz.com/edit/nuxt-starter-vpusa6kt?file=app.vue

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked StackBlitz reproduction and trace how NuxtImg generates preload link attributes for modifier URLs. Confirm that href and imagesrcset encode ampersands as & and that the resulting markup no longer produces the reported html-validate warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.