Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runPython is causing an infinite loop #92

Closed
holdenmatt opened this issue Feb 10, 2023 · 3 comments
Closed

runPython is causing an infinite loop #92

holdenmatt opened this issue Feb 10, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@holdenmatt
Copy link

I may be using the usePython hook differently than you intend, but it's currently causing an infinite loop for me.

I have code like:

const { runPython, ... } = usePython();

useEffect(() => {
  const code = ...
  runPython(code)
  ...
}, [runPython, ...]);

The problem is the runPython function isn't memoized, so it gets re-defined on each hook call. This causes useEffect to get triggered in an infinite loop.

I think (?) the fix is to wrap runPython in a useCallback where you define it here:
https://github.com/elilambnz/react-py/blob/main/src/hooks/usePython.ts#L180

You may want to consider doing this for other functions your hooks return, so they won't change for callers on every render.

@elilambnz elilambnz self-assigned this Feb 10, 2023
@elilambnz elilambnz added the question Further information is requested label Feb 10, 2023
@elilambnz
Copy link
Owner

elilambnz commented Feb 10, 2023

Thanks, I'll investigate this.

Any reason for passing the runPython function as a dependency to your useEffect? TIL. Will make this change when I next have a moment to do so, otherwise feel free to open a PR.

@elilambnz elilambnz added bug Something isn't working and removed question Further information is requested labels Feb 10, 2023
@holdenmatt
Copy link
Author

Cool, thanks for considering.

Yeah, I've removed it for now to fix this issue, but it requires disabling a lint rule, which isn't ideal. Not a blocker / urgent, but guessing others will run into this as well, so just a suggestion!

image

@elilambnz
Copy link
Owner

Please try out version 1.8.5, this should now be fixed. I have tested it, but please let me know if you run into any further issues with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants