snabbdom-pragma icon indicating copy to clipboard operation
snabbdom-pragma copied to clipboard

Fix zero in text node

Open tpresley opened this issue 3 years ago • 0 comments

Numbers in text nodes are not converted to strings, so the number zero is treated as 'falsy' by snabbdom. This can cause problems with dynamically changing values when patching the DOM.

Example:

// this works as expected
() => <div>1</div>
// renders to { children: undefined, sel: 'div', text: 1, ... }

// this does not work properly
() => <div>0</div>
// renders to { children: [{ children: undefined, sel: undefined, text: 0, ... }], sel: 'div', text: undefined, ... }

The fix in this PR just converts the results of sanitizeText to a string, which fixes the issue with numeric zero

Resolves #43

tpresley avatar Jun 01 '22 08:06 tpresley