You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DataGrid: Fix PageUp/PageDown focusing a row from the previous scroll position when rows render asynchronously - #36298
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Asynchronous page navigation still mishandles focus restoration during rapid direction reversals and legacy virtual scrolling, leaving focus stuck on the rows container or restoring it against stale rows.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Virtual-grid PageUp/PageDown navigation can leave focus on the previous page because custom loading blocks focus restoration, which is not retried when custom loading ends.
isLoading() includes the flag set by beginCustomLoading(), so PageUp/PageDown during custom loading in a virtual grid (for example, with loadPanel.enabled: false) leaves page navigation pending even after the viewport renders. endCustomLoading() only emits loadingChanged, so focus restoration is not retried and the focused row position stays on the previous page until another render. Distinguish actual pending viewport work from the custom loading indicator, while preserving checks for simultaneous real loading, and add a regression test for this sequence.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Virtual-grid PageUp/PageDown navigation can leave the focused-row index stale after target rows render because indicator-only loading blocks viewport readiness and ending it does not trigger another render.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Pending page navigation can restore focus to the previous row and undo scrolling, or overwrite an explicit grid.focus(cell) selection when rendering completes.
The reason will be displayed to describe this comment to others. Learn more.
This only runs from renderCompleted, so if the viewport update ends without a rows render, the flag stays set and _focusedCellPosition keeps the row from before PageDown.
Example: remote store, scrolling.mode: 'virtual', renderAsync: true, PageDown to a page that isn't cached, and the load fails. DataSourceAdapter.loadErrorHandler fires changed with changeType: 'loadError', and RowsView._handleDataChanged sends it to _update(), which doesn't render (only the focus and selection extenders handle their own change types there). So renderCompleted never fires. Once loading ends, keys are no longer blocked, and the next ArrowDown moves from the old row, which is the symptom this PR fixes. Before this change, restoreFocusableElement always set the position immediately.
This is a different path from the PageDown → PageUp reversal discussed above. Could completion be tied to the end of the viewport update itself (rendered, no-op, or failed) instead of the next renderCompleted?
The reason will be displayed to describe this comment to others. Learn more.
You're right: after a failed load the flag stays set and the position keeps the row from before PageDown until the next render.
The problem is that there is no correct row to complete with. A failed load doesn't re-render, so the DOM still has the old rows while the scroll position and the row index offset are already new. I tried completing the navigation on dataErrorOccurred: the pick landed on row 15, which isn't rendered, and arrows still did nothing. Base without renderAsync behaves the same after a failed load: focus stays on the rows view and arrows do nothing.
The "no-op" case doesn't occur: after the scroll timeout a render always follows (partialUpdateItem returns an update for every kept row, so cancelEmptyChanges doesn't cancel it).
After the error, the next successful render (retry, scroll, refresh) completes the navigation and focuses the top visible row. Any focus change (a click, the API) now drops the flag too (see the setFocusedRowIndex thread). So I'd leave the error case as is in this PR, unless you see a better target row for it.
The reason will be displayed to describe this comment to others. Learn more.
dataSourceController.isLoading() is also true during CustomLoader loads. CustomLoader.load calls dataSource._scheduleLoadCallbacks, which increments the loading count, and in non-legacy virtual mode the adapter's isLoading() returns _dataSource.isLoading(). Callers include selection (selection.ts), export (loadAll), header filter values and the focused-row index lookup (focus.ts). None of these loads is followed by a rows render.
Example: remote virtual grid, PageDown while a select-all or focused-row lookup load is running. The viewport render's renderCompleted sees isLoading() === true and keeps the navigation pending (keys stay blocked meanwhile). When the custom load finishes, nothing renders, so the focused position stays at the row from before PageDown until some unrelated render.
virtual_scrolling.ts:146 already excludes these loads: this._dataSource.isLoading() && !this.customLoader.isLoading(). This is separate from the beginCustomLoading case in the earlier thread.
The reason will be displayed to describe this comment to others. Learn more.
Follow-up to the grid.focus() thread: clearing the flag in _focusElement and in the success branch of _clickTargetCellHandler covers those two paths. Other focus changes made while navigation is pending still get replaced with the top visible row here:
a click in a master-detail cell or in the free-space row: _pointerEventHandler calls _updateFocusedCellPosition directly;
args.resetFocusedRow in _clickTargetCellHandler: it returns before the flag is cleared, so the reset row is focused again on completion.
The pending window is the scroll timeout plus the whole remote load, so a click in master-detail during a slow load is realistic. Because the focus extender's setFocusedRowIndex writes the focusedRowIndex option, this also changes focusedRowKey and raises onFocusedRowChanged. I haven't traced whether option('focusedRowKey', ...) / navigateToRow() while pending end up in _focusElement. If they don't, they're affected too.
Since every new focus path has to remember to clear the flag, could the pending state be dropped whenever the focused position changes from anywhere other than this completion?
The reason will be displayed to describe this comment to others. Learn more.
With this condition, every key in FOCUSED_CELL_KEYS (including tab, enter, space, home/end, see const.ts:38) gets preventDefault() and stopPropagation() for the whole remote load after PageDown. Before, keys were blocked only during async template layout, which is short.
With a slow or hanging request, a keyboard user can't Tab out of the grid until the load ends, and Enter/Space presses are dropped, not queued. Could Tab/Shift+Tab at least be allowed to leave the grid while page navigation is pending, or the wait be limited to the keys that depend on the focused row position?
The reason will be displayed to describe this comment to others. Learn more.
Agreed, with a slow request this is a long wait. I compared it with base: Tab during the same wait isn't better there. It runs with the stale row picked before the new rows arrived, so it doesn't reach the right cell either. With this PR, Tab is ignored until the load ends, and then focus is on the correct row. PageUp/PageDown, Ctrl+Up/Down, Escape and the mouse still work during the wait.
Letting Tab through isn't simple. The grid's Tab handler would move from the row before PageDown, which is scrolled away. A native Tab from the focused rows view can land on a cell or editor of the stale rows. Both need a browser check, and neither looks better than waiting. I'd keep this PR as is and handle "Tab out of the grid during a long load" in a separate task if we want it. What do you think?
The reason will be displayed to describe this comment to others. Learn more.
Method placement: the pending timer lives in VirtualScrollController, and the data controller is the one that decides which controller gets the position (_rowsScrollController or the adapter, in setViewportPosition). So the data controller is the right owner of this query, but it doesn't need a stub in the base DataController. The stub is only here because the caller, isViewportRowsRenderPending, is in the base RowsView and sees the base type.
Suggestion:
declare isViewportPositionPending in VirtualScrollingDataControllerExtension (virtual_scrolling/types.ts), next to setViewportPosition, and remove this stub;
move the body of isViewportRowsRenderPending (including the isVirtualPaging || isVirtualRowRendering check) into VirtualScrollingRowsViewExtender, which already types _dataController as DataController & VirtualScrollingDataControllerExtension;
keep only a return false; default in the base RowsView, so keyboard navigation doesn't depend on virtual-scrolling types.
This way the base RowsView and DataController don't need to know about the virtual-scrolling timer.
The reason will be displayed to describe this comment to others. Learn more.
Minor, and not a regression (the old code had the same gap): the flag is set only here. This code runs from _scrollBy, after the scrollable's next scroll event and then a setTimeout. Between PageDown and this callback, isWaitingForRowsRendering doesn't block anything. So an ArrowDown pressed right after PageDown moves from the old row and scrolls it back into view, undoing the page scroll.
Setting the flag when the PageUp/PageDown scroll starts would close most of that window. If no scroll event follows (for example, the grid is already scrolled to the boundary), the flag would need to be reset there, or it would stay pending.
The reason will be displayed to describe this comment to others. Learn more.
Yes, this window exists in base too. I checked that ArrowDown pressed between PageDown and the scroll callback behaves the same with and without this PR: in both, the completion then moves focus to the new top row.
To set the flag on the key press, we'd need a reliable "no scroll will happen" signal (already at the top or bottom, or the scrollable clamps the distance). Otherwise the flag stays set and a later render overwrites the user's focus. I'd keep it out of this PR and can file a follow-up if you think it's worth it.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.