Skip to content

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Mar 3, 2024

In useQueries, property tracking is still performed on each individual observer. However, not all invocations will access the property on all observers. For example:

results.some((result) => result.isLoading)

will only track the isLoading property of the first query in the array if isLoading is true, because the loop will eagerly abort, and thus the property isn't accessed at all on other observer, which can lead to missing re-renders.

This fix adds a callback to trackProperties, which will be invoked when we start to track a property on an observer. Then, in useQueries, we can use this callback to track the property manually for all observers.

That makes sure that if a property like isLoading is accessed on one observer, it is tracked for all of them.

fixes #7000

…n useQueries tracks properties across all observers

In useQueries, property tracking is still performed on each individual observer. However, not all invocations will access the property on all observers. For example:

```
results.some((result) => result.isLoading)
```

will only track the `isLoading` property of the first query in the array if `isLoading` is true, because the loop will eagerly abort, and thus the property isn't accessed at all on other observer, which can lead to missing re-renders.

This fix adds a callback to `trackProperties`, which will be invoked when we start to track a property on an observer. Then, in useQueries, we can use this callback to trigger the accessor manually for all other observers.

That makes sure that if a property like `isLoading` is accessed on one observer, it is tracked for all of them.
@vercel
Copy link

vercel bot commented Mar 3, 2024

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 Mar 3, 2024 8:17pm

@nx-cloud
Copy link

nx-cloud bot commented Mar 3, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1971f74. 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.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 3, 2024

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 1971f74:

Sandbox Source
@tanstack/query-example-angular-basic Configuration
@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

@TkDodo TkDodo merged commit 5e64873 into main Mar 3, 2024
@TkDodo TkDodo deleted the feature/tracked-use-queries branch March 3, 2024 21:23
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.

Buggy interaction between returning filtered data in the combine property for useQueries function

2 participants