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.

Maximum call stack size exceeded in react app

See original GitHub issue

Describe the bug

export const Tree: FC<TreeProps> = (props) => { 
  const keyToNodeMap = useRef<KeyToNodeMap>({})
  const [data, setData] = useState<TreeSource>(props.treeData)
  const doTranslate = useCallback((children: Array<TreeSource>, parent: TreeSource)=>{
    children.forEach((item: TreeSource) => {
      item.parent = parent
      keyToNodeMap.current[item.key] = item
      if(item.children && item.children.length > 0) {
        doTranslate(item.children, item)
      }
    })
  }, [])

  useEffect(() => {
    keyToNodeMap.current[data.key] = data
    if(data.children && data.children.length > 0) {
      // doTranslate(data.children, data)        **open this will report the bug** 
    }
  }, [data, doTranslate])

  return (
    <div className={sc('tree')}> 
      <div className={sc('tree-nodes')}>
        <TreeNode
          data={data}
          onCollapse={onCollapse}
          onCheck={onCheck}
        />
      </div>
    </div>
  )
}
export default Tree;

When the page is loaded for the first time, it is fine, but when I switch the sidebar, an error will be reported image

    "@storybook/addon-a11y": "^6.3.2",
    "@storybook/addon-actions": "6.3.2",
    "@storybook/addon-docs": "^6.3.2",
    "@storybook/addon-essentials": "^6.3.2",

To Reproduce

My Project:

https://github.com/ChocolateUI/chocolate-ui/blob/8f30fc55be25ce49cef938fd0427d5759d74077b/src/components/Tree/tree.tsx#L72

System macOS 11.2.3 chrome 91.0.4472.114

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
fikyaircommented, Jul 27, 2021

This part of the reconstruction has been completed, it is a problem with my code, thank you all

1reaction
fikyaircommented, Jul 23, 2021

hello @fikyair, do you have a repository we can check to reproduce this? I tend to share @marko-hologram’s idea but seeing the project altogether can be really helpful

https://github.com/ChocolateUI/chocolate-ui/blob/8f30fc55be25ce49cef938fd0427d5759d74077b/src/components/Tree/tree.tsx#L72 I found out that item.parent = parent in doTranslate triggered the circular reference

Great that you found the issue! I guess you can close this GitHub issue now since everything is resolved?

wait a moment, I will refactor the code and then give you a reply

Read more comments on GitHub >

github_iconTop Results From Across the Web

React, Uncaught RangeError: Maximum call stack size ...
I got 'Maximum call stack size exceeded', and similar errors because of framer-motion API dependency, version bigger than 4.1.17 (today's ...
Read more >
Bug: Maximum call stack size exceeded (React Devtools ...
The bottom line is that the profiler becomes unresponsive after any interaction with a heavily loaded react page. React version: React: 17.0.2 ...
Read more >
JavaScript RangeError: Maximum Call Stack Size Exceeded
The JavaScript RangeError: Maximum call stack size exceeded is an error that occurs when there are too many function calls, or if a...
Read more >
Error RangeError: Maximum call stack size exceeded
Sometimes calling a recursive function over and over again, causes the browser to send you Maximum call stack size exceeded error message as...
Read more >
React-native debugging error: Maximum call stack size ...
This error is almost always means you have a problem with recursion in JavaScript code, as there isn't any other way in JavaScript...
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