Skip to content

fix(search): only load more results from the mounted sentinel - #8797

Open
chenasraf wants to merge 1 commit into
nextcloud:mainfrom
chenasraf:fix/global-search-unmounted-sentinel
Open

chenasraf wants to merge 1 commit into
nextcloud:mainfrom
chenasraf:fix/global-search-unmounted-sentinel

Conversation

@chenasraf

Copy link
Copy Markdown

Summary

The global search can still get stuck sending cancelled /apps/deck/api/v1.0/search requests forever, see #8796 (it took my server down).

When a page of results has nothing to show (all of them are on the open board), the search section switches to "No results found" and unmounts the infinite scroll sentinel. vInfiniteScroll stops its scope on unmount, but the load that just finished still re-arms it from .finally() (vueuse/vueuse#5732), so the dead loader fetches the next page, which remounts a new sentinel with its own loader. From there the two keep cancelling each other's requests, and the cursor never moves.

This makes canLoadMore only say yes for the sentinel that is currently mounted, tracked with a function ref. The dead loader's canLoad then goes false as soon as its sentinel unmounts, so it never fires again. When a page is fully filtered out, loading now stops at "No results found", same as the InfiniteLoading version before the Vue 3 migration did.

To test (the loop only keeps going when the search endpoint takes more than ~100ms, a dev instance with xdebug is slow enough):

  1. Create a card titled zzloop on board A, make sure nothing else matches
  2. Open board A and type zzloop into the search field
  3. Before: "No results found", then ~20 requests/s for search?term=zzloop&cursor=<that card's lastModified>, all cancelled, also after clearing the field (term=). After: 2 requests and that's it, clearing sends one more
  4. Searching for something with more than 20 matches on another board still loads the next pages when scrolling the results to the end

Should be backported to stable35, 1.19.2 has the bug.

TODO

  • Nothing left

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Tests (unit, integration, api and/or acceptance) are included
  • Documentation (manuals or wiki) has been updated or is not required

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (ClaudeCode:claude-opus-5-5)

Claude Code helped track down the cause, wrote the fix and the unit tests, and ran the verification below on a local Nextcloud 36 dev instance. I reviewed and tested it myself as well.

Verification details

Requests counted with an in-page XHR recorder, Chrome 158, Nextcloud 36.0.0 dev, Deck main at 7650cb5.

On main, pasting a term whose only match is on the open board loops at ~19 req/s with the cursor stuck, until the recorder stopped it at 80 requests.

With this PR, on the same instance:

  • Paste that term: 2 requests, then nothing. Clearing the field: 1 more
  • Type it letter by letter: 2 requests per keystroke, settles
  • Clear while page 2 is loading, then type another term: settles, 5 requests total
  • 45 matches on another board, scroll the results to the end: pages 1-3 load, the empty 4th page ends it, all 45 cards shown
  • Switch to the board that holds the results with the search still open: no extra requests
  • Open a card from the results: no extra requests
  • Overview (Upcoming) with a search carried over from a board: no requests, there's no search field there and the component only renders its empty state

npx jest (56 passed), eslint and stylelint on the changed files are clean.

Assisted by ClaudeCode:claude-opus-5-5

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Chen Asraf <casraf@pm.me>
@chenasraf

Copy link
Copy Markdown
Author

/backport to stable35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global search still loops cancelled requests after 2ffe5f09

2 participants