Skip to content

[Detail Bug] User Assets panel can show stale/mixed results when search or type filter changes during in-flight requests #39138

In review

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_3377c26d-da48-4ccd-b83a-22c542f4fe83/bugs/bug_4e1b71ea-84d7-42d0-83ff-a0b1e35277bb

Introduced in #36006 by @Rohit0301 on Oct 23, 2026

Summary

  • Context: useUserAssetsList powers the search/filterable asset list in the User Assets panel (UserAssetsView) on the user profile page, paging results from the search API and guarding against slow/duplicated responses.
  • Bug: When the search text or type filter changes, the hook resets its list state during render but only bumps the stale-response counter (requestRef) later inside fetchPage, which runs in a passive effect — so a response belonging to the previous search/filter that settles in the window between the reset commit and the effect still passes the isCurrent() guard and commits stale data.
  • Actual vs. expected: The hook's own documented invariant is "Only the latest request may write state, so a slow earlier page or search can't overwrite a newer one", and the reset is meant to show "a loader rather than 'no match'" until the new query's results arrive — instead, the cleared list is repopulated with the previous query's hits; if a Load-more is then triggered from the stale frame, the load-more request is issued with the new query but the stale page number, and its newer request id causes the correct in-flight page-1 response to be discarded, leaving the panel showing the previous query's results mixed with wrong-page results of the new query until the user searches again.
  • Impact: The user assets panel renders wrong assets for the user's current search/filter — transiently in the plain case, where the new query's page-1 response replaces the stale list once it lands; in the load-more variant, the corrupted mixed list (previous query's pages + new query's wrong page) with an inconsistent total does not self-correct, and only a further search/filter change can recover it.

Code with Bug

openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/UserAssets/useUserAssetsList.ts

  // Clear the previous list during render, so the frame before the new
  // request starts shows a loader rather than "no match".
  const listKey = `${kind}|${ownerIdsKey}|${search}|${indexes.join(',')}`;
  const [prevListKey, setPrevListKey] = useState(listKey);
  if (prevListKey !== listKey) {
    setPrevListKey(listKey);
    setPage(1);
    setAssets([]);
    setError(undefined);
    setIsLoading(true);
    // <- BUG 🔴 requestRef.current is NOT bumped here, so prior in-flight responses still look "current"
  }
  const fetchPage = useCallback(
    async (pageNumber: number) => {
      // Only the latest request may write state, so a slow earlier page or
      // search can't overwrite a newer one.
      const requestId = ++requestRef.current; // <- BUG 🔴 only bump occurs here (passive effect), after the reset commit
      const isCurrent = () => requestId === requestRef.current;
      ...
      if (!isCurrent()) {
        return;
      }
      ...
      setAssets((prev) =>
        pageNumber === 1 ? hits : uniqBy([...prev, ...hits], 'id')
      );
      setPage(pageNumber);

Explanation

  • The hook resets state when listKey changes during render, but the next fetchPage(1) is started from a useEffect. Between the reset commit and the effect running, an older in-flight request (for the previous listKey) can resolve.
  • Because the reset does not invalidate in-flight work (requestRef.current is unchanged), the old response still satisfies isCurrent() and writes assets/page/total/isLoading, repopulating the cleared list with stale results.
  • If a load-more is triggered from that stale state, it can compute the next page from the stale page while using the new query params, causing wrong-page results for the new query to be appended; the newer request id then causes the correct page-1 response for the new query to be discarded.

Recommended Fix

Invalidate pre-reset requests when the reset runs so any response from the previous listKey becomes non-current:

  if (prevListKey !== listKey) {
    setPrevListKey(listKey);
    requestRef.current += 1; // <-- FIX 🟢 invalidate pre-reset in-flight responses
    setPage(1);
    setAssets([]);
    setError(undefined);
    setIsLoading(true);
  }

History

This bug was introduced in commit df19bff (PR #36006), which added the User Assets feature and the useUserAssetsList hook with a render-phase reset and a request counter bumped only when the effect-started fetch begins.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions