WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 9 months ago

#51395 closed defect (bug) (fixed)

The attachment modal is not opened when reloading the page

Reported by: Mista-Flo Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch dev-feedback
Focuses: javascript, administration Cc:

Description

Hello,

On the media library page, grid mode, if you click on an attachment, it will open a modal. If you refresh the page, the modal will be opened again on the same attachment.

But if you have more than 40 attachments in the page, if you click on the 41st attachment, the modal is opened as expected, but if you refresh the page, you have a console error (Uncaught TypeError: Cannot read property 'set' of undefined) in a JS file and the modal is not opened.

This is due because the code calls item.set( 'skipHistory', true ); in src/js/media/routers/manage.js despite it's not sure the item has been found.

So when moving this line after being sure the item is defined, the error is gone and the modal can be opened without a problem.

Attachments (1)

51395.1.patch (594 bytes) - added by Mista-Flo 9 months ago.

Download all attachments as: .zip

Change History (5)

@Mista-Flo
9 months ago

#1 @mukesh27
9 months ago

  • Focuses administration added
  • Keywords dev-feedback added
  • Version trunk deleted

Hi there,

I have replicated the issue and 51395.1.patch patch working fine for WordPress version 5.6-alpha-48958.

Added dev-feedback for dev feedback.

#2 @Mista-Flo
9 months ago

Thank you @mukesh27,

Just to mention that this is due to the fact that at the refresh, it loads the first 40 attachments (check the AJAX request), so the next attachments are not queried which seems legit.

#3 @SergeyBiryukov
9 months ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @SergeyBiryukov
9 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 49062:

Media: Check if the item is defined before setting the skipHistory property in media frame router.

This avoids a JS error when refreshing the "Attachment details" modal for an item that is not currently queried.

Follow-up to [41021].

Props Mista-Flo, mukesh27.
Fixes #51395.

Note: See TracTickets for help on using tickets.