Skip to content

Error in 5.0.9 #157

@autonome

Description

@autonome

Test case:

import { html, signal } from './uhtml.js';

const items = signal([]);

const ListItem = ({item}) =>
  html`<li>${item.text}</li>`;

const List = ({items}) =>
  html`<ul>
    ${items.value.map((item) =>
      html`<${ListItem} item=${item} />`
    )}
  </ul>`;

document.body.append(
  html`<${List} items=${items} />`
);

for (let i = 0; i < 3; i++) {
  items.value = [...items.value, ({text: `item ${i}`})];
}

The loop errors on the 3rd iteration:

Uncaught TypeError: can't access property "text", item is undefined

If I inline the li into List instead of a separate function, no error.

If I don't wrap the item in an object, and items is an array of strings, no error.

If I use the component fn directly instead of a nested tagged template, no error, eg:

${items.value.map(item => ListItem({item}))}

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