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 Canvas double render by preventing workpad and assets from being reloaded if it's already available #114712

Merged
merged 6 commits into from
Oct 19, 2021

Conversation

poffdeluxe
Copy link
Contributor

@poffdeluxe poffdeluxe commented Oct 12, 2021

Summary

Fixes #114340

The problem is caused by the getRedirectPath and how it's being passed to the useWorkpad hook. The getRedirectPath callback is updated whenever a redirect happens or a page is changed within the workpad. This was causing the hook within useWorkpad to change since one of its dependencies (getRedirectPath) was changing and it reloaded everything on the workpad.

My proposed fix here is to the useWorkpad hook into two effects:

  1. The first effect is responsible for loading and setting the workpad in state
  2. The second effect is responsible for updating the redirect path when it gets updated.

Now, when redirect path is changed with a page update or redirect, the workpad won't be re-loaded again.

@poffdeluxe poffdeluxe added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas loe:small Small Level of Effort v8.0.0 release_note:skip Skip the PR/issue when compiling release notes impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. Feature:Canvas v7.16.0 labels Oct 12, 2021
@poffdeluxe poffdeluxe requested a review from a team as a code owner October 12, 2021 19:21
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@poffdeluxe poffdeluxe closed this Oct 12, 2021
@poffdeluxe poffdeluxe reopened this Oct 12, 2021
@poffdeluxe poffdeluxe force-pushed the bug/fix-canvas-double-render branch 2 times, most recently from 466cdcb to 2a52e15 Compare October 18, 2021 15:40
@poffdeluxe
Copy link
Contributor Author

@elasticmachine merge upstream

@poffdeluxe poffdeluxe force-pushed the bug/fix-canvas-double-render branch from 2a52e15 to 4f1dc4b Compare October 18, 2021 20:34
@poffdeluxe
Copy link
Contributor Author

@elasticmachine merge upstream

@poffdeluxe poffdeluxe added the auto-backport Deprecated - use backport:version if exact versions are needed label Oct 18, 2021
@poffdeluxe poffdeluxe force-pushed the bug/fix-canvas-double-render branch from 4f1dc4b to deee03b Compare October 18, 2021 23:30
@poffdeluxe poffdeluxe force-pushed the bug/fix-canvas-double-render branch from deee03b to 9642b86 Compare October 19, 2021 01:44
Copy link
Contributor

@crob611 crob611 left a comment

Choose a reason for hiding this comment

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

Looks good. Great job taking care of that.

}, [workpadId, dispatch, setError, loadPages, workpadResolve]);

useEffect(() => {
(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this needs to be in an async function, vs just running synchronously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll rip this out real quick -- good catch

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
canvas 1.0MB 1.0MB +143.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@poffdeluxe poffdeluxe merged commit 9ee3779 into elastic:master Oct 19, 2021
@poffdeluxe poffdeluxe deleted the bug/fix-canvas-double-render branch October 19, 2021 17:09
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 19, 2021
…reloaded if it's already available (elastic#114712)

* Fix Canvas double render by preventing workpad and assets from being reloaded if it's already available

* Better fix

* Another fix

* updating tests

* updating tests again

* remove unused async
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Oct 19, 2021
…reloaded if it's already available (#114712) (#115610)

* Fix Canvas double render by preventing workpad and assets from being reloaded if it's already available

* Better fix

* Another fix

* updating tests

* updating tests again

* remove unused async

Co-authored-by: Poff Poffenberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:Canvas impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:small Small Level of Effort release_note:skip Skip the PR/issue when compiling release notes Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Canvas] duplicated API call on loading workpad
4 participants