Skip to content

Changes to key returning previous keys data #105

@DyBev

Description

@DyBev

🐞 Bug Report

Describe the bug

When changing the key of useFetchye, the first return of the function still returns the data of the previous run

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:
I used my fetchye-test repository on the fix/test-branch. running the pocketbase server locally and using the AppWithIdChange page on http://localhost:5173/id-change

  1. clone repo
  2. install dependencies
  3. Start the backend:
    a. ./database/pocketbase serve (Linux binary)
    b. ./database/pocketbase_mac serve (mac binary)
    c. admin login [email protected] password
  4. start the frontend:
    a. for dev build:
    - npm run dev
    b. for production build:
    - npm run build
    - npm run preview
  5. navigate to
    a. http://localhost:5173/id-change for dev
    b. http://localhost:4173/id-change for production preview
  6. watch logs return data of the previous key

Expected behavior

When the key changes the data returned should be relevent to the key

Implementation details

...
const id1 = 'n1kvy882szoh0v9'
const id2 = 'bl1xrv6z6rabdv3'

function App() {
  ...
  const [id, setId] = useState(id1);

  const { data: pocketdata, error: pocketerror, isLoading: pocketisLoading } = useFetchye(
    `http://127.0.0.1:8090/api/collections/testing/records/${id}`, {}, customFethcer
  );
  console.log({ id, location: 'AppWithIdChange', data: pocketdata, error: pocketerror, isLoading: pocketisLoading });

  useEffect(() => {
    setTimeout(() => {
		setId(id2)
	}, 4000);
  }, []);
  ...

I'm using a custom fetcher to add a 2s delay to the fetch call to test the loading state.

Screenshots

Before key change:
Image

After key change:
Image

System information

  • OS: macOS
  • Browser (not tested on other browse yet): firefox
  • Version of fetchye: 1.7.1
  • Node version: 23.6.0

Additional context

Issue found whilst I was testing my fix for my draft PR.

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