van icon indicating copy to clipboard operation
van copied to clipboard

van.hydrate is not working correctly?

Open creatormir opened this issue 7 months ago • 3 comments
trafficstars

I expect that when calling hydration, the entire DOM will be preserved and all reactivity/interactivity and events will be bound to it. However, I see that when calling hydration, all (even static) DOM is rendered. Is this incorrect work of van.hydrate or am I doing something wrong? For example, I modified the basic example: https://codesandbox.io/p/devbox/solitary-dream-fmqz28 Similar example in Vue (no re-rendering occurs): https://stackblitz.com/edit/vue-ssr-example-irrowjm5?file=client.js (auto-activation of hydrate after 7 seconds)

creatormir avatar Mar 19 '25 04:03 creatormir

as mentioned in the document https://vanjs.org/ssr#hydration van.hydrate replaces the SSR component

sirenkovladd avatar Mar 19 '25 05:03 sirenkovladd

In that case, it's strange that it's called hydrate. It's more correct to call it replace or update. The point of hydration is to not run rendering and bind reactivity to the existing DOM.

creatormir avatar Mar 19 '25 06:03 creatormir

I believe it's the callers of hydrate to ensure the new DOM hydrated element has the same semantic of the existing static element. It's the choice of implementation details in VanJS where we decided replacing the DOM element is the way to hydrate.

Tao-VanJS avatar Mar 20 '25 16:03 Tao-VanJS