Repository navigation
fix(plugin-cloud-storage): return updatedDoc from afterChange to reflect modified filenames and URLs (#18384) - #18391
Open
PINYOPATTANAWASANPORN wants to merge 1 commit into
Conversation
…ect modified filenames and URLs (payloadcms#18384) When an adapter modifies upload metadata (e.g. storage-vercel-blob with addRandomSuffix changing filename), afterChange calls payload.update to persist the new metadata and recompute hooks (including url generation). However, when select is not used, afterChange previously merged uploadMetadata directly onto doc, preserving the pre-update url. Return updatedDoc so that the response reflects the new filename and corresponding valid url. Fixes payloadcms#18384
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.
Summary of Changes
packages/plugin-cloud-storage/src/hooks/afterChange.ts, updatedocWithMetadatato return{ ...doc, ...updatedDoc }instead of{ ...doc, ...uploadMetadata }whenselectis not provided.packages/plugin-cloud-storage/src/hooks/afterChange.spec.tsasserting that afterChange returns updated document fields (e.g. refreshedurlmatching the suffixedfilename) when adapter upload metadata modifies the file.Root Cause / Technical Context
When storage adapters modify upload metadata during
handleUpload(such as@payloadcms/storage-vercel-blobwithaddRandomSuffix: trueappending a random suffix tofilename), theafterChangehook callsreq.payload.update(...)to persist the metadata.This
updatecall properly executes field hooks and generates the updatedurlmatching the new filename inupdatedDoc. However, whenselectwas undefined,afterChangepreviously returned:Because
docstill retained the pre-suffixurlfrom before the upload anduploadMetadataonly contained{ filename: ... }without the recomputedurl, the API response returned the newfilenamepaired with the stale/pre-suffixurl(which resulted in 404).Using
updatedDocensures that the response includes the recomputedurland all persisted metadata fields.Verification & Testing
packages/plugin-cloud-storage/src/hooks/afterChange.spec.tstesting adapter metadata return with mockedhandleUploadandpayload.update.afterChange.tswith strict LF line endings.Fixes #18384