Why my image is not hydrating correctly when Svelte initializes

This article came from a real issue debugging a hydration mismatch where images looked correct at first render but reloaded and caused a layout shift.

In short, if server-rendered HTML for an image and client render do not align, Svelte can replace nodes during hydration.

For my case, this surfaced when a generated set of image props was spread into <img /> output from an adapter layer. One attribute mismatch was enough to force replacement behavior.

The practical fix is:

Related deep-dive topics: