Skip to content

Commit

Permalink
Merge branch 'canary' into fix-dynamic-middleware-routing.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Mar 28, 2022
2 parents beb0728 + 50be7cc commit a089ea5
Show file tree
Hide file tree
Showing 56 changed files with 300 additions and 492 deletions.
2 changes: 0 additions & 2 deletions docs/api-reference/next/server.md
Expand Up @@ -55,8 +55,6 @@ The `NextFetchEvent` object extends the native [`FetchEvent`](https://developer.

The `waitUntil()` method can be used to prolong the execution of the function, after the response has been sent. In practice this means that you can send a response, then continue the function execution if you have other background work to make.

An example of _why_ you would use `waitUntil()` is integrations with logging tools such as [Sentry](https://sentry.io) or [DataDog](https://www.datadoghq.com). After the response has been sent, you can send logs of response times, errors, API call durations or overall performance metrics.

The `event` object is fully typed and can be imported from `next/server`.

```ts
Expand Down
2 changes: 0 additions & 2 deletions docs/middleware.md
Expand Up @@ -71,9 +71,7 @@ Middleware can be used for anything that shares logic for a set of pages, includ
- [Redirects and rewrites](https://github.com/vercel/examples/tree/main/edge-functions)
- [Handling unsupported browsers](https://github.com/vercel/examples/tree/main/edge-functions)
- [Feature flags and A/B tests](https://github.com/vercel/examples/tree/main/edge-functions)
- [Server-side analytics](https://github.com/vercel/examples/tree/main/edge-functions)
- [Advanced i18n routing requirements](https://github.com/vercel/examples/tree/main/edge-functions)
- [Logging](https://github.com/vercel/examples/tree/main/edge-functions)
## Execution Order
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.1.2-canary.0"
"version": "12.1.2"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"keywords": [
"react",
"next",
Expand Down
45 changes: 45 additions & 0 deletions packages/eslint-config-next/index.js
Expand Up @@ -4,6 +4,51 @@
*
* https://www.npmjs.com/package/@rushstack/eslint-patch
*/
const keptPaths = []
const sortedPaths = []
const cwd = process.cwd().replace(/\\/g, '/')
const originalPaths = require.resolve.paths('eslint-plugin-import')

// eslint throws a conflict error when plugins resolve to different
// locations, since we want to lock our dependencies by default
// but also need to allow using user dependencies this updates
// our resolve paths to first check the cwd and iterate to
// eslint-config-next's dependencies if needed

for (let i = originalPaths.length - 1; i >= 0; i--) {
const currentPath = originalPaths[i]

if (currentPath.replace(/\\/g, '/').startsWith(cwd)) {
sortedPaths.push(currentPath)
} else {
keptPaths.unshift(currentPath)
}
}

// maintain order of node_modules outside of cwd
sortedPaths.push(...keptPaths)

const hookPropertyMap = new Map(
[
['eslint-plugin-import', 'eslint-plugin-import'],
['eslint-plugin-react', 'eslint-plugin-react'],
['eslint-plugin-jsx-a11y', 'eslint-plugin-jsx-a11y'],
].map(([request, replacement]) => [
request,
require.resolve(replacement, { paths: sortedPaths }),
])
)

const mod = require('module')
const resolveFilename = mod._resolveFilename
mod._resolveFilename = function (request, parent, isMain, options) {
const hookResolved = hookPropertyMap.get(request)
if (hookResolved) {
request = hookResolved
}
return resolveFilename.call(mod, request, parent, isMain, options)
}

require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.1.2-canary.0",
"@next/eslint-plugin-next": "12.1.2",
"@rushstack/eslint-patch": "1.0.8",
"@typescript-eslint/parser": "5.10.1",
"eslint-import-resolver-node": "0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Expand Up @@ -135,7 +135,7 @@ export async function getPageRuntime(
try {
const { body } = await parse(pageContent, {
filename: pageFilePath,
isModule: true,
isModule: 'unknown',
})

for (const node of body) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ async function parseModuleInfo(
): Promise<void> {
const { body } = await parse(transformedSource, {
filename: resourcePath,
isModule: true,
isModule: 'unknown',
})
for (let i = 0; i < body.length; i++) {
const node = body[i]
Expand Down
13 changes: 8 additions & 5 deletions packages/next/build/webpack/loaders/next-flight-server-loader.ts
@@ -1,6 +1,6 @@
import { parse } from '../../swc'
import { getRawPageExtensions } from '../../utils'
import { buildExports, isEsmNodeType } from './utils'
import { buildExports } from './utils'

const imageExtensions = ['jpg', 'jpeg', 'png', 'webp', 'avif']

Expand Down Expand Up @@ -42,16 +42,18 @@ async function parseModuleInfo({
imports: string
isEsm: boolean
}> {
const ast = await parse(source, { filename: resourcePath, isModule: true })
const { body } = ast
const ast = await parse(source, {
filename: resourcePath,
isModule: 'unknown',
})
const { type, body } = ast
let transformedSource = ''
let lastIndex = 0
let imports = ''
let isEsm = false
const isEsm = type === 'Module'

for (let i = 0; i < body.length; i++) {
const node = body[i]
isEsm = isEsm || isEsmNodeType(node.type)
switch (node.type) {
case 'ImportDeclaration': {
const importSource = node.source.value
Expand Down Expand Up @@ -184,6 +186,7 @@ export default async function transformSource(
__webpack_require__,
_: () => {\n${imports}\n}
}`,
__next_rsc_server__: isServerComponent(resourcePath) ? 'true' : 'false',
}

if (isClientCompilation) {
Expand Down
9 changes: 0 additions & 9 deletions packages/next/build/webpack/loaders/utils.ts
Expand Up @@ -11,12 +11,3 @@ export function buildExports(moduleExports: any, isESM: boolean) {
})
return ret
}

const esmNodeTypes = [
'ImportDeclaration',
'ExportDeclaration',
'ExportNamedDeclaration',
'ExportDefaultExpression',
'ExportDefaultDeclaration',
]
export const isEsmNodeType = (type: string) => esmNodeTypes.includes(type)
14 changes: 7 additions & 7 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@next/env": "12.1.2-canary.0",
"@next/env": "12.1.2",
"caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5",
"styled-jsx": "5.0.1",
Expand Down Expand Up @@ -118,11 +118,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "2.4.4",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "12.1.2-canary.0",
"@next/polyfill-nomodule": "12.1.2-canary.0",
"@next/react-dev-overlay": "12.1.2-canary.0",
"@next/react-refresh-utils": "12.1.2-canary.0",
"@next/swc": "12.1.2-canary.0",
"@next/polyfill-module": "12.1.2",
"@next/polyfill-nomodule": "12.1.2",
"@next/react-dev-overlay": "12.1.2",
"@next/react-refresh-utils": "12.1.2",
"@next/swc": "12.1.2",
"@peculiar/webcrypto": "1.3.1",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/next/server/render.tsx
Expand Up @@ -307,7 +307,7 @@ function checkRedirectValues(

const rscCache = new Map()

function createRSCHook() {
function createFlightHook() {
return (
writable: WritableStream<Uint8Array>,
id: string,
Expand Down Expand Up @@ -356,7 +356,7 @@ function createRSCHook() {
}
}

const useRSCResponse = createRSCHook()
const useFlightResponse = createFlightHook()

// Create the wrapper component for a Flight stream.
function createServerComponentRenderer(
Expand Down Expand Up @@ -386,7 +386,7 @@ function createServerComponentRenderer(
serverComponentManifest
)

const response = useRSCResponse(
const response = useFlightResponse(
writable,
cachePrefix + ',' + id,
reqStream,
Expand Down Expand Up @@ -469,9 +469,9 @@ export async function renderToHTML(

// We don't need to opt-into the flight inlining logic if the page isn't a RSC.
const isServerComponent =
!!serverComponentManifest &&
hasConcurrentFeatures &&
!!ComponentMod.__next_rsc__
!!serverComponentManifest &&
!!ComponentMod.__next_rsc_server__

let Component: React.ComponentType<{}> | ((props: any) => JSX.Element) =
renderOpts.Component
Expand Down
13 changes: 5 additions & 8 deletions packages/next/shared/lib/dynamic.tsx
Expand Up @@ -117,14 +117,11 @@ export default function dynamic<P = {}>(
const suspenseOptions = loadableOptions as LoadableSuspenseOptions & {
loader: Loader<P>
}
if (!process.env.__NEXT_CONCURRENT_FEATURES) {
// Error if react root is not enabled and `suspense` option is set to true
if (!process.env.__NEXT_REACT_ROOT && suspenseOptions.suspense) {
// TODO: add error doc when this feature is stable
throw new Error(
`Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense`
)
}
// Error if Fizz rendering is not enabled and `suspense` option is set to true
if (!process.env.__NEXT_CONCURRENT_FEATURES && suspenseOptions.suspense) {
throw new Error(
`Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense`
)
}
if (suspenseOptions.suspense) {
return loadableFn(suspenseOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "12.1.2-canary.0",
"version": "12.1.2",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
1 change: 1 addition & 0 deletions test/integration/react-18-invalid-config/components/foo.js
@@ -0,0 +1 @@
export default () => 'foo'

0 comments on commit a089ea5

Please sign in to comment.