rsnext/packages
Kiko Beats 76083210ed
Middleware: remove req.ua (#37512)
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`
2022-06-09 11:10:21 +00:00
..
create-next-app v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
eslint-config-next v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
eslint-plugin-next v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next Middleware: remove req.ua (#37512) 2022-06-09 11:10:21 +00:00
next-bundle-analyzer v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-codemod v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-env v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-mdx v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-plugin-storybook v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-polyfill-module v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-polyfill-nomodule v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
next-swc v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
react-dev-overlay v12.1.7-canary.33 2022-06-08 16:55:45 -05:00
react-refresh-utils v12.1.7-canary.33 2022-06-08 16:55:45 -05:00