Skip to content

Conversation

@ymc9
Copy link
Member

@ymc9 ymc9 commented Dec 13, 2024

Summary by CodeRabbit

  • Documentation
    • Enhanced guidance on using the @zenstackhq/tanstack-query plugin with Next.js, including context provider usage.
    • Added information on automatic invalidation in mutation hooks.
    • Detailed the query key scheme for better understanding of cache organization.

@vercel
Copy link

vercel bot commented Dec 13, 2024

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

Name Status Preview Comments Updated (UTC)
zenstack-new-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 13, 2024 7:55am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The pull request introduces enhancements to the documentation for the @zenstackhq/tanstack-query plugin. Key updates include a new section on the Next.js app router, clarifying the use of React context providers in React Server Components. It also details the default behavior of automatic invalidation in mutation hooks and provides a description of the query key scheme used by generated hooks. These changes aim to improve user guidance for implementing the plugin, particularly in Next.js applications.

Changes

File Path Change Summary
docs/reference/plugins/tanstack-query.mdx - Added section on Next.js app router and context providers usage.
- Introduced invalidateQueries option in mutation hooks documentation.
- Added description of the query key scheme for generated hooks.

Possibly related PRs

  • doc: replace swr with TanStack for next page router tutorial #337: This PR updates the documentation for integrating ZenStack with Next.js, which is relevant as the main PR also enhances documentation related to the Next.js app router and context providers.
  • docs: add FAQ to tanstack-query #385: This PR adds an FAQ section addressing a specific error in Next.js applications, which relates to the main PR's focus on clarifying the use of context providers in Next.js.
  • docs: release 2.10.0 #399: This PR clarifies the functionality of the generated hooks in the @zenstackhq/tanstack-query plugin, which aligns with the main PR's updates on query key schemes and mutation hooks documentation.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
docs/reference/plugins/tanstack-query.mdx (3)

186-209: Enhance RSC documentation with alternative approaches

The section accurately explains the RSC limitation and provides a good solution using a client component wrapper. However, it would be helpful to explicitly mention the alternative approach of using the 'use client' directive in the layout component, along with its trade-offs.

Consider adding a note like:

 Next.js's app router renders components as React Server Components (RSC) by default. React context providers are not supported in RSC. If you're configuring the context providers in such a setup, please make sure to wrap them inside a client component, or set the containing layout as client component.

+There are two approaches to handle this:
+1. Create a separate client component for providers (recommended, as shown in the example below)
+2. Convert the layout component to a client component by adding 'use client' directive
+
+The first approach is preferred as it maintains RSC benefits for the rest of your layout component.

Line range hint 583-589: Improve visibility and context of invalidation documentation

While the information about automatic invalidation is accurate, its importance might be overlooked in the current info box placement.

Consider these improvements:

  1. Move this information higher up in the "Query Invalidation" section
  2. Add a brief example showing the default behavior in action:
 The automatic invalidation is enabled by default, and you can use the `invalidateQueries` option to opt-out and handle revalidation by yourself.

+For example:
+```ts
+// Queries are automatically invalidated (default behavior)
+const { mutate: createPost } = useCreatePost();
+
+// Opt-out of automatic invalidation
+const { mutate: createPostManual } = useCreatePost({ invalidateQueries: false });
+```
🧰 Tools
🪛 LanguageTool

[grammar] ~213-~213: It appears that a hyphen is missing in the noun “To-do” (= task) or did you mean the verb “to do”?
Context: ...ng app. You can find a fully functional Todo app example [here](https://github.com/z...

(TO_DO_HYPHEN)


Line range hint 591-617: Add practical examples of query key usage

The query key documentation is clear and well-structured. However, it would be more helpful to include common use cases for query keys.

Consider adding examples like:

 You can use the generated `getQueryKey` function to compute it.

 The query hooks also return the query key as part of the result object.

 ```ts
 const { data, queryKey } = useFindUniqueUser({ where: { id: '1' } });

+Here are some common use cases for query keys:
+
+```ts
+// 1. Prefetching data
+const queryClient = useQueryClient();
+const queryKey = getQueryKey.findUniqueUser({ where: { id: '1' } });
+await queryClient.prefetchQuery({ queryKey, queryFn: () => fetchUser('1') });
+
+// 2. Manual cache invalidation
+queryClient.invalidateQueries({

  • queryKey: ['zenstack', 'User'],
  • exact: false // invalidate all User queries
    +});

+// 3. Accessing cached data
+const cachedUser = queryClient.getQueryData(queryKey);
+```


<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[grammar] ~213-~213: It appears that a hyphen is missing in the noun “To-do” (= task) or did you mean the verb “to do”?
Context: ...ng app. You can find a fully functional Todo app example [here](https://github.com/z...

(TO_DO_HYPHEN)

</details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 4a88ab4f9e98a0c3a8839ed67e91531f69f57be6 and 82c510dcd5cd5f3d6d86dcd78db69e4ab2b4fe39.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `docs/reference/plugins/tanstack-query.mdx` (1 hunks)

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@ymc9 ymc9 merged commit 627f7b5 into main Dec 13, 2024
3 checks passed
@ymc9 ymc9 deleted the doc/tanstack-rsc-notes branch December 13, 2024 08:04
This was referenced Nov 5, 2025
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.

2 participants