Skip to content

Asynchronous mutations are handled when finished. #3031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mhverbakel opened this issue Oct 27, 2024 · 1 comment
Open

Asynchronous mutations are handled when finished. #3031

mhverbakel opened this issue Oct 27, 2024 · 1 comment

Comments

@mhverbakel
Copy link

Bug report

Description / Observed Behavior

When you provide an asynchronous function to the mutate function, the duration of the Promise does not seem to affect the other processes until it is resolved. isValidating is false for the duration of the Promise, and the automatic refresh intervals still get executed during the remote update.

Expected Behavior

When mutate is called with a data function that returns a Promise, the isValidating should go to true immediately, blocking any scheduled refreshing of the data.

Repro Steps / Code Example

https://codesandbox.io/p/sandbox/ts8qx3 (instructions included in example)

Additional Context

SWR Version 2.2.5

The test suite has tests for local mutations which includes tests for isValidating, but the remote mutation tests seem to lack this.

@Oripi
Copy link

Oripi commented Mar 5, 2025

tried to dig into the code, but i guess it's more than a 15m job :)
looks like the mutation is awaiting for the data without updating the state of the swr hook.
the awaiting code: https://github.com/vercel/swr/blob/main/src/_internal/utils/mutate.ts#L165
hopefully a maintainer will notice this and try to solve it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants