Skip to content

inconsistent or duplicate elements rendered when using preact standalone version #159

@catdad

Description

@catdad

I created a small repro demo that I set up in two ways:

Code:

//import { html, render } from 'https://cdn.jsdelivr.net/npm/[email protected]/preact/standalone.module.js';
//import { Fragment } from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/preact.module.js';

import { h, render, Fragment } from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/preact.module.js';
import htm from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/htm.module.js';
const html = htm.bind(h);

const elem = document.querySelector("#app");

const Item = (item) => {
	return html`
  	<div key=${item.id} data-id=${item.id}>
      ${item.text}
    </div>`;
};

const items = [{id: 1, text: 'one'}, { id: 2, text:'two' }];

const performRender = () => {
  const children = items.map(item => html`<${Item} ...${item} />`);
  render(html`<${Fragment}>${children.reverse()}<//>`, elem);
};

setTimeout(() => {
  items.push({ id: 3, text: 'three'});
  performRender();
}, 1000);

setTimeout(() => {
  items.push({ id: 4, text: 'four'});
  performRender();
}, 2000);

window.onload = performRender;

Fiddle for reference: https://jsfiddle.net/0ukweoz1/2/

Results:

  • when using preact with htm, the final version renders as:
four
three
two
one
  • using htm preact standalone, the final version renders as:
four
three
two
one
one

note that also, the render after 1 second does not actually update the DOM, so three is never just added by itself

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