Unverified Commit a44991d0 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Add server markdown analyzer eval

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent f3c36c33
...@@ -41,5 +41,9 @@ ...@@ -41,5 +41,9 @@
"agent-059-browser-initial-load-optimizer": { "agent-059-browser-initial-load-optimizer": {
"skills": ["next-browser-initial-load-optimizer"], "skills": ["next-browser-initial-load-optimizer"],
"timeout": 1800 "timeout": 1800
},
"agent-060-server-markdown-renderer": {
"skills": ["next-browser-initial-load-optimizer"],
"timeout": 1800
} }
} }
import { expect, test } from 'vitest'
import { transcriptPath } from '@vercel/agent-eval/eval'
import { readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
function sourceFiles(directory = process.cwd()): string[] {
const files: string[] = []
for (const entry of readdirSync(directory, { withFileTypes: true })) {
if (['.next', 'node_modules'].includes(entry.name)) continue
const path = join(directory, entry.name)
if (entry.isDirectory()) files.push(...sourceFiles(path))
else if (/\.[cm]?[jt]sx?$/.test(entry.name)) files.push(path)
}
return files
}
function sources(): Array<{ path: string; content: string }> {
return ['app', 'components']
.flatMap((directory) => sourceFiles(join(process.cwd(), directory)))
.map((path) => ({ path, content: readFileSync(path, 'utf8') }))
}
function isClientModule(content: string): boolean {
return /^\s*['"]use client['"]/m.test(content)
}
test('keeps the Markdown rendering stack out of client modules', () => {
const files = sources()
const clientSources = files
.filter(({ content }) => isClientModule(content))
.map(({ content }) => content)
.join('\n')
expect(clientSources).not.toMatch(
/from\s*['"](?:react-markdown|remark-gfm|rehype-highlight)['"]/
)
expect(files.map(({ content }) => content).join('\n')).toMatch(
/react-markdown/
)
})
test('renders the display-only content from a server boundary', () => {
const files = sources()
const markdownModules = files.filter(({ content }) =>
/from\s*['"]react-markdown['"]/.test(content)
)
expect(markdownModules.length).toBeGreaterThan(0)
expect(markdownModules.every(({ content }) => !isClientModule(content))).toBe(
true
)
})
test('preserves the formatted release notes', () => {
const content = sources()
.map((file) => file.content)
.join('\n')
expect(content).toContain('Release Notes')
expect(content).toContain('## Quarterly plan')
expect(content).toContain('- Ship the browser performance work')
expect(content).toContain('- Keep the release notes readable')
expect(content).toContain("const target = 'fast initial load'")
expect(content).toMatch(/remark-gfm/)
expect(content).toMatch(/rehype-highlight/)
})
test('uses analyzer evidence and verifies the optimization', () => {
const transcript = readFileSync(transcriptPath(), 'utf8')
const analyzerRuns = transcript.match(/experimental-analyze/g) ?? []
expect(transcript.trim()).not.toBe('')
expect(analyzerRuns.length).toBeGreaterThanOrEqual(2)
expect(transcript).toMatch(/(?:query|initial[_ -]?load|scope)/i)
expect(transcript).toMatch(/react-markdown/i)
expect(transcript).toMatch(/remark-gfm/i)
expect(transcript).toMatch(/rehype-highlight/i)
expect(transcript).toMatch(/(?:package|source|importer)/i)
expect(transcript).toMatch(
/(?:next\s+build|pnpm\s+(?:run\s+)?build|npm\s+run\s+build)/i
)
})
The `/` route in this Next.js app has become slow on first load. Optimize its browser initial-load performance without changing the visible release notes or their formatting.
The Markdown heading, bulleted list, and highlighted JavaScript code block must render exactly as useful display content; users do not edit this content in the browser.
Use the tools and documentation available in the project, verify the optimization, and leave the app in a production-buildable state.
import type { ReactNode } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { ReleaseNotes } from '../components/release-notes'
export default function Page() {
return (
<main>
<h1>Release Notes</h1>
<ReleaseNotes />
</main>
)
}
'use client'
import ReactMarkdown from 'react-markdown'
import rehypeHighlight from 'rehype-highlight'
import remarkGfm from 'remark-gfm'
const notes = `## Quarterly plan
- Ship the browser performance work
- Keep the release notes readable
\`\`\`js
const target = 'fast initial load'
\`\`\`
`
export function ReleaseNotes() {
return (
<article>
<ReactMarkdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeHighlight]}
>
{notes}
</ReactMarkdown>
</article>
)
}
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {}
export default nextConfig
{
"private": true,
"type": "module",
"scripts": {
"build": "next build",
"dev": "next dev",
"start": "next start"
},
"dependencies": {
"next": "^16",
"react": "19.1.0",
"react-dom": "19.1.0",
"react-markdown": "^10.1.0",
"rehype-highlight": "^7.0.2",
"remark-gfm": "^4.0.1"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"typescript": "^5",
"vitest": "^3.1.3"
}
}
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx",
".next/dev/types/**/*.ts"
],
"exclude": ["node_modules", "EVAL.ts"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment