Skip to content

placeholderData codemod #6196

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
merged 8 commits into from
Oct 31, 2023

Conversation

balazsmatepetro
Copy link
Contributor

Closes #5760

@vercel
Copy link

vercel bot commented Oct 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Visit Preview Oct 31, 2023 10:17am

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 19, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a1ff22b:

Sandbox Source
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

@nx-cloud
Copy link

nx-cloud bot commented Oct 20, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit a1ff22b. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@balazsmatepetro balazsmatepetro marked this pull request as ready for review October 30, 2023 17:59
@balazsmatepetro
Copy link
Contributor Author

@TkDodo please review the contents of the default.input.tsx and default.output.tsx files. If these files contain the necessary amount of examples, and the output of the code mod is correct, then I think we can merge it.

Shall I mention somewhere it's designed to work with only object expressions?

@@ -0,0 +1,90 @@
import * as React from 'react'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TkDodo please review the output of the codemod.

const { isKeepPreviousDataInUse } = transformUsages({
...dependencies,
config: {
hooks: ['useInfiniteQuery', 'useQueries', 'useQuery'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TkDodo other hooks might be affected?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops I missed this comment. We also have the global defaults like:

new QueryClient({
  defaultOptions: {
    queries: {
      keepPreviousData: true
    }
  }
})

and:

queryClient.setQueryDefaults(['key'], {
  keepPreviousData: true
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry, I will open another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov-commenter
Copy link

We're currently processing your upload. This comment will be updated when the results are available.

@TkDodo TkDodo merged commit d4c9f42 into TanStack:main Oct 31, 2023
balazsmatepetro added a commit to balazsmatepetro/react-query that referenced this pull request Nov 1, 2023
…ryClient` instance with the codemod

For further details see: TanStack#6196 (comment)
balazsmatepetro added a commit to balazsmatepetro/react-query that referenced this pull request Nov 1, 2023
TkDodo added a commit that referenced this pull request Nov 3, 2023
* chore(codemod): add named examples to the `keep-previous-data` codemod, because these were missing

* chore(codemod): remove the unnecessary `return` statement

* feat(codemod): cover the `setQueryDefaults` method usages on the `QueryClient` instance with the codemod

For further details see: #6196 (comment)

* chore(codemod): rename the `isKeepPreviousDataInUse` to `shouldAddKeepPreviousDataImport`

The new name describes better the purpose of this variable.

* feat(codemod): cover the `QueryClient` class instantiations with the codemod

For further details see: #6196 (comment)

* chore(codemod): fix `eslint` issues within the `keep-previous-data` codemod

* chore(codemod): fix the `prettier` issues within the `keep-previous-data` codemod README file

* chore(codemod): turn off the `sort-imports` ESLint rule in case of the codemods

Since the codemods might not respect the import order, it's easier to turn off the `sort-imports` ESLint rule.

---------

Co-authored-by: Dominik Dorfmeister <[email protected]>
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.

v5: keepPreviousData codemod
3 participants