Skip to content
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

[BUG]: Memoize TRPC call within store to populate branches #403

Open
ttebify opened this issue Apr 20, 2023 · 0 comments
Open

[BUG]: Memoize TRPC call within store to populate branches #403

ttebify opened this issue Apr 20, 2023 · 0 comments
Labels
🐞 bug Something isn't working 🙏 help wanted Extra attention is needed 🖥️ platform For envless platform

Comments

@ttebify
Copy link
Collaborator

ttebify commented Apr 20, 2023

Describe the bug

I noticed an issue with our current implementation of the zustand branches store. Currently, the query that sets the branches to the store is made only on the /projects/[slug]/index.tsx page, which works well. However, when a user goes to a page that needs the branch store without navigating from /projects/[slug]/index.tsx, the store is empty.

Steps to reproduce

  1. Go to the /projects/[slug]/index.tsx page.
  2. Check that the branches store is correctly initialized and has data by visiting the branches.
  3. Navigate to another page that requires the branches store, without first going to /projects/[slug]/index.tsx. For instance, you can copy and paste the URL of the "create new pull request" page into your browser and open it.
  4. Verify that the branches store is empty.

Expected behavior

I think we should create a memoized TRPC call within the store to populate the branches, instead of making the query only on the index page. The memoized call will ensure that the data is cached and only fetched when necessary, improving performance.

We should initialise the store before using it, but we shouldn't load it globally. We can do this by creating an initialise function that is called only when needed.

The API could look like this:

const { branches, baseBranch, setBaseBranch } = useBranchesStore({ projectId: xxxxxx });

Screenshots

No response

Additional information

No response

@ttebify ttebify added 🐞 bug Something isn't working 🙏 help wanted Extra attention is needed 🖥️ platform For envless platform labels Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🙏 help wanted Extra attention is needed 🖥️ platform For envless platform
Projects
None yet
Development

No branches or pull requests

1 participant