Skip to content

bug: xref-db caches empty array for missing results, preventing future resolution #5256

@marcoscaceres

Description

@marcoscaceres

Description

In src/core/xref-db.js:90, cacheXrefData() stores results.get(query.id) ?? [] into IDB. When the xref API returns no result for a query ID, an empty array is cached.

On subsequent page loads, resolveXrefCache() finds a cache hit (the empty array) and considers the query resolved, never re-fetching from the network. This permanently suppresses xref results for terms that were temporarily missing from the API.

Steps to reproduce

  1. Author uses [=some-term=] that is temporarily not in the xref database
  2. ReSpec fetches xref API, gets no result
  3. Empty array [] is cached in IDB for that query
  4. Term is later added to the xref database
  5. ReSpec never re-fetches because IDB has a cache hit

Suggested fix

Skip caching queries with no results:

for (const query of queries) {
  const result = results.get(query.id);
  if (result?.length) {
    tx.objectStore(STORE_NAME).add({ query, result });
  }
}

Found by

Adversarial gate holdout test (blind review of PR #5169).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions