State transformation in useEntity hangs browser
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the suggestion. It might work to just combine these:
into
I will have to run tests against this, though.
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 becausesubscriberFn
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.