Skip to content

Conversation

@KATT
Copy link
Member

@KATT KATT commented Jun 25, 2025

Closes #

🎯 Changes

Refactors next-minimal to app router

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Summary by CodeRabbit

  • New Features

    • Introduced new React components and layout using the Next.js App Router, including examples for tRPC queries and subscriptions.
    • Added server-side and client-side integration for tRPC with React Query, supporting data prefetching and hydration.
    • Enabled tRPC API routes with GET and POST handlers in the new App Router structure.
  • Chores

    • Updated documentation to reflect usage of the App Router and switched example commands from npm to pnpm.
    • Updated dependencies, removing @trpc/react-query and adding @tanstack/react-query-devtools and @trpc/tanstack-react-query.
    • Removed "Using Next.js" link from the documentation navbar.
  • Refactor

    • Migrated from the Pages Router to the App Router structure.
    • Reorganized tRPC and React Query integration for improved modularity and clarity.
    • Removed previous Pages Router files and consolidated tRPC client setup.
    • Removed custom path aliasing from TypeScript configuration.
  • Style

    • Applied global font and metadata settings in the new root layout.
  • Documentation

    • Updated README and TypeScript config comments for clarity and current best practices.
    • Removed the Next.js Prisma starter example section from the documentation.

@KATT KATT requested a review from a team as a code owner June 25, 2025 13:42
@vercel
Copy link

vercel bot commented Jun 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
next-prisma-starter Ready Ready Preview Aug 18, 2025 10:16pm
og-image Ready Ready Preview Comment Aug 18, 2025 10:16pm
www Error Error Aug 18, 2025 10:16pm

@railway-app
Copy link

railway-app bot commented Jun 25, 2025

πŸš… Deployed to the trpc-pr-6839 environment in trpc-sse-and-websockets

Service Status Web Updated (UTC)
next-sse-chat 😴 Sleeping (View Logs) Web Nov 4, 2025 at 3:02 am
next-prisma-websockets-starter ❌ Build Failed (View Logs) Aug 18, 2025 at 10:26 pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Important

Review skipped

Review was skipped due to path filters

β›” Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update migrates the examples/next-minimal-starter project from the Next.js Pages Router to the App Router architecture. It restructures the app to use React Server Components, introduces new tRPC and React Query integration patterns, updates dependencies, and removes obsolete files and path aliases to align with modern Next.js and tRPC best practices.

Changes

File(s) Change Summary
README.md, next-env.d.ts, tsconfig.json Updated documentation, TypeScript config, transformer URL, and removed path aliases.
package.json Removed @trpc/react-query, added @tanstack/react-query-devtools and @trpc/tanstack-react-query.
src/pages/_app.tsx, src/pages/index.ts, src/utils/trpc.ts Deleted legacy Pages Router entrypoint, example page, and tRPC client utility.
src/app/api/trpc/[trpc]/route.ts Added tRPC API route handler for App Router.
src/app/content.tsx Added new client component demonstrating tRPC queries and subscriptions with React Query.
src/app/layout.tsx Added App Router root layout with global font, metadata, and tRPC provider.
src/app/page.tsx Added main page component with data prefetching and hydration.
src/trpc/query-client.ts Added React Query client factory with custom hydration/dehydration logic.
src/trpc/server/init.ts Refactored tRPC server init: added context, updated transformer import, and typed tRPC instance.
src/trpc/server/routers/_app.ts Updated and exported appRouter, changed input schema, and removed old API handler export.
src/trpc/server/server.tsx Added server-side tRPC/React Query integration with query client caching, prefetch, and hydration boundary.
src/trpc/trpc-client.tsx Added client-side tRPC provider with React Query integration and operation-based link splitting.
www/docs/main/example-apps.mdx Removed entire Next.js Prisma starter example section including commands and deployment links.
www/docusaurus.config.ts Removed "Using Next.js" link from the navigation bar.

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant RootLayout
    participant TRPCReactProvider
    participant Page
    participant trpc (client)
    participant tRPC API Route
    participant React Query Client

    Browser->>RootLayout: Load app
    RootLayout->>TRPCReactProvider: Wrap children with tRPC & React Query context
    Browser->>Page: Navigate to /
    Page->>trpc (client): Prefetch greeting query
    trpc (client)->>tRPC API Route: HTTP request for greeting
    tRPC API Route->>trpc (client): Respond with greeting data
    Page->>React Query Client: HydrateClient wraps Content
    Content->>trpc (client): useTRPC for query/subscription
    trpc (client)->>tRPC API Route: Query/subscribe as needed
Loading

Poem

In burrows new, our code now dwells,
App Router rings the modern bells.
With tRPC and queries neat,
Subscriptions hop on nimble feet.
Old paths and pages swept awayβ€”
The starter’s fresh for future play!
πŸ‡βœ¨

✨ Finishing Touches
πŸ§ͺ Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 06-25-minimal-again

πŸͺ§ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 2

🧹 Nitpick comments (2)
examples/next-minimal-starter/src/app/layout.tsx (1)

4-5: Remove unused imports.

The imports trpc from '../trpc/server/server' and TRPCProvider are not used in this component. Only TRPCReactProvider is needed.

-import { trpc } from '../trpc/server/server';
-import { TRPCProvider, TRPCReactProvider } from '../trpc/trpc-client';
+import { TRPCReactProvider } from '../trpc/trpc-client';
examples/next-minimal-starter/src/trpc/trpc-client.tsx (1)

9-9: Remove unused import.

httpBatchStreamLink is imported but not used in the code. Only httpBatchLink is used in the splitLink configuration.

-  httpBatchStreamLink,
πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 5b325d7 and 0a18d37.

β›” Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
πŸ“’ Files selected for processing (16)
  • examples/next-minimal-starter/README.md (2 hunks)
  • examples/next-minimal-starter/next-env.d.ts (1 hunks)
  • examples/next-minimal-starter/package.json (1 hunks)
  • examples/next-minimal-starter/src/app/api/trpc/[trpc]/route.ts (1 hunks)
  • examples/next-minimal-starter/src/app/content.tsx (1 hunks)
  • examples/next-minimal-starter/src/app/layout.tsx (1 hunks)
  • examples/next-minimal-starter/src/app/page.tsx (1 hunks)
  • examples/next-minimal-starter/src/pages/_app.tsx (0 hunks)
  • examples/next-minimal-starter/src/pages/index.tsx (0 hunks)
  • examples/next-minimal-starter/src/trpc/query-client.ts (1 hunks)
  • examples/next-minimal-starter/src/trpc/server/init.ts (1 hunks)
  • examples/next-minimal-starter/src/trpc/server/routers/_app.ts (1 hunks)
  • examples/next-minimal-starter/src/trpc/server/server.tsx (1 hunks)
  • examples/next-minimal-starter/src/trpc/trpc-client.tsx (1 hunks)
  • examples/next-minimal-starter/src/utils/trpc.ts (0 hunks)
  • examples/next-minimal-starter/tsconfig.json (1 hunks)
πŸ’€ Files with no reviewable changes (3)
  • examples/next-minimal-starter/src/pages/_app.tsx
  • examples/next-minimal-starter/src/utils/trpc.ts
  • examples/next-minimal-starter/src/pages/index.tsx
🧰 Additional context used
🧬 Code Graph Analysis (6)
examples/next-minimal-starter/src/app/page.tsx (2)
examples/next-minimal-starter/src/trpc/server/server.tsx (3)
  • prefetch (20-30)
  • trpc (14-18)
  • HydrateClient (32-40)
examples/next-minimal-starter/src/app/content.tsx (1)
  • Content (65-75)
examples/next-minimal-starter/src/app/api/trpc/[trpc]/route.ts (2)
packages/server/src/adapters/fetch/fetchRequestHandler.ts (1)
  • fetchRequestHandler (24-80)
examples/next-minimal-starter/src/trpc/server/routers/_app.ts (1)
  • appRouter (11-64)
examples/next-minimal-starter/src/app/layout.tsx (1)
examples/next-minimal-starter/src/trpc/trpc-client.tsx (1)
  • TRPCReactProvider (36-73)
examples/next-minimal-starter/src/trpc/query-client.ts (1)
examples/next-minimal-starter/src/trpc/transformer.ts (1)
  • transformer (8-8)
examples/next-minimal-starter/src/trpc/server/routers/_app.ts (1)
examples/next-minimal-starter/src/trpc/server/init.ts (2)
  • router (31-31)
  • publicProcedure (29-29)
examples/next-minimal-starter/src/app/content.tsx (1)
examples/next-minimal-starter/src/trpc/server/server.tsx (1)
  • trpc (14-18)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: E2E-tests (soa)
  • GitHub Check: E2E-tests (next-minimal-starter)
  • GitHub Check: E2E-tests (.test/internal-types-export)
  • GitHub Check: E2E-tests (.experimental/next-app-dir)
  • GitHub Check: E2E-tests (cloudflare-workers)
  • GitHub Check: E2E-tests (express-minimal)
  • GitHub Check: E2E-tests (.test/diagnostics-big-router)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
  • GitHub Check: E2E-tests (.test/ssg)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
  • GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
  • GitHub Check: Test a monorepo using built declaration files
  • GitHub Check: Release using pkg.pr.new
  • GitHub Check: E2E-tests (Deno) (deno-deploy)
  • GitHub Check: test
  • GitHub Check: Lint and auto-fix
πŸ”‡ Additional comments (24)
examples/next-minimal-starter/next-env.d.ts (1)

5-5: Updated link reflects current Next .js docs – looks good.

examples/next-minimal-starter/src/trpc/query-client.ts (1)

7-24: Well-structured query client factory with proper SSR support.

The implementation correctly configures React Query for server-side rendering with appropriate serialization/deserialization handling and includes pending queries in dehydration, which ensures smooth hydration on the client side.

examples/next-minimal-starter/tsconfig.json (1)

25-25: Appropriate removal of path aliases for the App Router migration.

Removing the custom path alias mapping simplifies the configuration and aligns with the restructured codebase that no longer requires these mappings.

examples/next-minimal-starter/README.md (1)

1-1: Clear documentation updates reflecting the App Router migration.

The title update and switch to pnpm commands properly document the architectural changes and align with modern package management practices.

Also applies to: 10-11, 19-19

examples/next-minimal-starter/package.json (1)

12-12: Appropriate dependency updates for the tRPC + React Query migration.

The addition of React Query devtools and the migration to @trpc/tanstack-react-query correctly aligns with the newer tRPC integration patterns and provides better development experience.

Also applies to: 16-16

examples/next-minimal-starter/src/app/page.tsx (1)

4-12: Well-implemented App Router page with proper data prefetching and hydration.

The component correctly implements the prefetch pattern using void for fire-and-forget semantics and wraps the content with HydrateClient to ensure proper server-side data hydration on the client side.

examples/next-minimal-starter/src/app/api/trpc/[trpc]/route.ts (1)

1-30: LGTM! Clean App Router implementation.

The tRPC API route handler is properly implemented for Next.js App Router. The use of fetchRequestHandler with correct configuration including router, context creation, and error handling is appropriate. Exporting both GET and POST handlers follows App Router conventions.

examples/next-minimal-starter/src/trpc/server/routers/_app.ts (3)

7-7: LGTM! Import path correctly updated.

The import path change from the previous alias to relative path aligns with the new file structure and App Router migration.


11-11: LGTM! Proper export for App Router.

Exporting appRouter is necessary for the new API route handler to consume it, which is the correct approach for App Router architecture.


16-20: LGTM! Improved API flexibility.

Making the input schema optional provides better API flexibility by allowing calls without any input parameters.

examples/next-minimal-starter/src/trpc/server/init.ts (4)

11-11: LGTM! Import path simplified.

The import path simplification aligns with the new file structure.


13-18: LGTM! Proper context setup.

The createContext function is correctly implemented as an async function returning an empty object. The documentation reference is helpful for future extensions.


20-20: LGTM! Correct context type definition.

The Context type is properly derived from the createContext function's return type.


22-24: LGTM! Proper tRPC initialization with context.

The tRPC initialization correctly includes the Context type, enabling proper type inference throughout the application.

examples/next-minimal-starter/src/app/layout.tsx (2)

9-12: LGTM! Proper metadata configuration.

The metadata export is correctly configured for Next.js App Router.


14-30: LGTM! Correct layout implementation.

The RootLayout component properly wraps children with TRPCReactProvider and applies the Inter font. The async function signature and HTML structure are correct for App Router.

examples/next-minimal-starter/src/trpc/trpc-client.tsx (3)

20-20: LGTM! Proper tRPC context creation.

The tRPC context is correctly created with the AppRouter type, providing proper type inference for the client.


22-34: LGTM! Proper query client management.

The query client management correctly handles server vs browser environments, ensuring a single client instance on the browser while creating new ones on the server. The comments explaining the importance are helpful.


36-73: LGTM! Well-structured provider component.

The TRPCReactProvider component is well-implemented with:

  • Proper query client initialization
  • Correct tRPC client setup with appropriate links
  • Proper provider nesting (QueryClientProvider -> TRPCProvider)
  • Good comments explaining the implementation choices
examples/next-minimal-starter/src/app/content.tsx (2)

1-5: LGTM! Clean imports and proper client component setup.

The 'use client' directive is correctly placed, and the imports are appropriate for the tRPC and React Query integration patterns used in this App Router setup.


34-63: Well-implemented subscription example with proper error handling.

The subscription component correctly handles real-time data updates and provides user-friendly error recovery with the reset functionality. The table structure clearly displays subscription state information.

examples/next-minimal-starter/src/trpc/server/server.tsx (3)

1-1: Excellent use of server-only directive.

The server-only import ensures this module cannot be accidentally imported on the client side, which is crucial for server-side tRPC setup and prevents bundle bloat.


13-18: Well-designed caching strategy for query client stability.

The cached getQueryClient ensures the same query client instance is reused during a single request, which is important for consistent state management in server components.


32-40: Clean hydration boundary implementation.

The HydrateClient component correctly dehydrates the server query client state and provides it to the client for seamless hydration. This is a standard and effective pattern for SSR with React Query.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 25, 2025

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6839

@trpc/next

npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6839

@trpc/react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6839

@trpc/server

npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6839

@trpc/tanstack-react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/tanstack-react-query@6839

@trpc/upgrade

npm i https://pkg.pr.new/trpc/trpc/@trpc/upgrade@6839

commit: 4f1c260

trpc-bot
trpc-bot previously approved these changes Aug 18, 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.

3 participants