near / react-on-chain

Improved execution layer for NEAR decentralized frontend components
https://roc-docs.near.dev/
23 stars 5 forks source link

fix: render at the Component/container level #415

Closed andy-haynes closed 1 month ago

andy-haynes commented 1 month ago

This PR updates the container render logic to request renders at the Component level. When the commit hook is triggered on render, the target vnode is the root for the DOM subtree that changed. However the outer application only recognizes changes at the Component/container level. This means if the rendered vnode is the descendant of a Component, that subtree render will replace the entire Component DOM in the outer window. E.g. given

const A = () => (<span>A</span>);
const B = () => (<span>B</span>);
...
<>
  <A />
  <B />
</>

The initial render would print both A and B, but if <A /> were to re-render then only A would be printed. Since the outer application treats all render requests as coming directly from a Component, the updated descendant element overwrites the Component's DOM entirely.

Ideally this subtree rendering would be supported, but this requires a more sophisticated approach to synchronize state across containers and the outer DOM. It seems unlikely that this would yield demonstrable performance benefits in the current implementation, although it may become a less daunting task as the render pipeline matures.

Fixes #399 (https://bos-web-engine-git-fix-399-compon-03c7d9-near-developer-console.vercel.app/bwe-demos.near/NPM.Zustand?showCode=true 🎉 )

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bos-web-engine ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 11:52pm
bos-web-engine-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 11:52pm
bos-web-engine-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 11:52pm