fix(ui): avoid mounting collapsed array fields - #18240
Open
AbarnaaSree wants to merge 1 commit into
Open
AbarnaaSree wants to merge 1 commit into
AbarnaaSree wants to merge 1 commit into
Conversation
AbarnaaSree
requested review from
AlessioGr,
JarrodMFlesch and
jacobsfletch
as code owners
September 21, 2026 15:34
This branch has not been deployed
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?
Fixes the Array field performance issues reported in #18182.
This PR addresses two sources of unnecessary rendering:
Why?
When an Array contains many rows, the number of mounted fields can grow significantly even when most rows are collapsed.
Collapsiblehides its children visually, but the children remain mounted. As a result,ArrayRowwas still renderingRenderFieldsfor collapsed rows.Additionally,
RowLabelProviderwas usinguseWatchForm(). Since the form watch context changes when the form updates, row labels could rerender on every field change, even when the change was unrelated to the row label.Together, these behaviors can increase rendering work and contribute to typing latency as the number of Array rows grows.
How?
1. Do not mount fields for collapsed Array rows
Updated
packages/ui/src/fields/Array/ArrayRow.tsxso thatRenderFieldsis only rendered when the row is expanded.The loading state is unchanged and still renders
ShimmerEffect.Before:
After:
This prevents the fields inside collapsed rows from being mounted while keeping the existing expanded-row behavior.
2. Avoid subscribing RowLabelProvider to FormWatchContext
Updated
packages/ui/src/forms/RowLabel/Context/index.tsxto useuseForm()instead ofuseWatchForm().Before:
After:
This prevents
RowLabelProviderfrom subscribing to the form's watch context and avoids rerenders caused by unrelated form updates.3. Add regression tests
Added tests covering both changes:
packages/ui/src/fields/Array/ArrayRow.spec.tsRenderFieldsis not mounted when the row is collapsed.RenderFieldsis mounted when the row is expanded.packages/ui/src/forms/RowLabel/Context/index.spec.tsFormContext.FormWatchContextis not used for retrieving the row data.Testing
Focused Vitest tests were run:
Also verified:
with no errors.
Related Issue
Fixes #18182