van icon indicating copy to clipboard operation
van copied to clipboard

Cannot update dom when initial state is undefined or null

Open cubxx opened this issue 4 months ago • 1 comments

const s = van.state();
van.add(document.body, van.tags.div(() => s.val));
s.val = 'new';

The initial s.val is undefined, so vanjs won't create a DOM to bind with the state. Maybe creating an empty TextNode is a solution.

cubxx avatar Oct 07 '25 09:10 cubxx

This is intended behavior. Because in the binding function for a child DOM node, returning undefined or null means you want to delete that node. See the Removing a DOM node section in VanJS tutorial.

Tao-VanJS avatar Oct 21 '25 17:10 Tao-VanJS