WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 6 weeks ago

#50025 new defect (bug)

Media Library not showing new uploads when filtering by date

Reported by: teamdnk Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.4
Component: Media Keywords: needs-patch
Focuses: ui, javascript Cc:

Description

The issue is produced while in the grid mode and while using the media modal since both use Ajax. The problem happens when attempting to upload a new image while using the filter(s). New uploads do not show up without refreshing the page. To reproduce do the following steps:

  1. Use grid mode in Media Library
  2. Filter by a date
  3. Upload a new image
  4. Toggle back to "All Dates"

You will notice that not only is there no feedback whether or not my image has been successfully uploaded, but the new image does not show even when toggling back to the "All Dates". The only way that I have found to show any new uploads is to actually refresh the page which defeats the purpose especially with the modal. The modal at least has some feedback with the uploading status bar but still has the same issue.

There should be some kind of feedback when uploading media while using the filters. At the very least it should show the new upload while on the current month and when toggling back to the "All" filter.

Change History (11)

#1 @afercia
7 months ago

  • Focuses administration removed

@teamdnk thanks for your report and welcome to Trac.

I can reproduce what you reported but only partially. It seems to me the actual behavior differs depending on the editor used and on the state of the media selection. Would you mind clarifying a few things?

  • I assume you're using WordPress 5.4, correct?
  • Are you using the Classic Editor or the Block Editor?
  • Do you have any activated plugin and are you using a default theme? If so, please confirm that the issue still exists with the default theme (Twenty Twenty) activated and all other plugins deactivated.

From what I can tell, based on my testing:

Media Library (grid mode)

  • when switching back to "All dates", the new media are visible for me

Media Modal with the Classic Editor

  • When uploading one or more images, they're automatically "selected" and the selection state is visible in the bottom bar:

http://cldup.com/TUziTp2K_w.png

http://cldup.com/21NCs75Eej.png

  • Keeping the selection: when I switch back to "All dates", the new media are visible for me.
  • Clearing the selection: when I switch back to "All dates", the new media are not visible. I think this has always been the case with the media modal. Not saying it shouldn't be fixed. It's just to clarify it's an issue that probably exists since the introduction of the media modal or, maybe, since the introduction of the "date" filter in WordPress 4.1.
  • In all cases, there's a lack of a clear feedback and this should be fixed in some way.

Media Modal with the Block Editor
It's a bit more complicated to test because different blocks use different media modal types. For example:

  • The Image block uses the "Select media" frame (no selection status bottom bar).
  • The Gallery block uses the "Create Gallery" frame (does have the selection status bar).
  • In both cases, the added images are visible for me.

So, at least for me, this appears to happen when the selection status is "cleared". Note that in the Media Library "grid", the added media are not automatically selected, which is probably the reason why the bug doesn't happen there.

#2 @teamdnk
7 months ago

@afercia

Thanks for the welcome and the response! For clarification:

  • WordPress 5.4
  • Block Editor
  • No plugins and using Twenty Twenty theme

I do not have the classic editor so I cannot speak to that but here is what I found:

Media Library (grid mode)
I noticed after flushing it out a little more that the issue happens when you toggle back to "All Dates" at least once before uploading new media. I am not sure but it seems to be caching the results with out re-querying new results after a new upload.

Media Modal with the Block Editor
I can replicate the same behavior on the Image block and the Gallery block.

#3 @afercia
7 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.5

@teamdnk thanks for further testing.

the issue happens when you toggle back to "All Dates" at least once before uploading new media.

it seems to be caching the results with out re-querying new results after a new upload.

Yup, the media views collections do implement a caching mechanism. They check whether a query has already been made and in that case they just re-display the cached collection, avoiding a new fetch. I'm not sure I fully understand how this mechanism works, yet. The fact the media views inner workings aren't described nor documented anywhere after more than 7 years from their introduction doesn't help.

Regardless, I was able to reproduce something similar to the steps you provided back to WordPress 4.9 and I guess it always happened on all previous versions:

  • go to the Media Library so that attachments are fetched for the first time
  • filter by a previous month
  • in the filtered month view, drag and drop a new attachment
  • switch back the filter to "All dates"
  • the new attachment is visible
  • but...
  • switch back to the previously selected month
  • drag and drop one more attachment
  • switch back the filter to "All dates"
  • this time, the new attachment is not visible

This translates to:

  • first fetch: the "all" view is not cached yet
  • switch to a month: the month view is not cached yet
  • add attachment, switch to "all" view
  • the "all" view is not cached yet: a new fetch occurs which includes the new attachment and the collection gets cached
  • switch to month: the month view is now cached
  • add attachment, switch to "all" view
  • the "all" view is cached and will display the previous attachments, ignoring the new one

To my understanding, there's a flaw in the media views collections design. When attachments are added, the cache should be flushed to trigger a new fetch.

This doesn't seem to happen when attachments are removed. Although the collection is cached (there's no new fetch), the deleted attachment is not displayed, as expected. Agani to my understanding, this works correctly because destroyed attachments are filtered out.

Moving to 5.5 consideration.

#4 @afercia
7 months ago

Additional detail: not to mention that, when the added attachment belongs to a new month, the "filter by date" select doesn't get updated with the new month. This select gets the month values from a query to the database that runs on page load. The values are printed out on the page under _wpMediaViewsL10n.settings thus the select isn't updated "on the fly".

#5 @teamdnk
7 months ago

@afercia

When attachments are added, the cache should be flushed to trigger a new fetch.

Thank you for breaking down explaining exactly what is going on here. I agree that the cache should be flushed after uploading a new attachment.

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


5 months ago

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


5 months ago

#8 @antpb
5 months ago

  • Milestone changed from 5.5 to 5.6

This ticket was discussed in a recent Media Component bug scrub for 5.5. I'm going to move this to 5.6 as we are in Beta cycle and this change may be a bit too big to add in Beta. I'm happy to be wrong on that and please feel free to move back into the milestone if it's possible to land in time. Thanks!

#9 @Mista-Flo
3 months ago

Note that I can reproduce the issue as well in the upload.php admin page in grid view. If I select the current month in the Date filter, even if I upload a new image, it's not shown on the grid.

Version 0, edited 3 months ago by Mista-Flo (next)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


6 weeks ago

#11 @antpb
6 weeks ago

  • Milestone changed from 5.6 to Future Release
  • Summary changed from Media Library (Ajax) Filters Not Showing New Uploads to Media Library not showing new uploads when filtering by date

With 5.6 Beta 1 in the rear view mirror, we should probably mark this Future Release as there is still investigation to do here.
Also changing the title to better describe the issue as ajax doesn't seem to be the culprit.

Note: See TracTickets for help on using tickets.