Skip to content

useEffect + setState panics with RefCell already borrowed on macOS ARM64 #4

@tomkennedy22

Description

@tomkennedy22

Hey! Humongous fan of perry!

Been playing around with perry-react today and hit a crash that I think is also responsible for the weather-app demo crashing on launch.
Calling a state setter inside useEffect panics every time:

function App() {
  const [status, setStatus] = useState("idle")

  useEffect(() => {
    setStatus("started")
  }, [])

  return <div><h1>Status: {status}</h1></div>
}
thread '<unnamed>' panicked at crates/perry-ui-macos/src/state.rs:382:13:
RefCell already borrowed

My guess is the useEffect fires and triggers a re-render while the initial render is still holding a borrow on the state RefCell.

I initially found this when cloning & testing the weather-app and it crashes on launch with the same abort — pretty sure it's the same root cause since it calls setState from inside a fetch callback on startup. I couldn't get weather-app working so started a new react repo and ultimately hit this error

macOS ARM64, built from source, perry-react from PerryTS/react.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions