Skip to content

Firehose - store firehoses in state to trigger rerender when changed - #2822

Merged
openshift-merge-robot merged 3 commits into
openshift:masterfrom
rawagner:4.3-firehose
Oct 24, 2019
Merged

Firehose - store firehoses in state to trigger rerender when changed#2822
openshift-merge-robot merged 3 commits into
openshift:masterfrom
rawagner:4.3-firehose

Conversation

@rawagner

Copy link
Copy Markdown
Contributor

When we change resources to fetch, Firehose will restart the watch in componentDidUpdate which is incorrect lifecycle method - this.firehoses are updated after the rerender but we want them to update before.

I've moved the whole logic from componentDidUpdate to shouldComponentUpdate to restart the watch before rerendering.

@spadgett

@openshift-ci-robot openshift-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. component/core Related to console core functionality labels Sep 24, 2019
@rawagner

Copy link
Copy Markdown
Contributor Author

another solution would be to use UNSAFE_componentWillUpdate but that is going away soon so I opted for shouldComponentUpdate

@spadgett

Copy link
Copy Markdown
Member

I don't think it's a good practice for shouldComponentUpdate to have side effects. Are you seeing a specific problem? Since the watch is asynchronous, I'm not sure having it in componentDidUpdate is a problem. The render will happen first regardless.

/hold
/cc @christianvogt

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 24, 2019
@rawagner

rawagner commented Sep 25, 2019

Copy link
Copy Markdown
Contributor Author

Yes I see the specific problem. I debugged it and here's the flow which leads to problem:

Imagine you have two components - A and B. A is watching some resource (lets say ClusterVersion). B gets mounted and at first isn't watching anything (it is wrapped in Firehose but resources props is empty array). B's Firehoses props from redux are k8sModels - some immutable map, loaded is true and inFlight is false. B will update Firehose's resources props to wach ClusterVersion too, Firehose's render is called but this.firehoses is still empty as that is updated in start/clear functions which weren't called yet.
Sice render was called, componentDidUpdate follows - it will call clear and start which will update this.firehoses. This however wont trigger rerender as state didnt change, props didnt change and props from redux connect didnt change because k8sModels are still the same, loaded is still true (as the resource is already loaded by component B), inFlight is still false. And you end up with Firehose never injecting ClusterVersion to component B, unless there's is some rerender caused by something else.

Specific scenario:
This is actually happening to me in Dashboards page in this PR #2806 .You can easily try it out - first load of dashboards page is ok, Cluster health in Status card is shown fine, then go to some other page (ie pods) and go back to dashboards - Cluster health will be stuck in loading state. This is because masthead-toolbar is watching ClusterVersion (component A from example below) and Status card Cluster health is also watching ClusterVersion (component B). You may wonder why the first render is ok - this is because Firehose's k8sModels, inFlight gets updated so it will trigger rerender, but when changing pages wont as k8sModels are already loaded

@rawagner

Copy link
Copy Markdown
Contributor Author

Ok, i agree that shouldComponentUpdate is not a best place to do clear/start. Should I go with UNSAFE_componentWillUpdate ?

@rawagner

Copy link
Copy Markdown
Contributor Author

PR updated, i've put this.firehoses to state and also converted UNSAFE_componentWillMount to componentDidMount

@spadgett

Copy link
Copy Markdown
Member

Thanks, this seems like a much better approach, although it looks like it's broken something. e2e-aws-console and e2e-aws-console-olm both failed with the same error.

@spadgett
spadgett changed the base branch from master-4.3 to master September 25, 2019 12:59
@spadgett
spadgett changed the base branch from master to master-4.3 September 25, 2019 12:59
@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 25, 2019
@spadgett spadgett added this to the v4.3 milestone Sep 25, 2019
@rawagner
rawagner changed the base branch from master-4.3 to master September 25, 2019 21:21
@rawagner
rawagner force-pushed the 4.3-firehose branch 2 times, most recently from 34babfa to d785b2b Compare September 26, 2019 07:26
@rawagner

Copy link
Copy Markdown
Contributor Author

/retest

@rawagner

Copy link
Copy Markdown
Contributor Author

/test e2e-aws-console

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 26, 2019
@spadgett

spadgett commented Oct 2, 2019

Copy link
Copy Markdown
Member

Are we sure it's safe to remove forceUpdate?

@TheRealJon If you remember the scenario that required forceUpdate, can you check if it's still an issue?

@rawagner

rawagner commented Oct 2, 2019

Copy link
Copy Markdown
Contributor Author

not sure yet, but it would be nice. A test case would be great, but if you wont remember any, maybe we could try it out and revert if anything goes wrong ?

@TheRealJon

Copy link
Copy Markdown
Member

@spadgett @rawagner I tested this branch out and the project overview workloads page seems to be working fine. I remember adding the forceUpdate prop to firehose because when passing props directly to a firehose child, updating those props did not always trigger a rerender. I don't remember the exact scenario that produced the issue, but it seems like everything is working fine with these updates.

@spadgett

spadgett commented Oct 2, 2019

Copy link
Copy Markdown
Member

I remember adding the forceUpdate prop to firehose because when passing props directly to a firehose child, updating those props did not always trigger a rerender.

Oh, so in this example...

https://github.com/openshift/console/blob/master/frontend/public/components/overview/index.tsx#L1186-L1194

If a prop like selectedItem changed, OverviewMainContent didn't re-render since shouldComponentUpdate in Firehose returned false? We should be able to test that.

@TheRealJon

Copy link
Copy Markdown
Member

@spadgett Yes, that's a good example. I did manually test that specific prop, and changing the selected item does work as expected.

@rawagner

rawagner commented Oct 3, 2019

Copy link
Copy Markdown
Contributor Author

Thanks @TheRealJon . I will add a test to this PR too

@rawagner
rawagner force-pushed the 4.3-firehose branch 2 times, most recently from 108305a to d98657b Compare October 4, 2019 12:18
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 4, 2019
@rawagner

Copy link
Copy Markdown
Contributor Author

/test e2e-aws-console-olm

@rawagner

Copy link
Copy Markdown
Contributor Author

@spadgett added a few tests, can you take a look ?

@spadgett spadgett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/approve
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 24, 2019
@spadgett

Copy link
Copy Markdown
Member

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 24, 2019
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rawagner, spadgett

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2019
@spadgett

Copy link
Copy Markdown
Member

/retest

@spadgett

Copy link
Copy Markdown
Member

/skip

@spadgett

Copy link
Copy Markdown
Member

/retest

1 similar comment
@spadgett

Copy link
Copy Markdown
Member

/retest

@openshift-merge-robot
openshift-merge-robot merged commit e4d69f7 into openshift:master Oct 24, 2019
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@rawagner: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws 6798bca27f05f2689105343132c86696de33c5e7 link /test e2e-aws
ci/prow/e2e-aws-console-olm f474858 link /test e2e-aws-console-olm
ci/prow/e2e-gcp-console f474858 link /test e2e-gcp-console

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/dev-console Related to dev-console component/shared Related to console-shared lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants