@@ -957,8 +957,11 @@ export default class DataBrowser extends React.Component {
957957 const objectsToFetch = [ ] ;
958958
959959 if ( prevState . panelCount > 1 && selectedObjectId ) {
960- // If the selected object is not in the displayed list, update displayed objects
961- if ( ! newDisplayedObjectIds . includes ( selectedObjectId ) ) {
960+ // When batch-navigate is enabled, always rebuild the batch starting from the selected row
961+ // to ensure prefetched data is properly utilized
962+ const shouldRebuildBatch = ! newDisplayedObjectIds . includes ( selectedObjectId ) || prevState . batchNavigate ;
963+
964+ if ( shouldRebuildBatch ) {
962965 const currentIndex = this . props . data ?. findIndex ( obj => obj . id === selectedObjectId ) ;
963966 if ( currentIndex !== - 1 ) {
964967 const { prefetchCache } = prevState ;
@@ -1367,8 +1370,10 @@ export default class DataBrowser extends React.Component {
13671370 }
13681371
13691372 const cache = { ...this . state . prefetchCache } ;
1373+ const now = Date . now ( ) ;
1374+
1375+ // Clean up stale entries and track which keys are removed
13701376 if ( prefetchStale ) {
1371- const now = Date . now ( ) ;
13721377 Object . keys ( cache ) . forEach ( key => {
13731378 if ( ( now - cache [ key ] . timestamp ) / 1000 >= prefetchStale ) {
13741379 delete cache [ key ] ;
@@ -1379,6 +1384,18 @@ export default class DataBrowser extends React.Component {
13791384 this . setState ( { prefetchCache : cache } ) ;
13801385 }
13811386
1387+ // Helper function to check if an object needs prefetching (missing or stale)
1388+ const needsPrefetch = ( objectId ) => {
1389+ if ( ! Object . prototype . hasOwnProperty . call ( cache , objectId ) ) {
1390+ return true ;
1391+ }
1392+ if ( prefetchStale ) {
1393+ const entry = cache [ objectId ] ;
1394+ return entry && ( now - entry . timestamp ) / 1000 >= prefetchStale ;
1395+ }
1396+ return false ;
1397+ } ;
1398+
13821399 const history = this . state . selectionHistory ;
13831400 if ( history . length < 3 ) {
13841401 return ;
@@ -1401,7 +1418,7 @@ export default class DataBrowser extends React.Component {
14011418 ) {
14021419 // For each step ahead, prefetch the main object
14031420 const mainObjId = this . props . data [ c + ( i * stepSize ) ] . id ;
1404- if ( ! Object . prototype . hasOwnProperty . call ( cache , mainObjId ) ) {
1421+ if ( needsPrefetch ( mainObjId ) ) {
14051422 this . prefetchObject ( mainObjId ) ;
14061423 }
14071424
@@ -1410,7 +1427,7 @@ export default class DataBrowser extends React.Component {
14101427 const batchStartIndex = c + ( i * stepSize ) ;
14111428 for ( let j = 1 ; j < panelCount && batchStartIndex + j < this . props . data . length ; j ++ ) {
14121429 const batchObjId = this . props . data [ batchStartIndex + j ] . id ;
1413- if ( ! Object . prototype . hasOwnProperty . call ( cache , batchObjId ) ) {
1430+ if ( needsPrefetch ( batchObjId ) ) {
14141431 this . prefetchObject ( batchObjId ) ;
14151432 }
14161433 }
0 commit comments