From 6a162abbfa4c0732f02458dd5981a824d3eec095 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 7 Nov 2026 08:06:32 -0800 Subject: [PATCH] prevent refreshes from changing destination --- .../app-frame/app-frame.component.spec.ts | 1 + .../app-frame/app-frame.component.ts | 2 +- .../document-list-view.service.spec.ts | 36 +++++++++++++++++++ .../services/document-list-view.service.ts | 4 +-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.spec.ts b/src-ui/src/app/components/app-frame/app-frame.component.spec.ts index 358d794c82..f9789c6e58 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.spec.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.spec.ts @@ -226,6 +226,7 @@ describe('AppFrameComponent', () => { status: PaperlessTaskStatus.Success, }) expect(reload).toHaveBeenCalledTimes(1) + expect(reload).toHaveBeenCalledWith(null, false) expect(refresh).toHaveBeenCalledWith(document.id) expect(maybeRefreshSpy).toHaveBeenCalledTimes(1) expect(tasksReload).toHaveBeenCalledTimes(1) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts index dbbefafeb4..bfd2f31569 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.ts @@ -183,7 +183,7 @@ export class AppFrameComponent takeUntilDestroyed(this.destroyRef) ) .subscribe(({ status, error }) => { - this.documentList.reload() + this.documentList.reload(null, false) this.documentList.reduceSelectionToFilter() // maybe someday we can optimize to only refresh affected documents this.openDocumentsService.getOpenDocuments().forEach((doc) => { diff --git a/src-ui/src/app/services/document-list-view.service.spec.ts b/src-ui/src/app/services/document-list-view.service.spec.ts index d5ef7e7b4b..aa9e80b55f 100644 --- a/src-ui/src/app/services/document-list-view.service.spec.ts +++ b/src-ui/src/app/services/document-list-view.service.spec.ts @@ -124,6 +124,42 @@ describe('DocumentListViewService', () => { }) }) + it.each([false, true])( + 'preserves the current route on a background refresh (saved view: %s)', + (savedView) => { + if (savedView) documentListViewService.activateSavedView(view) + const navigate = jest.mocked(router.navigate) + navigate.mockClear() + documentListViewService.reload(null, false) + httpTestingController + .expectOne((req) => req.url === `${environment.apiBaseUrl}documents/`) + .flush(full_results) + expect(documentListViewService.documents).toEqual(full_results.results) + expect(navigate).not.toHaveBeenCalled() + } + ) + + it('preserves the route when a background refresh falls back to the first page', () => { + jest + .spyOn(documentListViewService, 'saveDocumentListView') + .mockImplementation(() => {}) + documentListViewService.currentPage = 2 + httpTestingController + .expectOne((req) => req.url === `${environment.apiBaseUrl}documents/`) + .flush(full_results) + const navigate = jest.mocked(router.navigate) + navigate.mockClear() + documentListViewService.reload(null, false) + httpTestingController + .expectOne((req) => req.url === `${environment.apiBaseUrl}documents/`) + .flush('Not found', { status: 404, statusText: 'Not found' }) + httpTestingController + .expectOne((req) => req.url === `${environment.apiBaseUrl}documents/`) + .flush(full_results) + expect(documentListViewService.currentPage).toBe(1) + expect(navigate).not.toHaveBeenCalled() + }) + it('should reload the list', () => { expect(documentListViewService.currentPage).toEqual(1) documentListViewService.reload() diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts index 5a3a60c5b0..1947f62c98 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -380,7 +380,7 @@ export class DocumentListViewService { queryParams: paramsFromViewState(activeListViewState), replaceUrl: !this.router.routerState.snapshot.url.includes('?'), // in case navigating from params-less /documents }) - } else if (this._activeSavedViewId) { + } else if (updateQueryParams && this._activeSavedViewId) { this.router.navigate([], { queryParams: paramsFromViewState(activeListViewState, true), queryParamsHandling: 'merge', @@ -399,7 +399,7 @@ export class DocumentListViewService { // this happens when applying a filter: the current page might not be available anymore due to the reduced result set. activeListViewState.currentPage = 1 this.markChanged() - this.reload() + this.reload(onFinish, updateQueryParams) } else if ( activeListViewState.sortField.indexOf('custom_field') === 0 && !this.settings