Navigation back to parent directory fails to restore scroll position in Files app (VirtualList resets to index 1)

This issue respects the following points: :warning:

Bug description

When navigating back from a subfolder to a parent directory, the Files app fails to remember and restore the previous scroll position. Even though the system appears to trigger a scroll event, it incorrectly targets index 1 or scrollTop: 22, forcing the view back to the top of the list. This is particularly problematic in large directories (e.g., 100+ files).

Steps to reproduce

Open a folder with a large number of items (enough to require scrolling).

Scroll down and click on a folder (e.g., located at index 60).

Click the “Back” button or use the breadcrumbs to return to the parent directory.

Observe that the list resets to the very top instead of highlighting or scrolling to the folder you just exited.

Expected behavior

The view should automatically scroll back to the folder that was previously accessed, maintaining the user’s context in the file list.

Nextcloud Server version

32

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.4

Web server

Apache (supported)

Database engine version

MariaDB

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

Monitoring the browser console during navigation reveals a race condition or a logic error in VirtualList.vue and FilesList.vue.

When returning to the parent directory, the VirtualList attempts to scroll before the content is fully rendered or uses an incorrect index:

Plaintext

FilesList.vue:334 [DEBUG] files: Directory changed {…, newDir: ‘/Parent’, oldDir: ‘/Parent/Subfolder’}

VirtualList.vue:220 [DEBUG] files: VirtualList: Skip scrolling, nothing to scroll {…, index: 62, totalRows: 0}

FilesList.vue:414 [DEBUG] files: Fetched contents {…, totalRows: 141}

VirtualList.vue:261 [DEBUG] files: VirtualList: scrolling to index 1 {…, scrollTop: 22}
Observations:

The initial scroll attempt (Index 62) is skipped because totalRows is 0 (content not yet loaded).

After contents are fetched, the system incorrectly issues a scroll command to index 1 with a scrollTop of 22, effectively pinning the view to the top.

Additional context: The issue was observed on Nextcloud version [32.0.3].

The core logic failure seems to be that VirtualList: scrolling to index 1 is being triggered as a fallback after the Skip scrolling event (which happens because totalRows is still 0 during the directory change). This fallback scroll should not be issued if a target file/folder is still being resolved.