You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VSCodeCheckbox React components that have a checked value which references a React state variable initialised to true will call their onChange prop on first render. Since the onChange prop is usually toggling that same state variable, the component enters into an infinite recursive loop.
This actually seems to happen when useState is initialised with anything other than false. I tried a bunch of other values, truthy and falsy, and they all triggered the bug. It doesn't occur when the checked prop has a literal value of true.
To reproduce
The problem can be reproduced with the following code:
importReact,{FunctionComponent,useState}from"react";import{VSCodeCheckbox}from"@vscode/webview-ui-toolkit/react";constMyPage: FunctionComponent=()=>{const[isChecked,setIsChecked]=useState(true);functiontoggleChecked(){console.log("I'll be called on first render");setIsChecked(checked=>!checked)}return(<VSCodeCheckboxonChange={toggleChecked}checked={isChecked}>Togglechecked</VSCodeCheckbox>);};
Expected behavior
The onChange handler should only be called when the checkbox is first clicked, like normal <input type="checkbox" /> elements.
Current behavior
The onChange handler is called immediately on first render, which results in an infinite loop if it toggles the value read by checked.
Desktop (please complete the following information):
OS Version: macOS 12.6
Toolkit Version: v1.1.0
The text was updated successfully, but these errors were encountered:
I've also encountered such an issue, the component keeps re-rendering util its max-depth when triggered onChanged event.
So I had to write the radio buttons using raw HTML.
Describe the bug
VSCodeCheckbox
React components that have achecked
value which references a React state variable initialised totrue
will call theironChange
prop on first render. Since theonChange
prop is usually toggling that same state variable, the component enters into an infinite recursive loop.This actually seems to happen when
useState
is initialised with anything other thanfalse
. I tried a bunch of other values, truthy and falsy, and they all triggered the bug. It doesn't occur when thechecked
prop has a literal value oftrue
.To reproduce
The problem can be reproduced with the following code:
Expected behavior
The
onChange
handler should only be called when the checkbox is first clicked, like normal<input type="checkbox" />
elements.Current behavior
The
onChange
handler is called immediately on first render, which results in an infinite loop if it toggles the value read bychecked
.Desktop (please complete the following information):
macOS 12.6
v1.1.0
The text was updated successfully, but these errors were encountered: