I created a small repro demo that I set up in two ways:
- using
preact@10.3.4 with htm@3.0.3
- using only
htm@3.0.3 with the preact standalone version of the module
Code:
//import { html, render } from 'https://cdn.jsdelivr.net/npm/htm@3.0.3/preact/standalone.module.js';
//import { Fragment } from 'https://cdn.jsdelivr.net/npm/preact@10.3.4/dist/preact.module.js';
import { h, render, Fragment } from 'https://cdn.jsdelivr.net/npm/preact@10.3.4/dist/preact.module.js';
import htm from 'https://cdn.jsdelivr.net/npm/htm@3.0.3/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:
- using htm preact standalone, the final version renders as:
note that also, the render after 1 second does not actually update the DOM, so three is never just added by itself
I created a small repro demo that I set up in two ways:
preact@10.3.4withhtm@3.0.3htm@3.0.3with the preact standalone version of the moduleCode:
Fiddle for reference: https://jsfiddle.net/0ukweoz1/2/
Results:
note that also, the render after 1 second does not actually update the DOM, so
threeis never just added by itself