Skip to content

Commit

Permalink
fix safari not updating state correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
LamHo220 committed Feb 24, 2025
1 parent b8486ca commit 75bfde8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/hooks/usePythonConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function usePythonConsole(props?: UsePythonConsoleProps) {
const [banner, setBanner] = useState<string | undefined>()
const [consoleState, setConsoleState] = useState<ConsoleState>()
const [isRunning, setIsRunning] = useState(false)
const [output, setOutput] = useState<string[]>([])
const [stdout, setStdout] = useState('')
const [stderr, setStderr] = useState('')
const [pendingCode, setPendingCode] = useState<string | undefined>()
Expand Down Expand Up @@ -72,6 +73,13 @@ export default function usePythonConsole(props?: UsePythonConsoleProps) {
}
}, [])

// Immediately set stdout upon receiving new input
useEffect(() => {
if (output.length > 0 && !isRunning) {
setStdout(output.join(''))
}
}, [output, isRunning])

const allPackages = useMemo(() => {
const official = [
...new Set([
Expand Down Expand Up @@ -104,7 +112,7 @@ export default function usePythonConsole(props?: UsePythonConsoleProps) {
if (suppressedMessages.includes(msg)) {
return
}
setStdout(msg)
setOutput((prev) => [...prev, msg])
}),
proxy(({ id, version, banner }) => {
setRunnerId(id)
Expand Down Expand Up @@ -150,6 +158,7 @@ del sys
const runPython = useCallback(
async (code: string) => {
// Clear stdout and stderr
setOutput([])
setStdout('')
setStderr('')

Expand Down

0 comments on commit 75bfde8

Please sign in to comment.