near / bos-web-engine

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

Fix infinite loop on the container subtree run #422

Closed pavelisnear closed 7 months ago

pavelisnear commented 7 months ago

This one-liner is fixing the infinite loop, causing the browser page to freeze.

Before merging this PR, this component would hit a loop after hitting the button to increment a value:

import { useState } from 'react';

function Child() {
  const [countChild, setCountChild] = useState(0);
  const handleClick = () => setCountChild((x) => x + 1);

  return (
    <div>
      <button onClick={handleClick}>++</button>
      child: {countChild}
    </div>
  );
}

export default function () {
  return (
    <div>
      <h1>Callback</h1>
      <Child />
    </div>
  );
}

This fix resolves the issue.

vercel[bot] commented 7 months ago

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

Name Status Preview Updated (UTC)
bos-web-engine ✅ Ready (Inspect) Visit Preview Apr 18, 2024 6:32pm
bos-web-engine-docs ✅ Ready (Inspect) Visit Preview Apr 18, 2024 6:32pm
bos-web-engine-sandbox ✅ Ready (Inspect) Visit Preview Apr 18, 2024 6:32pm