Tram-One / tram-one

🚋 Legacy View Framework For Vanilla Javascript
http://tram-one.io/
MIT License
36 stars 8 forks source link

Effects don't attach when a component is just rendering another component #166

Closed JRJurman closed 2 years ago

JRJurman commented 3 years ago

Summary

While a parent component only renders another component, any effects that would be attached to the child are blown away. This is because the element returned here is just the child element, so any effects get overridden.

https://github.com/Tram-One/tram-one/blob/412b7c9836d704c58e4923c2ec85340f66625ffe/src/process-effects.ts#L19-L20

Potentially we can warn when a parent would only render a child, or merge these effects. It's unclear if merging would be safe, and in reality, I think having a parent that just returns a child is fairly rare.

JRJurman commented 3 years ago

This was found by accident when trying to make performance tests.

const app = () => {
    if (useUrlParams('/element-rendering').matches) return html`<element-rendering />`
    if (useUrlParams('/double-render').matches) return html`<double-render />`
    return html`
        <main>
            <h1>Performance Test App</h1>
        </main>
    `
}
JRJurman commented 3 years ago

Haha, it looks like the logic for #142 might actually cover this. Requires more investigation :microscope: