Skip to content

Bug: Duplicate API calls instead of cache usage with useFetch (v8) #136

Description

@lobor

Describe the bug
When using useFetch from Hyper fetch v8 in multiple components rendered in a list, identical requests are executed multiple times instead of being deduplicated through cache sharing.

This leads to unnecessary duplicate API calls even when the fetcher and parameters are identical.


To Reproduce
Steps to reproduce the behavior:

  1. Create two components using the same useFetch hook
  2. Render them multiple times using a list (e.g. .map)
  3. Mount both components simultaneously in the same render tree
  4. Observe network / logs from the fetcher
  5. See that the same request is executed multiple times instead of being cached
function ComponentA() {
  const { data } = useFetch(getData);
  return <div>A</div>;
}

function ComponentB() {
  const { data } = useFetch(getData);
  return <div>B</div>;
}

export default function App() {
  const items = Array.from(Array(22).keys());
  return (
    <>
      {items.map((_, index) => (
        <Fragment key={index}>
          <ComponentA />
          <ComponentB />
        </Fragment>
      ))}
    </>
  );
}

Expected behavior

  • Only one network request should be executed
  • All hook instances should share the same cached result
  • No duplicate API calls should occur for identical requests

Screenshots
Not applicable (behavior observable via network tab or console logs)


Smartphone (please complete the following information):

  • Device: Pixel 9
  • OS: android

Additional context

  • Issue occurs when multiple components using the same useFetch hook are rendered in a list
  • Each component independently triggers the same request
  • Suggests cache deduplication is not shared across hook instances or mounts
  • Behavior is consistent even when rendering identical fetchers in the same render cycle
  • Likely related to cache key resolution or request deduplication timing in v8

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