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

chore: use trpc queryOptions in example #1153

Merged
merged 1 commit into from
Feb 18, 2025
Merged

chore: use trpc queryOptions in example #1153

merged 1 commit into from
Feb 18, 2025

Conversation

juliusmarminge
Copy link
Member

@juliusmarminge juliusmarminge commented Feb 18, 2025

Summary by CodeRabbit

  • Refactor
    • Updated the app's data-handling workflows to provide more consistent and responsive file management, including streamlined refresh and update behavior during file uploads and deletions.
  • Chores
    • Upgraded core dependencies to the latest versions to enhance overall application stability and performance.

Copy link

changeset-bot bot commented Feb 18, 2025

⚠️ No Changeset found

Latest commit: 07bd744

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Feb 18, 2025

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

Name Status Preview Comments Updated (UTC)
docs-uploadthing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 18, 2025 0:44am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
legacy-docs-uploadthing ⬜️ Ignored (Inspect) Feb 18, 2025 0:44am

Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

Walkthrough

The changes refactor the data-handling approach by replacing TRPC utilities and providers with the React Query library. In the application layout and components, TRPC’s context and hooks (like trpc.useUtils() and trpc.getFiles.useQuery()) are replaced with React Query’s QueryClientProvider, useQueryClient(), useQuery(), and useMutation(). This update affects components that fetch data, handle mutations (e.g., file deletion), and invalidate queries. The TRPC client initialization is also refactored, and dependency versions are upgraded accordingly.

Changes

File(s) Change Summary
examples/minimal-expo/app/_layout.tsx, examples/minimal-expo/app/index.tsx Replaced <TRPCProvider> with <QueryClientProvider client={queryClient}> in the layout; updated data-fetching logic in HomeScreen by replacing TRPC hooks with React Query’s useQuery() and query invalidation with queryClient.invalidateQueries().
examples/minimal-expo/components/file-item.tsx, examples/minimal-expo/components/upload-drawer.tsx Updated mutation handling and cache invalidation: replaced TRPC’s mutation and query utilities with React Query’s useMutation() and useQueryClient(), adjusting callbacks (onMutate, onSettled) accordingly.
examples/minimal-expo/lib/trpc.tsx Modified TRPC client initialization by introducing createTRPCOptionsProxy and creating a new queryClient instance; removed the TRPCProvider and refactored the resolveUrl declaration.
examples/minimal-expo/package.json Upgraded dependency versions for @trpc/client and @trpc/server from 11.0.0-rc.452 to 11.0.0-rc.772 and added @trpc/tanstack-react-query with version 11.0.0-rc.772.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant HS as HomeScreen Component
    participant QC as QueryClient
    participant S as Server

    U->>HS: Visit HomeScreen
    HS->>QC: Call useQuery(trpc.getFiles.queryOptions())
    QC->>S: Fetch file data
    S-->>QC: Return files data
    QC-->>HS: Deliver data
Loading
sequenceDiagram
    participant U as User
    participant FI as FileItem Component
    participant QC as QueryClient
    participant S as Server

    U->>FI: Trigger delete file action
    FI->>QC: Call useMutation(trpc.deleteFile.mutationOptions)
    QC->>S: Execute delete file request
    S-->>QC: Acknowledge deletion
    QC-->>FI: Update cache data via setQueryData
    FI->>QC: Invalidate queries (queryClient.invalidateQueries)
Loading

Suggested labels

📚 documentation

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 3 workspace projects
/tmp/eslint/packages/uploadthing:
 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND  In packages/uploadthing: "@uploadthing/mime-types@workspace:*" is in the dependencies but no package named "@uploadthing/mime-types" is present in the workspace

This error happened while installing a direct dependency of /tmp/eslint/packages/uploadthing

Packages found in the workspace:


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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. (Beta)
  • @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

📦 Bundle size comparison

Bundle Size (gzip) Visualization
Main 30.66KB See Treemap 📊
PR (60e84d4) 30.66KB See Treemap 📊
Diff No change

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

🧹 Nitpick comments (2)
examples/minimal-expo/lib/trpc.tsx (2)

9-15: Defining a global QueryClient for the app.

Centralizing the query client is a solid approach. If you foresee advanced features (like SSR, offline support, or caching strategies), ensure you configure the default options accordingly or conditionally override them. Otherwise, this looks good.


18-33: Constructing the TRPC proxy with a shared QueryClient.

This approach neatly integrates TRPC with React Query by passing the queryClient. The creation of the TRPC client is straightforward and should work seamlessly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2f3f87 and 07bd744.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • examples/minimal-expo/app/_layout.tsx (3 hunks)
  • examples/minimal-expo/app/index.tsx (3 hunks)
  • examples/minimal-expo/components/file-item.tsx (2 hunks)
  • examples/minimal-expo/components/upload-drawer.tsx (4 hunks)
  • examples/minimal-expo/lib/trpc.tsx (1 hunks)
  • examples/minimal-expo/package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: bundle-analyze-result
  • GitHub Check: e2e-node (backend-adapters)
  • GitHub Check: build
🔇 Additional comments (10)
examples/minimal-expo/lib/trpc.tsx (2)

1-4: Imports look consistent with the new React Query integration.

These additions align well with the planned shift to @tanstack/react-query and @trpc/tanstack-react-query. No immediate issues noted.


41-41: Refactoring resolveUrl into a function declaration.

This change is stylistic but clear. The try-catch block is sufficient for runtime errors, so no issues there.

examples/minimal-expo/app/_layout.tsx (2)

5-15: Introducing QueryClientProvider and removing TRPCProvider.

Replacing TRPCProvider with QueryClientProvider is consistent with the new data-fetching pattern. The import references to your exported queryClient are correctly set up.


19-35: Wrapping the app with QueryClientProvider.

Providing the queryClient at the root ensures all nested components access the same query context. Looks good for your shifted approach to React Query.

examples/minimal-expo/app/index.tsx (3)

3-3: Swapping in React Query imports.

Using useQuery and useQueryClient aligns perfectly with the new architecture.


12-13: Using the shared query client and query options.

This pattern streamlines fetching while retaining type safety via trpc.getFiles.queryOptions(). No immediate concerns.


38-40: Invalidating queries with React Query’s approach.

Replacing utils.getFiles.invalidate() with queryClient.invalidateQueries(trpc.getFiles.queryFilter()) is correct. Remember to handle error states or data staleness if it arises.

examples/minimal-expo/components/file-item.tsx (1)

3-3: LGTM! Clean transition to React Query.

The changes effectively migrate from TRPC to React Query while maintaining type safety through trpc.deleteFile.mutationOptions. The cache management is properly handled with optimistic updates and invalidation.

Also applies to: 21-34

examples/minimal-expo/components/upload-drawer.tsx (1)

8-8: LGTM! Consistent cache invalidation with React Query.

The changes properly migrate cache invalidation from TRPC utils to React Query's queryClient, maintaining consistency across both image and PDF upload handlers.

Also applies to: 19-19, 30-30, 50-50

examples/minimal-expo/package.json (1)

19-21: LGTM! Dependencies are properly aligned.

The TRPC packages are consistently updated to version 11.0.0-rc.772, and the new @trpc/tanstack-react-query package is added to support the migration to React Query.

@juliusmarminge juliusmarminge merged commit 02a800c into main Feb 18, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant