Skip to content
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

fix: double invalidate bug #25

Merged
merged 3 commits into from
Mar 1, 2025

Conversation

sinasab
Copy link
Contributor

@sinasab sinasab commented Feb 28, 2025

Currently, if a query gets invalidated while its state is Loading(Some(value)), it loses the value. This can be annoying in cases where the query is invalidated multiple times within a short timespan, or for long-running queries.

We can fix this by nooping set_loading calls for queries that are already loading, which is what this change adds.

Manually verified this behavior locally via dx serve --example queries 🫡

Currently, if a query gets invalidated while its state is Loading(Some(value)), it loses the value. This can be annoying in cases where the query is invalidated multiple times within a short timespan, or for long-running queries.

We can fix this by nooping set_loading calls for queries that are already loading, which is what this change adds.
@marc2332 marc2332 self-requested a review March 1, 2025 09:37
@marc2332
Copy link
Owner

marc2332 commented Mar 1, 2025

But how is the value lost if there is this:

let result = mem::replace(self, Self::Pending).into();
// this:
if let Some(v) = result {
    *self = Self::Loading(Some(v))
}

to consider:

impl<T, E> From<MutationResult<T, E>> for Option<T> {
    fn from(result: MutationResult<T, E>) -> Self {
        match result {
            MutationResult::Ok(v) => Some(v),
            MutationResult::Err(_) => None,
            MutationResult::Loading(v) => v,
            MutationResult::Pending => None,
        }
    }
}

If the value was already Loading it would be assigned as loading again, not sure why would that not be the case, do you? 🤔

@sinasab
Copy link
Contributor Author

sinasab commented Mar 1, 2025

Cleaned up fix looks good, thanks for taking a look 😁

@marc2332 marc2332 merged commit 77466cf into marc2332:main Mar 1, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants