You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current SSR/hydration mechanism in Svelte (especially noticeable in Svelte 5) heavily relies on inserting empty or structured comment nodes (like , ) into the DOM to keep track of dynamic blocks, lists, and conditionals.
While this works from a functional standpoint, it severely impacts the developer experience (DX). Inspecting the DOM in Browser DevTools becomes incredibly cluttered, making it difficult to read the actual semantic HTML structure. In large applications with complex lists or deeply nested components, the amount of comment nodes sometimes matches or exceeds the number of actual DOM elements.
Describe the solution you'd like
I would like to propose replacing comment-based hydration markers with a more elegant approach, such as using specific data-* attributes on existing DOM elements, or at least minimizing the footprint of these markers.
For example, instead of wrapping a block like this:
<divclass="user-card">
John Doe</div>
We could attach hydration metadata directly to the parent or specific elements:
<divclass="user-card" data-sv-hydrate="...">
John Doe
</div>
If a virtual boundaries-only marker is absolutely required (e.g., for text nodes or fragments without a wrapper), a single descriptive data-attributed element or a more compact approach could be used, rather than scattering open/close comments everywhere.
Describe alternatives you've considered
Keeping comments but stripping them in a specific "DevTools clean mode" (likely hard to implement on the browser side).
Accepting the DOM pollution, which hurts the original Svelte promise of outputting clean, minimal HTML.
Additional context
Frameworks like Vue and Nuxt have historically managed to keep their hydration footprint relatively clean, and moving towards standard HTML5 data- attributes feels more robust, modern, and friendly for developers who spend a lot of time in the elements panel.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The current SSR/hydration mechanism in Svelte (especially noticeable in Svelte 5) heavily relies on inserting empty or structured comment nodes (like
,) into the DOM to keep track of dynamic blocks, lists, and conditionals.While this works from a functional standpoint, it severely impacts the developer experience (DX). Inspecting the DOM in Browser DevTools becomes incredibly cluttered, making it difficult to read the actual semantic HTML structure. In large applications with complex lists or deeply nested components, the amount of comment nodes sometimes matches or exceeds the number of actual DOM elements.
Describe the solution you'd like
I would like to propose replacing comment-based hydration markers with a more elegant approach, such as using specific
data-*attributes on existing DOM elements, or at least minimizing the footprint of these markers.For example, instead of wrapping a block like this:
We could attach hydration metadata directly to the parent or specific elements:
If a virtual boundaries-only marker is absolutely required (e.g., for text nodes or fragments without a wrapper), a single descriptive data-attributed element or a more compact approach could be used, rather than scattering open/close comments everywhere.
Describe alternatives you've considered
Additional context
Frameworks like Vue and Nuxt have historically managed to keep their hydration footprint relatively clean, and moving towards standard HTML5
data-attributes feels more robust, modern, and friendly for developers who spend a lot of time in the elements panel.All reactions