Skip to content

Hydration attribute mismatch in HTML because of translation on img alt attribute #3881

@mrleblanc101

Description

@mrleblanc101

Environment


  • Operating System: Darwin
  • Node Version: v20.19.2
  • Nuxt Version: 4.2.1
  • CLI Version: 3.30.0
  • Nitro Version: 2.12.9
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, compatibilityDate, nitro, vite, i18n
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

https://github.com/mrleblanc101/repro-nuxt-i18n-node-mismatch

Describe the bug

If I add :alt="t('Ville de Québec l’accent d’Amérique')" this to my <img src="...">, then I get a Hydration attribute mismatch if i run pnpm build && pnpm preview.

<img
    class="quebec-city-logo"
    src="@/assets/img/ville-quebec.svg"
    :alt="t('Ville de Québec l’accent d’Amérique')"
    width="276"
    height="81"
/>

Hydration attribute mismatch on <img class="quebec-city-logo" src="/_nuxt/ville-quebec.Ctek8D92.svg" alt="Partenaires" width="276" height="81">

Everything is fine if I run pnpm run dev.

Image

Notice that, on the server-side, the domain is not in the url, but on the client it is.
I think this is what is causing the mismatch.

These alt don't seem to cause problem:

<img
    class="quebec-city-logo"
    src="@/assets/img/ville-quebec.svg"
    :alt="'Ville de Québec l’accent d’Amérique'"
    width="276"
    height="81"
/>
<img
    class="quebec-city-logo"
    src="@/assets/img/ville-quebec.svg"
    alt="Ville de Québec l’accent d’Amérique"
    width="276"
    height="81"
/>

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions