wordpress-develop
wordpress-develop copied to clipboard
refact: update the media item modal loader to load all images until current
Summary
Fixes broken media library navigation when accessing items beyond the initial page load via direct URL after a page refresh.
Trac ticket: https://core.trac.wordpress.org/ticket/54091
Solution
Implemented a two-phase loading strategy:
- Immediate fetch - Opens the item instantly as it currently does.
- Background context loading - Recursively loads library batches until the item is found in the collection, then enables navigation.
Changes Made
src/js/media/routers/manage.js
- Added recursive batch loading to load all the images in library till the image found in the backend.
- Updates edit frame model once item is found in collection to enable navigation.
src/js/media/views/frame/edit-attachments.js
- Added
-1index check tohasNext()andhasPrevious()
Screen Recording
https://github.com/user-attachments/assets/a1a9dfae-b62f-46af-9e28-866bae98f40f
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.