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

fix(events): remove async callbacks from code #1730

Merged
merged 1 commit into from
Jun 28, 2022

Conversation

markov00
Copy link
Member

Summary

Working at #1729 leads to an interesting issue regarding the asynchronous callback.
In particular, we were calling the onChartRendered and onProjectionAreaChanged callbacks in a new macro task thanks to a requestAnimationFrame.

The reasons to avoid this way of handling callbacks are:

  • give the freedom to the user to choose how they want to execute/queue the task in their own environment
  • events caused by mouse events are already async by nature
  • those callbacks should be used only for small side effects, like triggering a focus, a slight change in the state (like disabling a loading spinner) etc the user should not attach long-running sync methods to these events.

This PR removes the use of RAF in favor of sync calls.

This solves a side issue in the composable story where the chart render-complete was not called correctly.

@markov00 markov00 requested review from monfera and nickofthyme June 27, 2022 11:24
@markov00 markov00 added enhancement New feature or request :interactions Interactions related issue :refactor Code refactor labels Jun 27, 2022
@github-actions github-actions bot temporarily deployed to PR #1730 June 27, 2022 11:26 Inactive
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!! Works great. Thanks for jumping on this so fast! Any idea why we wrapped those in a RAF?

@markov00
Copy link
Member Author

markov00 commented Jun 27, 2022

Excellent!! Works great. Thanks for jumping on this so fast! Any idea why we wrapped those in a RAF?

If the user attaches very long sync function to a callback then the rendering phase of the event loop will start only after that sync function has completed, freezing the chart until the end of the callback.
Adding a RAF will push the callback in the queue and runs it after the rendering phase, reducing the freeze effect.
With that instead we want to push that decision to the users

@markov00 markov00 merged commit 27a7256 into elastic:master Jun 28, 2022
@markov00 markov00 deleted the remove_async_eventing branch June 28, 2022 09:37
nickofthyme pushed a commit that referenced this pull request Jun 28, 2022
## [46.11.2](v46.11.1...v46.11.2) (2022-06-28)

### Bug Fixes

* **events:** remove async callbacks from code ([#1730](#1730)) ([27a7256](27a7256))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request :interactions Interactions related issue :refactor Code refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants