76083210ed
This PR moves the internal logic associated with `req.ua` into an explicit method the user should to call to have the same behavior. **before** ```typescript // middleware.ts import { NextRequest, NextResponse } from 'next/server' export function middleware(request: NextRequest) { const url = request.nextUrl const viewport = request.ua.device.type === 'mobile' ? 'mobile' : 'desktop' url.searchParams.set('viewport', viewport) return NextResponse.rewrites(url) } ``` **after** ```typescript // middleware.ts import { NextRequest, NextResponse, userAgent } from 'next/server' export function middleware(request: NextRequest) { const url = request.nextUrl const { device } = userAgent(request) const viewport = device.type === 'mobile' ? 'mobile' : 'desktop' url.searchParams.set('viewport', viewport) return NextResponse.rewrites(url) } ``` This potentially will save the extra 17 kB related to the size of `ua-parser-js` |
||
---|---|---|
.. | ||
create-next-app | ||
eslint-config-next | ||
eslint-plugin-next | ||
next | ||
next-bundle-analyzer | ||
next-codemod | ||
next-env | ||
next-mdx | ||
next-plugin-storybook | ||
next-polyfill-module | ||
next-polyfill-nomodule | ||
next-swc | ||
react-dev-overlay | ||
react-refresh-utils |