Skip to content

Only last element renders when reusing #401

@sidvishnoi

Description

@sidvishnoi

I maybe misunderstanding how hyperHTML works, but in the first case of the example below, only the last usage of icon is rendered. Does hyperHTML move the elements into the DOM instead of cloning them?

See minimal reproduction: https://codepen.io/sidvishnoi/pen/VwaqwzM

// Case 1:
const icon = hyperHTML`<em>🚫</em>`;
for (const num of [1, "2", "3 only last SVG is rendered"]) {
  const contents = [];
  contents.push(hyperHTML`<span>${icon} ${num}</span>`);
  // ... 
  document.getElementById("main1").append(hyperHTML`<h2>${contents}</h2>`);
}

// Case 2:
for (const num of [4, 5, 6]) {
  const icon = hyperHTML`<em></em>`;
  const contents = [];
  contents.push(hyperHTML`<span>${icon} ${num}</span>`);
  // ...
  document.getElementById("main2").append(hyperHTML`<h2>${contents}</h2>`);
}


console.log(document.getElementById("main1").innerHTML);
console.log(document.getElementById("main2").innerHTML);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions