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

Adding onFirstUpdate function kills the page #448

Open
piechoo opened this issue Aug 25, 2022 · 5 comments
Open

Adding onFirstUpdate function kills the page #448

piechoo opened this issue Aug 25, 2022 · 5 comments

Comments

@piechoo
Copy link

piechoo commented Aug 25, 2022

Reproduction demo

https://codesandbox.io/s/react-popper-v2-x-issue-template-forked-k37vgt?file=/src/index.js

Steps to reproduce the problem

  1. Open the codesanbox
  2. Page is unresponsive

What is the expected behavior?

It should run function on first update and not kill the page :)

What went wrong?

The page is totally unresponsive

Any other comments?

Packages versions

  • Popper.js:
  • react-popper:
@FezVrasta
Copy link
Member

I think you should memoize that function with useCallback. Anyways I would suggest to upgrade to Floating UI as this version is not going to receive many updates.

@piechoo
Copy link
Author

piechoo commented Aug 26, 2022

Unfortunately useCallback doesn't solve this issue.

@atomiks
Copy link
Collaborator

atomiks commented Aug 26, 2022

useCallback does solve it, it's a problem of the function being different on every render.

    onFirstUpdate: useCallback((state) => {
      console.log("Popper positioned on", state.placement)
    }, [])

@piechoo
Copy link
Author

piechoo commented Aug 30, 2022

Okay, you're right, useCallback does solve it, but i think there is still an issue, why passing new function causes infinite rerender of component ?

@JosePadilla98
Copy link

Okay, you're right, useCallback does solve it, but i think there is still an issue, why passing new function causes infinite rerender of component ?

I experience the same problem and I'm agree with @piechoo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants