Skip to content

Commit

Permalink
Merge branch 'canary' into koukou
Browse files Browse the repository at this point in the history
  • Loading branch information
11koukou authored Jan 15, 2022
2 parents 4a7922d + 67bc262 commit 3e8f06a
Show file tree
Hide file tree
Showing 34 changed files with 1,110 additions and 458 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,35 +347,6 @@ jobs:
- run: xvfb-run node run-tests.js test/integration/with-electron/test/index.test.js
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testYarnPnP:
runs-on: ubuntu-latest
needs: [build, build-native-dev]
env:
NODE_OPTIONS: '--unhandled-rejections=strict'
YARN_COMPRESSION_LEVEL: '0'
steps:
- name: Setup node
uses: actions/setup-node@v2
if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }}
with:
node-version: 14

- uses: actions/cache@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}

- uses: actions/download-artifact@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
name: next-swc-dev-binary
path: packages/next-swc/native

- run: bash ./scripts/test-pnp.sh
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

testsPass:
name: thank you, next
runs-on: ubuntu-latest
Expand All @@ -387,7 +358,6 @@ jobs:
checkPrecompiled,
testIntegration,
testUnit,
testYarnPnP,
testDev,
testProd,
]
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/security-headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
return [
{
// Apply these headers to all routes in your application.
source: '/(.*)',
source: '/:path*',
headers: securityHeaders,
},
]
Expand Down
2 changes: 2 additions & 0 deletions docs/api-reference/next/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The loading strategy of the script.

A method that returns additional JavaScript that should be executed after the script has finished loading.

> **Note: `onLoad` can't be used with the `beforeInteractive` loading strategy.**
The following is an example of how to use the `onLoad` property:

```jsx
Expand Down
14 changes: 7 additions & 7 deletions errors/export-image-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

#### Why This Error Occurred

You are attempting to run `next export` while importing the `next/image` component configured using the default `loader`.
You are attempting to run `next export` while importing the `next/image` component using the default `loader` configuration.

However, the default `loader` relies on the Image Optimization API which is not available for exported applications.

This is because Next.js optimizes images on-demand, as users request them (not at build time).

#### Possible Ways to Fix It

- Use `next start` to run a server, which includes the Image Optimization API.
- Use any provider which supports Image Optimization (like [Vercel](https://vercel.com/docs/next.js/image-optimization)).
- Configure a third-party [loader](https://nextjs.org/docs/basic-features/image-optimization#loader) in `next.config.js`.
- Use the [`loader`](https://nextjs.org/docs/api-reference/next/image#loader) prop for `next/image`.
- Use [`next start`](https://nextjs.org/docs/api-reference/cli#production) to run a server, which includes the Image Optimization API.
- Use any provider which supports Image Optimization (such as [Vercel](https://vercel.com)).
- [Configure the loader](https://nextjs.org/docs/api-reference/next/image#loader-configuration) in `next.config.js`.
- Use the [`loader`](https://nextjs.org/docs/api-reference/next/image#loader) prop for each instance of `next/image`.

### Useful Links

- [Deployment Documentation](https://nextjs.org/docs/deployment#vercel-recommended)
- [Deployment Documentation](https://nextjs.org/docs/deployment#managed-nextjs-with-vercel)
- [Image Optimization Documentation](https://nextjs.org/docs/basic-features/image-optimization)
- [`next export` Documentation](https://nextjs.org/docs/advanced-features/static-html-export)
- [`next/image` Documentation](https://nextjs.org/docs/api-reference/next/image)
- [Vercel Documentation](https://vercel.com/docs/next.js/image-optimization)
- [Vercel Documentation](https://vercel.com/docs/concepts/next.js/image-optimization)
2 changes: 1 addition & 1 deletion examples/blog-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"remark": "13.0.0",
"remark-html": "13.0.1"
"remark-html": "13.0.2"
},
"devDependencies": {
"autoprefixer": "^10.4.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supabase-auth-realtime-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
},
"dependencies": {
"@supabase/supabase-js": "^1.2.1",
"@supabase/ui": "^0.6.1",
"@supabase/ui": "^0.36.2",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"swr": "0.2.3"
"swr": "1.1.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IncomingMessage, ServerResponse } from 'http'
import { apiResolver } from '../../../../server/api-utils'
import { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils'
import { DecodeError } from '../../../../shared/lib/utils'
import { NodeNextResponse, NodeNextRequest } from '../../../../server/base-http'

export function getApiHandler(ctx: ServerlessHandlerCtx) {
const { pageModule, encodedPreviewProps, pageIsDynamic } = ctx
Expand All @@ -13,7 +14,15 @@ export function getApiHandler(ctx: ServerlessHandlerCtx) {
normalizeDynamicRouteParams,
} = getUtils(ctx)

return async (req: IncomingMessage, res: ServerResponse) => {
return async (
rawReq: NodeNextRequest | IncomingMessage,
rawRes: NodeNextResponse | ServerResponse
) => {
const req =
rawReq instanceof IncomingMessage ? new NodeNextRequest(rawReq) : rawReq
const res =
rawRes instanceof ServerResponse ? new NodeNextResponse(rawRes) : rawRes

try {
// We need to trust the dynamic route params from the proxy
// to ensure we are using the correct values
Expand Down Expand Up @@ -41,8 +50,8 @@ export function getApiHandler(ctx: ServerlessHandlerCtx) {
}

await apiResolver(
req,
res,
req.originalRequest,
res.originalResponse,
Object.assign({}, parsedUrl.query, params),
await pageModule,
encodedPreviewProps,
Expand All @@ -53,7 +62,7 @@ export function getApiHandler(ctx: ServerlessHandlerCtx) {

if (err instanceof DecodeError) {
res.statusCode = 400
res.end('Bad Request')
res.body('Bad Request').send()
} else {
// Throw the error to crash the serverless function
throw err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import cookie from 'next/dist/compiled/cookie'
import { TEMPORARY_REDIRECT_STATUS } from '../../../../shared/lib/constants'
import { NextConfig } from '../../../../server/config'
import { addRequestMeta } from '../../../../server/request-meta'
import { BaseNextRequest } from '../../../../server/base-http'

const getCustomRouteMatcher = pathMatch(true)

Expand Down Expand Up @@ -85,7 +86,10 @@ export function getUtils({
defaultRouteMatches = dynamicRouteMatcher(page) as ParsedUrlQuery
}

function handleRewrites(req: IncomingMessage, parsedUrl: UrlWithParsedQuery) {
function handleRewrites(
req: BaseNextRequest | IncomingMessage,
parsedUrl: UrlWithParsedQuery
) {
for (const rewrite of rewrites) {
const matcher = getCustomRouteMatcher(rewrite.source)
let params = matcher(parsedUrl.pathname)
Expand Down Expand Up @@ -150,15 +154,18 @@ export function getUtils({
return parsedUrl
}

function handleBasePath(req: IncomingMessage, parsedUrl: UrlWithParsedQuery) {
function handleBasePath(
req: BaseNextRequest | IncomingMessage,
parsedUrl: UrlWithParsedQuery
) {
// always strip the basePath if configured since it is required
req.url = req.url!.replace(new RegExp(`^${basePath}`), '') || '/'
parsedUrl.pathname =
parsedUrl.pathname!.replace(new RegExp(`^${basePath}`), '') || '/'
}

function getParamsFromRouteMatches(
req: IncomingMessage,
req: BaseNextRequest | IncomingMessage,
renderOpts?: any,
detectedLocale?: string
) {
Expand Down Expand Up @@ -269,7 +276,10 @@ export function getUtils({
return pathname
}

function normalizeVercelUrl(req: IncomingMessage, trustQuery: boolean) {
function normalizeVercelUrl(
req: BaseNextRequest | IncomingMessage,
trustQuery: boolean
) {
// make sure to normalize req.url on Vercel to strip dynamic params
// from the query which are added during routing
if (pageIsDynamic && trustQuery && defaultRouteRegex) {
Expand Down Expand Up @@ -374,7 +384,7 @@ export function getUtils({
if (detectedDomain) {
defaultLocale = detectedDomain.defaultLocale
detectedLocale = defaultLocale
addRequestMeta(req, '__nextIsLocaleDomain', true)
addRequestMeta(req as any, '__nextIsLocaleDomain', true)
}

// if not domain specific locale use accept-language preferred
Expand All @@ -394,7 +404,7 @@ export function getUtils({
...parsedUrl,
pathname: localePathResult.pathname,
})
addRequestMeta(req, '__nextStrippedLocale', true)
addRequestMeta(req as any, '__nextStrippedLocale', true)
parsedUrl.pathname = localePathResult.pathname
}

Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/webpack/loaders/next-swc-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export function pitch() {
;(async () => {
let loaderOptions = this.getOptions() || {}
if (
// TODO: investigate swc file reading in PnP mode?
!process.versions.pnp &&
loaderOptions.fileReading &&
!EXCLUDED_PATHS.test(this.resourcePath) &&
this.loaders.length - 1 === this.loaderIndex &&
Expand Down
9 changes: 5 additions & 4 deletions packages/next/server/api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { sendEtagResponse } from './send-payload'
import generateETag from 'next/dist/compiled/etag'
import isError from '../lib/is-error'
import { interopDefault } from '../lib/interop-default'
import { BaseNextRequest, BaseNextResponse } from './base-http'

export type NextApiRequestCookies = { [key: string]: string }
export type NextApiRequestQuery = { [key: string]: string | string[] }
Expand Down Expand Up @@ -141,7 +142,7 @@ export async function apiResolver(
* @param req request object
*/
export async function parseBody(
req: NextApiRequest,
req: IncomingMessage,
limit: string | number
): Promise<any> {
let contentType
Expand Down Expand Up @@ -335,11 +336,11 @@ const COOKIE_NAME_PRERENDER_BYPASS = `__prerender_bypass`
const COOKIE_NAME_PRERENDER_DATA = `__next_preview_data`

export const SYMBOL_PREVIEW_DATA = Symbol(COOKIE_NAME_PRERENDER_DATA)
const SYMBOL_CLEARED_COOKIES = Symbol(COOKIE_NAME_PRERENDER_BYPASS)
export const SYMBOL_CLEARED_COOKIES = Symbol(COOKIE_NAME_PRERENDER_BYPASS)

export function tryGetPreviewData(
req: IncomingMessage,
res: ServerResponse,
req: IncomingMessage | BaseNextRequest,
res: ServerResponse | BaseNextResponse,
options: __ApiPreviewProps
): PreviewData {
// Read cached preview data if present
Expand Down
Loading

0 comments on commit 3e8f06a

Please sign in to comment.