fix(ui): prevent re-render cascade in UploadHandlersProvider#16088
Open
mahmoodhamdi wants to merge 1 commit intopayloadcms:mainfrom
Open
fix(ui): prevent re-render cascade in UploadHandlersProvider#16088mahmoodhamdi wants to merge 1 commit intopayloadcms:mainfrom
mahmoodhamdi wants to merge 1 commit intopayloadcms:mainfrom
Conversation
Replace useState with useRef for the upload handlers map to prevent unnecessary re-renders when multiple cloud storage collections register their handlers on mount.
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 memory leak / browser crash when using multiple collections with a cloud storage plugin (e.g.
s3Storage,azureStorage,gcsStorage).Closes #16039
Why
UploadHandlersProvideruseduseStateto store the handlers map. EachClientUploadHandlerprovider (one per upload collection) callssetUploadHandleron mount, which triggerssetState→ a full re-render of the admin tree below it. With N collections, that's N state updates each causing a cascading re-render of the entire admin panel, plus N Map clone allocations.The handlers map doesn't need to trigger re-renders —
getUploadHandleris only called during form submission, never during rendering.Changes
useStatewithuseReffor the upload handlers map — registering a handler no longer triggers a re-rendergetUploadHandlerandsetUploadHandlerinuseCallbackfor stable referencesuseMemoto prevent unnecessary consumer re-rendersTesting
pnpm run build:uipasses with no errorsgetUploadHandleris only consumed during form submission (Form/index.tsx:582) and bulk upload (FormsManager/index.tsx:362), never during render — so switching from state to ref is safeUploadHandlersContext) and public API are unchanged