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

Add separate provider for context and pass as children #1410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TimothyAsirJeyasing
Copy link
Contributor

@TimothyAsirJeyasing TimothyAsirJeyasing force-pushed the seperate-provider-for-context-and-pass-as-childern branch from 12b2eec to 8717610 Compare June 20, 2024 08:29
@SanjalKatiyar
Copy link
Collaborator

plz test the PR properly and attach screenshots...

@TimothyAsirJeyasing
Copy link
Contributor Author

image
image

@TimothyAsirJeyasing TimothyAsirJeyasing force-pushed the seperate-provider-for-context-and-pass-as-childern branch from 8717610 to 653e738 Compare June 25, 2024 13:52
@SanjalKatiyar
Copy link
Collaborator

/lgtm

@SanjalKatiyar
Copy link
Collaborator

/approve cancel

Copy link
Contributor

openshift-ci bot commented Jul 8, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: TimothyAsirJeyasing
Once this PR has been reviewed and has the lgtm label, please ask for approval from sanjalkatiyar. For more information see the Kubernetes Code Review Process.

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

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 openshift-ci bot removed the approved label Jul 8, 2024
@alfonsomthd
Copy link
Collaborator

@SanjalKatiyar is this approved?

Comment on lines +235 to +240
const value = {
activeItemsUID,
setActiveItemsUID,
activeItem,
setActiveItem,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

won't this create a new object after every render? due to this TopologySearchContext.Provider will get new params after every render right?

@GowthamShanmugam
Copy link
Contributor

I still have doubts about this PR, Whether the provider is a separate component does not matter, when the provider props change then It will re-render all of its children. It does not matter whether the child component is a consumer of the provider's property or not.

All we can do is pass the parent state to the provider instead of passing the direct value to avoid the request re-rendering.

@SanjalKatiyar
Copy link
Collaborator

I still have doubts about this PR, Whether the provider is a separate component does not matter, when the provider props change then It will re-render all of its children. It does not matter whether the child component is a consumer of the provider's property or not.

All we can do is pass the parent state to the provider instead of passing the direct value to avoid the request re-rendering.

{children} part of this snippet should be the one making the difference:

<TopologyDataContext.Provider value={value}>
    {children}
</TopologyDataContext.Provider>

^ this is something which can be tested and cross-verified by updating the state continuously and adding a logger in any of the consumer component.

@GowthamShanmugam
Copy link
Contributor

I still have doubts about this PR, Whether the provider is a separate component does not matter, when the provider props change then It will re-render all of its children. It does not matter whether the child component is a consumer of the provider's property or not.
All we can do is pass the parent state to the provider instead of passing the direct value to avoid the request re-rendering.

{children} part of this snippet should be the one making the difference:

<TopologyDataContext.Provider value={value}>
    {children}
</TopologyDataContext.Provider>

^ this is something which can be tested and cross-verified by updating the state continuously and adding a logger in any of the consumer component.

ack

@GowthamShanmugam
Copy link
Contributor

LGTM

Copy link
Contributor

@bipuladh bipuladh left a comment

Choose a reason for hiding this comment

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

@TimothyAsirJeyasing can we test this PR out and see if there is a difference in re-render amounts significantly?

packages/odf/components/topology/Topology.tsx Show resolved Hide resolved
@TimothyAsirJeyasing TimothyAsirJeyasing force-pushed the seperate-provider-for-context-and-pass-as-childern branch from 653e738 to 20e9786 Compare August 5, 2024 12:29
@openshift-ci openshift-ci bot removed the lgtm label Aug 5, 2024
Copy link
Contributor

openshift-ci bot commented Aug 5, 2024

New changes are detected. LGTM label has been removed.

@TimothyAsirJeyasing
Copy link
Contributor Author

TimothyAsirJeyasing commented Aug 5, 2024

The profile details are varying, However i could observe some small improvement statistically in 10 to 20 attempt.
Before
image
after:
Screenshot from 2024-08-05 17-58-07

@SanjalKatiyar
Copy link
Collaborator

SanjalKatiyar commented Aug 5, 2024

In case there is any confusion on why this change was needed (or why GH issue was created), plz check:
https://codesandbox.io/p/sandbox/without-children-h3kmm5
https://codesandbox.io/p/sandbox/with-children-qn3tcr

^ above was the idea for requesting this change, it's more of a good-practice/correct-way to add context following the pattern shown in the shared sandbox.

@TimothyAsirJeyasing
Copy link
Contributor Author

/test odf-console-e2e-aws

1 similar comment
@TimothyAsirJeyasing
Copy link
Contributor Author

/test odf-console-e2e-aws

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

Successfully merging this pull request may close these issues.

5 participants