question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

State transformation in useEntity hangs browser

See original GitHub issue

Describe the bug Trying to use Array.map inside tranform argument hangs Chrome 91

Getting Too many re-renders. React limits the number of renders to prevent an infinite loop

To Reproduce Create an entity with items property and try to use in useEntity with some transformations

// In state file
const StateEntity = entity({ items: [/*your items*/] })

// In component
const items = useEntity(StateEntity, s=> s.items.map(x => ({...x, newProp: true}));

(https://codesandbox.io/s/zealous-almeida-l9qs6?file=/src/App.tsx)

Expected behavior State transforms as it updates and doesn’t hang browser

Desktop (please complete the following information):

  • OS: Windows 10 Pro 21H1
  • Browser: Chrome
  • Version: 91.0.4472.164

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arnelenerocommented, Jul 28, 2021

Thanks for the suggestion. It might work to just combine these:

  useIsoEffect(() => entity._subscribe(subscriberFn), [subscriberFn, entity])

  // Re-sync state in case transform function has changed
  subscriberFn(entity._value)

into

  useIsoEffect(() => {
     // Re-sync state in case transform function has changed
     subscriberFn(entity._value)
  
     return entity._subscribe(subscriberFn)
  }, [subscriberFn, entity])

I will have to run tests against this, though.

0reactions
arnelenerocommented, Feb 20, 2022

After revisiting this I can confirm that the original code, where the subscriberFn is called to re-sync state in case the transform function has changed, is indeed intentional and safe. It will not cause any re-render unconditionally because subscriberFn performs comparison with current entity value. Therefore, the discussed enhancement above would not provide the intended result.

There has been no reported issues that are similar to the original issue reported here, and the original sandbox currently appears to be working as intended.

Due to the above, I am closing this issue. We can reopen if a similar issue resurfaces.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Browser freezes upon opening state history - Frontend
... I open entity details in the frontend of Lovelace, the browser freezes when loading the state history as you can see in...
Read more >
Performance considerations for EF 4, 5, and 6 - Microsoft Learn
Query views: these represent the transformation necessary to go from ... DetectChanges synchronizes the object graph with the object state ...
Read more >
Dashboard browsing URL format - Axway Documentation Portal
Introduction As you work with Axway Decision Insight (DI), the browser URL is updated to reflect the current application state.
Read more >
Browser freezing when using React Hook - Stack Overflow
When you call setState() in the fetchUsername function, your component's state variable is updated. The problem is that when the state ...
Read more >
Designing Enterprise Applications - UCI Canvas
While many applications can be distributed to Web browser clients ... tion, XSLT transformations, internationalization, state access, and HTML forms.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found