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

Events fail to initialize on react@^18 #2171

Open
nickofthyme opened this issue Sep 14, 2023 · 8 comments
Open

Events fail to initialize on react@^18 #2171

nickofthyme opened this issue Sep 14, 2023 · 8 comments
Assignees

Comments

@nickofthyme
Copy link
Collaborator

nickofthyme commented Sep 14, 2023

When using charts with react@^18, the event callbacks for user interactions all fail to be called.

With React18 that seriously blocks us: event callbacks like onBrushEnd are not called in React18.

Originally posted by @yannbolliger in #1910 (comment)

This issue appears to be related to the ResizeObserver calling onResize with an empty element (i.e. { height: 0, width: 0 }). Then the UPDATE_PARENT_DIMENSION is updating to the zeroed dimensions and blocking the initialization of the event callbacks.

See codesandbox example here

Screen Recording 2023-09-14 at 10 48 12 AM

Notice not console logs of the events.

@nickofthyme nickofthyme self-assigned this Sep 14, 2023
@nickofthyme
Copy link
Collaborator Author

nickofthyme commented Sep 18, 2023

@markov00 I took a look into this and for some reason the redux state does not appear to be updating the parent dimensions. The UPDATE_PARENT_DIMENSION reducer is called with a non-zero height and width but then immediately after the getInternalIsInitializedSelector returns a non-initialized state with height = width = 0.

When you get a chance could you take a look, cuz I'm out of ideas on what it could be.

@markov00
Copy link
Member

markov00 commented Sep 19, 2023

@markov00 I took a look into this and for some reason the redux state does not appear to be updating the parent dimensions. The UPDATE_PARENT_DIMENSION reducer is called with a non-zero height and width but then immediately after the getInternalIsInitializedSelector returns a non-initialized state with height = width = 0.

When you get a chance could you take a look, cuz I'm out of ideas on what it could be.

I did but not fully sure about my findings (I need to dig a bit more):

  • it seems related to the way we dispatch the call: we update from within a RAF
  • it could be also related to the debounce function used: react 18 put some changes to how setTimeout works, not sure if this is related but we should check

@nickofthyme
Copy link
Collaborator Author

nickofthyme commented May 1, 2024

This issue appears to be caused by using the StrictMode component from react. Still investigating but likely due to these changes.

See same demo as above with StrictMode removed.

@nickofthyme
Copy link
Collaborator Author

Since kibana does not use StrictMode I am pushing this fix to 8.16 cycle to be done along with work to upgrade redux #2377.

@jonas080301
Copy link

jonas080301 commented Jun 5, 2024

Hi there, i am using elastic/charts 65.2.0 with Next13 and React18 and have the same error with onElementClick event. Is there any workaround or fix?

@nickofthyme
Copy link
Collaborator Author

@jonas080301 are you using StrictMode?

@jonas080301
Copy link

@jonas080301 are you using StrictMode?

Looks like NextJS uses React in Strict Mode. I got it to work by setting reactStrictMode to false in the next.config.ts! Thank you

@nickofthyme
Copy link
Collaborator Author

nickofthyme commented Jun 5, 2024

Glad to hear! I plan to dig deeper into the issue soon but for now that is the best workaround.

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

3 participants