Skip to content

Commit f7cd1e0

Browse files
committed
Media editor: consume original_attachment as a bare id
The field is now the original attachment's id (embeddable via the wp:original-attachment link); take the URL from the record already fetched for dimensions.
1 parent 7bc8fb1 commit f7cd1e0

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • packages/media-editor/src/components/media-editor

‎packages/media-editor/src/components/media-editor/index.tsx‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,12 +562,11 @@ function MediaEditorContent( {
562562
}, [ id, invalidateResolution ] );
563563

564564
// Restore-original: the lineage root the edited attachment descends from,
565-
// exposed by the server as the root-level `original_attachment` field
566-
// on the attachment (edit context). Fetch its
567-
// record for the natural dimensions the cropper needs to seed itself (the
568-
// field itself carries only the id and url).
569-
const originalAttachment = media?.original_attachment;
570-
const originalId: number | undefined = originalAttachment?.attachment_id;
565+
// exposed by the server as the root-level `original_attachment` id on the
566+
// attachment (edit context, embeddable via the `wp:original-attachment`
567+
// link). Fetch the original's record for the URL and natural dimensions
568+
// the cropper needs to seed itself.
569+
const originalId: number | undefined = media?.original_attachment;
571570
const originalRecord = useSelect(
572571
( select ) =>
573572
originalId
@@ -581,16 +580,19 @@ function MediaEditorContent( {
581580
);
582581
const originalWidth = Number( originalRecord?.media_details?.width );
583582
const originalHeight = Number( originalRecord?.media_details?.height );
583+
const originalUrl = originalRecord?.source_url;
584584
const originalSource =
585-
originalAttachment &&
585+
originalId &&
586586
originalRecord &&
587+
typeof originalUrl === 'string' &&
588+
originalUrl.length > 0 &&
587589
Number.isFinite( originalWidth ) &&
588590
originalWidth > 0 &&
589591
Number.isFinite( originalHeight ) &&
590592
originalHeight > 0
591593
? {
592-
id: originalAttachment.attachment_id as number,
593-
url: originalAttachment.source_url as string,
594+
id: originalId,
595+
url: originalUrl,
594596
width: originalWidth,
595597
height: originalHeight,
596598
media: originalRecord,

0 commit comments

Comments
 (0)