Update LinkControl docs with advice to memoize value prop - #54659
Merged
Conversation
Mamaduka
reviewed
Sep 20, 2023
Mamaduka
reviewed
Sep 20, 2023
|
Flaky tests detected in 6fb2d75. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6406030158
|
Mamaduka
approved these changes
Oct 5, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Documents the best practice to memoize the
valueprop passed to<LinkControl>.Addresses #54603 (comment)
Props to @Mamaduka for the inspiration and the great work to fix this Issue in Core.
Why?
LinkControl is likely to be inside other compomnents which may re-render. Ifvalueis not-memozied thenLinkControlwill then also have to re-render.As
LinkControlmaintains it's own internal state of any changes made by the user interacting with the control prior to submitting their changes. This is synchronised with thevalueprop passed to the component.By memoizing the
valuewe avoid this.This pattern is established in Core PRs:
How?
Add documentation.
Why don't you just remove the internal state?
If you ask this question please carefully read and evaluate the discussion in #51387 🙇
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast