@@ -1229,6 +1229,15 @@ export function TableGrid({
12291229 const findOpenRef = useRef ( findOpen )
12301230 findOpenRef . current = findOpen
12311231
1232+ /**
1233+ * Whether `match` is still in the live result set. Both the paging await and
1234+ * the deferred reveal can outlast a refetch that removed it, and revealing a
1235+ * cell that no longer matches would select a non-hit and mark the cursor as
1236+ * sitting on a result.
1237+ */
1238+ const isStillAMatch = ( match : TableFindMatch ) =>
1239+ findMatchesRef . current . some ( ( m ) => m . rowId === match . rowId && m . column === match . column )
1240+
12321241 /** Loads the row containing match `index` (wrapping), then queues the cell reveal. */
12331242 const goToMatch = useCallback ( async ( index : number ) => {
12341243 const matches = findMatchesRef . current
@@ -1256,10 +1265,7 @@ export function TableGrid({
12561265 // revealing it would select a cell that no longer matches and mark the
12571266 // cursor as sitting on a result, which then makes the next step skip the
12581267 // match that replaced it.
1259- const stillMatches = findMatchesRef . current . some (
1260- ( m ) => m . rowId === match . rowId && m . column === match . column
1261- )
1262- if ( ! stillMatches ) {
1268+ if ( ! isStillAMatch ( match ) ) {
12631269 activeMatchRef . current = null
12641270 cursorIsOnMatchRef . current = false
12651271 return
@@ -1304,6 +1310,15 @@ export function TableGrid({
13041310 useEffect ( ( ) => {
13051311 const match = pendingMatchRef . current
13061312 if ( ! match ) return
1313+ // Last gate before the selection moves: the queue-to-reveal hop is another
1314+ // commit the result set can change under, so re-check here too rather than
1315+ // trusting the check `goToMatch` made before its await.
1316+ if ( ! isStillAMatch ( match ) ) {
1317+ pendingMatchRef . current = null
1318+ activeMatchRef . current = null
1319+ cursorIsOnMatchRef . current = false
1320+ return
1321+ }
13071322 const rowIndex = rows . findIndex ( ( r ) => r . id === match . rowId )
13081323 if ( rowIndex === - 1 ) return
13091324 const colIndex = displayColumns . findIndex ( ( c ) => c . key === match . column )
0 commit comments