Skip to content

Commit e29dc60

Browse files
committed
Fix collapsing stack frames loop in error-overlay
1 parent a6945b6 commit e29dc60

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/utils/error-overlay/src/components/Collapsible.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
/* @flow */
9-
import {useState} from 'preact/hooks';
9+
import {useRef} from 'preact/hooks';
1010
import {theme} from '../styles';
1111

1212
const _collapsibleStyle = {
@@ -40,15 +40,12 @@ type CollapsiblePropsType = {|
4040
|};
4141

4242
function Collapsible(props: CollapsiblePropsType): React$Element<'details'> {
43-
const [collapsed, setCollapsed] = useState(true);
44-
45-
const toggleCollapsed = () => {
46-
setCollapsed(!collapsed);
47-
};
43+
const ref = useRef(null);
44+
const collapsed = ref.current?.open;
4845

4946
const count = props.children.length;
5047
return (
51-
<details open={!collapsed} onToggle={toggleCollapsed}>
48+
<details>
5249
<summary
5350
style={collapsed ? collapsibleCollapsedStyle : collapsibleExpandedStyle}
5451
>
@@ -58,7 +55,10 @@ function Collapsible(props: CollapsiblePropsType): React$Element<'details'> {
5855
</summary>
5956
<div>
6057
{props.children}
61-
<button onClick={toggleCollapsed} style={collapsibleExpandedStyle}>
58+
<button
59+
onClick={() => ref.current?.setAttribute('open', false)}
60+
style={collapsibleExpandedStyle}
61+
>
6262
{`▲ ${count} stack frames were expanded.`}
6363
</button>
6464
</div>

0 commit comments

Comments
 (0)