Open History to see the last commit
1# Contributing
2β
3## Questions
4β
5If you have questions about implementation details, help or support, then please use our dedicated community forum at [GitHub Discussions](https://github.com/TanStack/query/discussions) **PLEASE NOTE:** If you choose to instead open an issue for your question, your issue will be immediately closed and redirected to the forum.
6β
7## Reporting Issues
8β
9If you have found what you think is a bug, please [file an issue](https://github.com/TanStack/query/issues/new/choose). **PLEASE NOTE:** Issues that are identified as implementation questions or non-issues will be immediately closed and redirected to [GitHub Discussions](https://github.com/TanStack/query/discussions)
10β
11## Suggesting new features
12β
13If you are here to suggest a feature, first create an issue if it does not already exist. From there, we will discuss use-cases for the feature and then finally discuss how it could be implemented.
14β
15## Development
16β
17_TanStack/query uses **symlink-based** configuration files. For smooth development in a local environment, we recommend developing in an environment that supports symlinks(ex: Linux, macOS, Windows Subsystem for Linux / WSL)._
18β
19If you have been assigned to fix an issue or develop a new feature, please follow these steps to get started:
20β
21- Fork this repository.
22- Install dependencies
23β
24 ```bash
25 pnpm install
26 ```
27β
28 - We use [pnpm](https://pnpm.io/) v10 for package management (run in case of pnpm-related issues).
29β
30 ```bash
31 corepack enable && corepack prepare
32 ```
33β
34 - We use [nvm](https://github.com/nvm-sh/nvm) to manage node versions - please make sure to use the version mentioned in `.nvmrc`
35β
36 ```bash
37 nvm use
38 ```
39β
40- Build all packages.
41β
42 ```bash
43 pnpm build:all
44 ```
45β
46- Run development server.
47β
48 ```bash
49 pnpm run watch
50 ```
51β
52- Implement your changes and tests to files in the `src/` directory and corresponding test files.
53- Document your changes in the appropriate doc page.
54- Git stage your required changes and commit (see below commit guidelines).
55- Submit PR for review.
56β
57### Editing the docs locally and previewing the changes
58β
59The documentations for all the TanStack projects are hosted on [tanstack.com](https://tanstack.com), which is a TanStack Start application (https://github.com/TanStack/tanstack.com). You need to run this app locally to preview your changes in the `TanStack/query` docs.
60β
61> [!NOTE]
62> The website fetches the doc pages from GitHub in production, and searches for them at `../query/docs` in development. Your local clone of `TanStack/query` needs to be in the same directory as the local clone of `TanStack/tanstack.com`.
63β
64You can follow these steps to set up the docs for local development:
65β
661. Make a new directory called `tanstack`.
67β
68```sh
69mkdir tanstack
70```
71β
722. Enter that directory and clone the [`TanStack/query`](https://github.com/TanStack/query) and [`TanStack/tanstack.com`](https://github.com/TanStack/tanstack.com) repos.
73β
74```sh
75cd tanstack
76git clone git@github.com:TanStack/query.git
77# We probably don't need all the branches and commit history
78# from the `tanstack.com` repo, so let's just create a shallow
79# clone of the latest version of the `main` branch.
80# Read more about shallow clones here:
81# https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/#user-content-shallow-clones
82git clone git@github.com:TanStack/tanstack.com.git --depth=1 --single-branch --branch=main
83```
84β
85> [!NOTE]
86> Your `tanstack` directory should look like this:
87>
88> ```
89> tanstack/
90> |
91> +-- query/ (<-- this directory cannot be called anything else!)
92> |
93> +-- tanstack.com/
94> ```
95β
963. Enter the `tanstack/tanstack.com` directory, install the dependencies and run the app in dev mode:
97β
98```sh
99cd tanstack.com
100pnpm i
101# The app will run on https://localhost:3000 by default
102pnpm dev
103```
104β
1054. Now you can visit http://localhost:3000/query/latest/docs/framework/react/overview in the browser and see the changes you make in `tanstack/query/docs` there.
106β
107> [!WARNING]
108> You will need to update the `docs/config.json` file (in `TanStack/query`) if you add a new documentation page!
109β
110You can see the whole process in the screen capture below:
111β
112https://github.com/fulopkovacs/form/assets/43729152/9d35a3c3-8153-4e74-9cb2-af275f7a269b
113β
114### Running examples
115β
116- Make sure you've installed the dependencies in the repo's root directory.
117β
118 ```bash
119 pnpm install
120 ```
121β
122- If you want to run the example against your local changes, run below in the repo's root directory. Otherwise, it will be run against the latest TanStack Query release.
123β
124 ```bash
125 pnpm run watch
126 ```
127β
128- Run below in the selected examples' directory.
129β
130 ```bash
131 pnpm run dev
132 ```
133β
134#### Note on standalone execution
135β
136If you want to run an example without installing dependencies for the whole repo, just follow the instructions from the example's README.md file. It will then be run against the latest TanStack Query release.
137β
138## Online one-click setup
139β
140You can use Gitpod (An Online open-source VS Code-like IDE that is free for Open Source) for developing online. With a single click it will start a workspace and automatically:
141β
142- clone the `TanStack/query` repo.
143- install all the dependencies in `/` and `/docs`.
144- run below in the root(`/`) to Auto-build files.
145β
146 ```bash
147 npm start
148 ```
149β
150- run below in `/docs`.
151β
152 ```bash
153 npm run dev
154 ```
155β
156[](https://gitpod.io/#https://github.com/TanStack/query)
157β
158## Changesets
159β
160This repo uses [Changesets](https://github.com/changesets/changesets) to automate releases. If your PR should release a new package version (patch, minor, or major), please run `pnpm changeset` and commit the file. If needed, changeset descriptions can be more descriptive, and will be included in the changelog. If your PR affects docs, examples, styles, etc., you probably don't need to generate a changeset.
161β
162## Pull requests
163β
164Maintainers merge pull requests by squashing all commits and editing the commit message if necessary using the GitHub user interface.
165β
166Use an appropriate commit type. Be especially careful with breaking changes.
167β
168## Releases
169β
170For each new commit added to `main`, a GitHub Workflow is triggered which runs the [Changesets Action](https://github.com/changesets/action). This generates a preview PR showing the impact of all changesets. When this PR is merged, the package will be published to NPM.
171β
172## π§ͺ Test
173β
174TanStack Query uses [Nx](https://nx.dev/) as its monorepo tool.
175To run tests in a local environment, you should use `nx` commands from the root directory.
176β
177### β
Run all tests
178β
179To run tests for **all packages**, run:
180β
181```bash
182npm run test
183```
184β
185### β
Run tests for a specific package
186β
187To run tests for a specific package, use the following command:
188β
189```bash
190npx nx run @tanstack/{package-name}:test:lib
191```
192β
193For example:
194β
195```bash
196npx nx run @tanstack/react-query:test:lib
197```
198β
199### β οΈ Caution
200β
201Do not run `pnpm run test:lib` inside individual package folders.
202This can cause test failures due to dependencies between packages.
203Always run tests from the **root folder** using `nx` commands.