Problem
ALGO.html is a tagged template function but it sets document.body.innerHTML instead of returning an element:
// Expected:
const el = ALGO.html\`<div>hello</div>\`;
el.textContent; // "hello"
// Actual:
ALGO.html\`<div>hello</div>\`; // returns undefined, sets body
Impact
- Confusing for developers expecting jQuery-like behavior
- The Code Metrics app failed silently because:
const canvas = ALGO.html\`<canvas></canvas>\`; // undefined!
canvas.getContext("2d"); // Error: cannot read 'getContext' of undefined
Options
- Document clearly - Add JSDoc/comments explaining it sets body
- Rename - Call it
ALGO.setBody() or ALGO.render()
- Change behavior - Make it return the created element(s)
- Add alternative - Keep current + add
ALGO.create() that returns element
Workaround
Use standard DOM:
const canvas = document.createElement('canvas');
canvas.width = 400;
Problem
ALGO.htmlis a tagged template function but it setsdocument.body.innerHTMLinstead of returning an element:Impact
Options
ALGO.setBody()orALGO.render()ALGO.create()that returns elementWorkaround
Use standard DOM: