-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Adapt trpc middleware input attachment (#13831)
- Loading branch information
Showing
33 changed files
with
847 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dev-packages/e2e-tests/test-applications/nextjs-t3/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
!*.d.ts | ||
|
||
# Sentry | ||
.sentryclirc | ||
|
||
.vscode | ||
|
||
test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nextjs-t3/next-env.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nextjs-t3/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
await import('./src/env.js'); | ||
|
||
/** @type {import("next").NextConfig} */ | ||
const config = {}; | ||
|
||
import { withSentryConfig } from '@sentry/nextjs'; | ||
|
||
export default withSentryConfig(config, { | ||
disableLogger: true, | ||
silent: true, | ||
}); |
54 changes: 54 additions & 0 deletions
54
dev-packages/e2e-tests/test-applications/nextjs-t3/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "t3", | ||
"version": "0.1.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "next build", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test:prod": "TEST_ENV=production playwright test", | ||
"test:dev": "TEST_ENV=development playwright test", | ||
"test:build": "pnpm install && npx playwright install && pnpm build", | ||
"test:build-canary": "pnpm install && pnpm add next@canary && pnpm add react@beta && pnpm add react-dom@beta && npx playwright install && pnpm build", | ||
"test:build-latest": "pnpm install && pnpm add next@rc && pnpm add react@beta && pnpm add react-dom@beta && npx playwright install && pnpm build", | ||
"test:assert": "pnpm test:prod && pnpm test:dev" | ||
}, | ||
"dependencies": { | ||
"@sentry/nextjs": "latest || *", | ||
"@t3-oss/env-nextjs": "^0.10.1", | ||
"@tanstack/react-query": "^5.50.0", | ||
"@trpc/client": "^11.0.0-rc.446", | ||
"@trpc/react-query": "^11.0.0-rc.446", | ||
"@trpc/server": "^11.0.0-rc.446", | ||
"geist": "^1.3.0", | ||
"next": "^14.2.4", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"server-only": "^0.0.1", | ||
"superjson": "^2.2.1", | ||
"zod": "^3.23.3" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.1", | ||
"@sentry-internal/test-utils": "link:../../../test-utils", | ||
"@types/eslint": "^8.56.10", | ||
"@types/node": "^20.14.10", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@typescript-eslint/eslint-plugin": "^8.1.0", | ||
"@typescript-eslint/parser": "^8.1.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-next": "^14.2.4", | ||
"postcss": "^8.4.39", | ||
"prettier": "^3.3.2", | ||
"prettier-plugin-tailwindcss": "^0.6.5", | ||
"tailwindcss": "^3.4.3", | ||
"typescript": "^5.5.3" | ||
}, | ||
"ct3aMetadata": { | ||
"initVersion": "7.37.0" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
dev-packages/e2e-tests/test-applications/nextjs-t3/playwright.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
const testEnv = process.env.TEST_ENV; | ||
|
||
if (!testEnv) { | ||
throw new Error('No test env defined'); | ||
} | ||
|
||
const config = getPlaywrightConfig( | ||
{ | ||
startCommand: testEnv === 'development' ? 'pnpm next dev -p 3030' : 'pnpm next start -p 3030', | ||
port: 3030, | ||
}, | ||
{ | ||
// This comes with the risk of tests leaking into each other but the tests run quite slow so we should parallelize | ||
workers: '100%', | ||
}, | ||
); | ||
|
||
export default config; |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/nextjs-t3/postcss.config.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const config = { | ||
plugins: { | ||
tailwindcss: {}, | ||
}, | ||
}; | ||
|
||
module.exports = config; |
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nextjs-t3/sentry.client.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1, | ||
debug: false, | ||
}); |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/nextjs-t3/sentry.edge.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on). | ||
// The config you add here will be used whenever one of the edge features is loaded. | ||
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally. | ||
// https://docs.sentry.io/platforms/javascript/guides/nextjs/ | ||
|
||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
}); |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nextjs-t3/sentry.server.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
}); |
75 changes: 75 additions & 0 deletions
75
dev-packages/e2e-tests/test-applications/nextjs-t3/src/app/_components/post.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
|
||
import { api } from '~/trpc/react'; | ||
|
||
export function LatestPost() { | ||
const [latestPost] = api.post.getLatest.useSuspenseQuery(); | ||
|
||
const utils = api.useUtils(); | ||
const [name, setName] = useState(''); | ||
const createPost = api.post.create.useMutation({ | ||
onSuccess: async () => { | ||
await utils.post.invalidate(); | ||
setName(''); | ||
}, | ||
}); | ||
|
||
const throwingMutation = api.post.throwError.useMutation({ | ||
onSuccess: async () => { | ||
await utils.post.invalidate(); | ||
setName(''); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="w-full max-w-xs"> | ||
{latestPost ? ( | ||
<p className="truncate">Your most recent post: {latestPost.name}</p> | ||
) : ( | ||
<p>You have no posts yet.</p> | ||
)} | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
createPost.mutate({ name }); | ||
}} | ||
className="flex flex-col gap-2" | ||
> | ||
<input | ||
type="text" | ||
placeholder="Title" | ||
value={name} | ||
onChange={e => setName(e.target.value)} | ||
id="createInput" | ||
className="w-full rounded-full px-4 py-2 text-black" | ||
/> | ||
<button | ||
type="submit" | ||
id="createButton" | ||
className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20" | ||
disabled={createPost.isPending} | ||
> | ||
{createPost.isPending ? 'Submitting...' : 'Submit'} | ||
</button> | ||
</form> | ||
<form | ||
onSubmit={e => { | ||
e.preventDefault(); | ||
throwingMutation.mutate({ name: 'I love dogs' }); | ||
}} | ||
className="flex flex-col gap-2" | ||
> | ||
<button | ||
id="error-button" | ||
type="submit" | ||
className="rounded-full bg-white/10 px-10 py-3 font-semibold transition hover:bg-white/20" | ||
disabled={throwingMutation.isPending} | ||
> | ||
THROW TRPC | ||
</button> | ||
</form> | ||
</div> | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
dev-packages/e2e-tests/test-applications/nextjs-t3/src/app/api/trpc/[trpc]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; | ||
import { type NextRequest } from 'next/server'; | ||
|
||
import { env } from '~/env'; | ||
import { appRouter } from '~/server/api/root'; | ||
import { createTRPCContext } from '~/server/api/trpc'; | ||
|
||
/** | ||
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when | ||
* handling a HTTP request (e.g. when you make requests from Client Components). | ||
*/ | ||
const createContext = async (req: NextRequest) => { | ||
return createTRPCContext({ | ||
headers: req.headers, | ||
}); | ||
}; | ||
|
||
const handler = (req: NextRequest) => | ||
fetchRequestHandler({ | ||
endpoint: '/api/trpc', | ||
req, | ||
router: appRouter, | ||
createContext: () => createContext(req), | ||
onError: | ||
env.NODE_ENV === 'development' | ||
? ({ path, error }) => { | ||
console.error(`❌ tRPC failed on ${path ?? '<no-path>'}: ${error.message}`); | ||
} | ||
: undefined, | ||
}); | ||
|
||
export { handler as GET, handler as POST }; |
27 changes: 27 additions & 0 deletions
27
dev-packages/e2e-tests/test-applications/nextjs-t3/src/app/global-error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client'; | ||
|
||
import * as Sentry from '@sentry/nextjs'; | ||
import NextError from 'next/error'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function GlobalError({ | ||
error, | ||
}: { | ||
error: Error & { digest?: string }; | ||
}) { | ||
useEffect(() => { | ||
Sentry.captureException(error); | ||
}, [error]); | ||
|
||
return ( | ||
<html> | ||
<body> | ||
{/* `NextError` is the default Next.js error page component. Its type | ||
definition requires a `statusCode` prop. However, since the App Router | ||
does not expose status codes for errors, we simply pass 0 to render a | ||
generic error message. */} | ||
<NextError statusCode={0} /> | ||
</body> | ||
</html> | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
dev-packages/e2e-tests/test-applications/nextjs-t3/src/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import '~/styles/globals.css'; | ||
|
||
import { GeistSans } from 'geist/font/sans'; | ||
import { type Metadata } from 'next'; | ||
|
||
import { TRPCReactProvider } from '~/trpc/react'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'Create T3 App', | ||
description: 'Generated by create-t3-app', | ||
icons: [{ rel: 'icon', url: '/favicon.ico' }], | ||
}; | ||
|
||
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) { | ||
return ( | ||
<html lang="en" className={`${GeistSans.variable}`}> | ||
<body> | ||
<TRPCReactProvider>{children}</TRPCReactProvider> | ||
</body> | ||
</html> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
dev-packages/e2e-tests/test-applications/nextjs-t3/src/app/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Link from 'next/link'; | ||
|
||
import { LatestPost } from '~/app/_components/post'; | ||
import { HydrateClient, api } from '~/trpc/server'; | ||
|
||
export default async function Home() { | ||
const hello = await api.post.hello({ text: 'from tRPC' }); | ||
|
||
void api.post.getLatest.prefetch(); | ||
|
||
return ( | ||
<HydrateClient> | ||
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c] text-white"> | ||
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16"> | ||
<h1 className="text-5xl font-extrabold tracking-tight sm:text-[5rem]"> | ||
Create <span className="text-[hsl(280,100%,70%)]">T3</span> App | ||
</h1> | ||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8"> | ||
<Link | ||
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" | ||
href="https://create.t3.gg/en/usage/first-steps" | ||
target="_blank" | ||
> | ||
<h3 className="text-2xl font-bold">First Steps →</h3> | ||
<div className="text-lg"> | ||
Just the basics - Everything you need to know to set up your database and authentication. | ||
</div> | ||
</Link> | ||
<Link | ||
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20" | ||
href="https://create.t3.gg/en/introduction" | ||
target="_blank" | ||
> | ||
<h3 className="text-2xl font-bold">Documentation →</h3> | ||
<div className="text-lg"> | ||
Learn more about Create T3 App, the libraries it uses, and how to deploy it. | ||
</div> | ||
</Link> | ||
</div> | ||
<div className="flex flex-col items-center gap-2"> | ||
<p className="text-2xl text-white">{hello ? hello.greeting : 'Loading tRPC query...'}</p> | ||
</div> | ||
|
||
<LatestPost /> | ||
</div> | ||
</main> | ||
</HydrateClient> | ||
); | ||
} |
Oops, something went wrong.