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
I encountered a scenario in Preact 10.10.3 where a state update does not work after the initial render. The test case below works in earlier Preact releases (I tested 10.10.0-10.10.2).
Test case:
import{h,render}from"preact";import{useState}from"preact/hooks";functionWidget(){const[,setUnusedState]=useState(0);const[suggestionsListOpen,setSuggestionsListOpen]=useState(false);constopen=()=>{// Test works if line below is commented outsetUnusedState(42);setSuggestionsListOpen(true);};constclose=()=>{setSuggestionsListOpen(false);};return(<div><buttononClick={open}>Open</button><buttononClick={close}>Close</button><divdata-testid="state">{suggestionsListOpen ? "open" : "closed"}</div></div>);}constroot=document.querySelector("#app");render(<Widget/>,root);
Expected behavior: The text below the button should change to "open" after clicking the "Open" button and change to "closed" after clicking the "Close" button.
Actual behavior: The text changes to "Open" after clicking "Open" but does not update after clicking "Close".
After clicking the "Open" button a second time, the Open and Close buttons then behave as expected. The issue has something to do with the sequence of states that are updated. See the note above the code which calls setUnusedState.
In Preact 10.10.2 and earlier, the example works as expected.
The text was updated successfully, but these errors were encountered:
Describe the bug
I encountered a scenario in Preact 10.10.3 where a state update does not work after the initial render. The test case below works in earlier Preact releases (I tested 10.10.0-10.10.2).
Test case:
Steps to reproduce
Expected behavior: The text below the button should change to "open" after clicking the "Open" button and change to "closed" after clicking the "Close" button.
Actual behavior: The text changes to "Open" after clicking "Open" but does not update after clicking "Close".
After clicking the "Open" button a second time, the Open and Close buttons then behave as expected. The issue has something to do with the sequence of states that are updated. See the note above the code which calls
setUnusedState
.In Preact 10.10.2 and earlier, the example works as expected.
The text was updated successfully, but these errors were encountered: