Skip to content

fix(examples, docs): ignored promise from invalidate queries #8847

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

Merged

Conversation

keyurgovrani
Copy link
Contributor

@keyurgovrani keyurgovrani commented Mar 23, 2025

This PR fixes the issue of Promise returned from invalidateQueries being ignored in documentation and examples

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 23, 2025
@keyurgovrani keyurgovrani force-pushed the fix/ignored-promise-from-invalidate-queries branch from 624b3b1 to 1875663 Compare March 23, 2025 19:03
@keyurgovrani keyurgovrani changed the title fix: ignored promise from invalidate queries fix(examples): ignored promise from invalidate queries Mar 23, 2025
@keyurgovrani keyurgovrani changed the title fix(examples): ignored promise from invalidate queries fix(examples, docs): ignored promise from invalidate queries Mar 23, 2025
@keyurgovrani keyurgovrani force-pushed the fix/ignored-promise-from-invalidate-queries branch 2 times, most recently from cde6864 to 3bfb5d6 Compare March 23, 2025 19:13
@TkDodo
Copy link
Collaborator

TkDodo commented Mar 24, 2025

the promise in the current code is not ignored:

onSettled: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),

this code returns the promise from invalidateQueries, because arrow functions return the statement (if they have no brackets), and invalidateQueries returns a promise.

Wrapping this in return await is unnecessary.

@TkDodo TkDodo closed this Mar 24, 2025
@keyurgovrani
Copy link
Contributor Author

Thank you @TkDodo for your feedback on my pull request. While it's true that arrow functions without braces return the result of their expression, I encountered issues with the code's behaviour, especially when arrow functions have curly braces. In those cases, an explicit return is required, and ESLint flagged warnings about the promise being ignored. This would ensure the promise is properly handled while maintaining both functionality and code quality. Could you please reconsider this approach and revisit the matter?

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 26, 2025

I encountered issues with the code's behaviour, especially when arrow functions have curly braces

yes because then you don’t return a Promise from the function. This is just how javascript works. You can return a Promise, or not. You can use arrow functions or not. You can write the same thing in a million ways

onSuccess: async () => { return await queryClient.invalidateQueries(...) }
onSuccess: () => queryClient.invalidateQueries(...)
onSuccess() { return queryClient.invalidateQueries(...) }
onSuccess: function onSuccess() { return queryClient.invalidateQueries(...) }

@TkDodo TkDodo reopened this Mar 26, 2025
@keyurgovrani keyurgovrani force-pushed the fix/ignored-promise-from-invalidate-queries branch from 3bfb5d6 to 5b7f8ec Compare March 26, 2025 09:10
@keyurgovrani keyurgovrani requested a review from TkDodo March 26, 2025 09:23
Copy link

nx-cloud bot commented Mar 26, 2025

View your CI Pipeline Execution ↗ for commit b8a3821.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 47s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-26 09:27:54 UTC

@TkDodo TkDodo merged commit 3064422 into TanStack:main Mar 26, 2025
1 check passed
@keyurgovrani keyurgovrani deleted the fix/ignored-promise-from-invalidate-queries branch March 26, 2025 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants