-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inconsistent or duplicate elements rendered when using preact standalone version #159
Comments
Hi @catdad - this happens because you are using two copies of Preact - Some context - the reason we don't export However: it looks like the copy of Preact we bundled with htm 3.0.3 has a bug with fragments at the root, or our bundling is breaking something. That's a bug. Here's your demo without the Fragment usage: // should work, but seems to have an issue with bundled preact and fragments:
//import { html, render } from 'https://cdn.jsdelivr.net/npm/htm@3.0.3/preact/standalone.module.js';
import { h, render } 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`${children.reverse()}`, elem);
};
setTimeout(() => {
items.push({ id: 3, text: 'three'});
performRender();
}, 1000);
setTimeout(() => {
items.push({ id: 4, text: 'four'});
performRender();
}, 2000);
window.onload = performRender; |
Fix render() in standalone build (fixes #159)
This has been fixed! It's available on unpkg and npm as htm 3.0.4. |
I created a small repro demo that I set up in two ways:
preact@10.3.4
withhtm@3.0.3
htm@3.0.3
with 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
three
is never just added by itselfThe text was updated successfully, but these errors were encountered: