Skip to content

refactor(vue-query): use shallowRef to improve performance #5493

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

Closed
wants to merge 2 commits into from
Closed

refactor(vue-query): use shallowRef to improve performance #5493

wants to merge 2 commits into from

Conversation

RomainLanz
Copy link

@RomainLanz RomainLanz commented May 30, 2023

Hey there! 👋🏻

This PR refactors the useQueries composable to use a shallowRef instead of a ref to define the state.

If an object is assigned as a ref's value, the object is made deeply reactive. That is the case in the useQueries composable. Meaning if we had a huge data object, all its properties would be reactive, causing performance issues.

A shallowRef, in comparison, does not convert the object. The inner value is stored and exposed as-is.

This PR is in draft because I believe we can do the same optimization in the useQuery composable. I need to play with it and ensure nothing is breaking before making changes.

Related PR on VueUse repository to add a toShallowRef helper that could be used in useQuery.

Linked Discussion: #5400

@vercel
Copy link

vercel bot commented May 30, 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) Jun 30, 2023 10:20pm

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 30, 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 fc866bd:

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 May 31, 2023

☁️ Nx Cloud Report

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

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@TkDodo TkDodo deleted the branch TanStack:alpha July 24, 2023 09:59
@TkDodo TkDodo closed this Jul 24, 2023
@TkDodo
Copy link
Collaborator

TkDodo commented Jul 24, 2023

please reopen to the beta branch, thanks.

@GreatAuk
Copy link

useQuery return a readonly data, use ref seems is meaningless.

@RomainLanz
Copy link
Author

useQuery return a readonly data, use ref seems is meaningless.

It has to be a ref (or shallowRef) to ensure a rerender when data changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants