Skip to content

fix(server): align user agent parsing with Next.js - #3202

Open
hyoban wants to merge 3 commits into
cloudflare:mainfrom
hyoban:fix/user-agent-parsing
Open

fix(server): align user agent parsing with Next.js#3202
hyoban wants to merge 3 commits into
cloudflare:mainfrom
hyoban:fix/user-agent-parsing

Conversation

@hyoban

@hyoban hyoban commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

userAgent() currently returns empty browser, device, engine, OS, and CPU objects, so the documented mobile viewport example always selects desktop. Its broad bot regex also disagrees with Next.js for agents such as WhatsApp and custom crawlers.

Use ua-parser-js@1.0.35, matching Next.js, and the same known-bot pattern. Keep parsing in a dedicated module re-exported by next/server, including Next.js-compatible empty input and result shapes. Add 45 tests covering the upstream cases, mobile/tablet/CPU parsing, request headers, and bot classification.

References:

Validation:

  • vp test run tests/user-agent.test.ts tests/shims.test.ts — 1,356 tests passed
  • vp check
  • node scripts/sync-next-types.mjs --check
  • node scripts/check-shim-types.mjs
  • vp run vinext#build
  • Built server shim successfully parses a mobile Request; direct comparison with Next.js 16.2.7 matches for empty, unknown, bot, mobile, desktop, and long UA inputs.

Cloudflare Workers runtime comparison has not been run locally; full-suite and E2E validation are left to CI.

@pkg-pr-new

pkg-pr-new Bot commented Sep 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@3202
npm i https://pkg.pr.new/create-vinext-app@3202
npm i https://pkg.pr.new/@vinext/types@3202
npm i https://pkg.pr.new/vinext@3202

commit: e5d8653

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared e5d8653 against base 609d222 using alternating same-runner rounds. Next.js was unchanged and skipped.

2 improved · 1 regressed · 3 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 142.4 KB 142.4 KB ⚫ -0.0%
Client entry size (gzip) vinext 129.7 KB 129.7 KB ⚫ -0.0%
Dev server cold start vinext 3.51 s 3.39 s 🟢 -3.6%
Production build time vinext 3.81 s 3.63 s 🟢 -4.7%
RSC entry closure size (gzip) vinext 125.5 KB 125.4 KB ⚫ -0.0%
Server bundle size (gzip) vinext 216.1 KB 223.4 KB 🔴 +3.4%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@james-elicx

Copy link
Copy Markdown
Member

/bigbonk review for issues

@ask-bonk

ask-bonk Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

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