Skip to content

ALGO.html() doesn't return element - confusing API #7

@williamsharkey

Description

@williamsharkey

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

  1. Document clearly - Add JSDoc/comments explaining it sets body
  2. Rename - Call it ALGO.setBody() or ALGO.render()
  3. Change behavior - Make it return the created element(s)
  4. Add alternative - Keep current + add ALGO.create() that returns element

Workaround

Use standard DOM:

const canvas = document.createElement('canvas');
canvas.width = 400;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions