Skip to content

Commit

Permalink
Merge branch 'canary' into mk/proxy-host
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Nov 12, 2021
2 parents 7878e95 + d1adf1d commit 0ab1d04
Show file tree
Hide file tree
Showing 33 changed files with 378 additions and 31 deletions.
4 changes: 4 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@
"title": "no-router-instance",
"path": "/errors/no-router-instance.md"
},
{
"title": "no-server-import-in-page",
"path": "/errors/no-server-import-in-page.md"
},
{
"title": "no-sync-scripts",
"path": "/errors/no-sync-scripts.md"
Expand Down
23 changes: 23 additions & 0 deletions errors/no-server-import-in-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# No Server Import In Page

### Why This Error Occurred

`next/server` was imported in a page outside of `pages/_middleware.js` (or `pages/_middleware.tsx` if you are using TypeScript)

### Possible Ways to Fix It

Only import and use `next/server` within `pages/_middleware.js` (or `pages/_middleware.tsx`) to add middlewares.

```jsx
// pages/_middleware.ts

import type { NextFetchEvent, NextRequest } from 'next/server'

export function middleware(req: NextRequest, ev: NextFetchEvent) {
return new Response('Hello, world!')
}
```

### Useful Links

- [Middleware](https://nextjs.org/docs/middleware)
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.0.4-canary.9"
"version": "12.0.4-canary.10"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"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.0.4-canary.9",
"@next/eslint-plugin-next": "12.0.4-canary.10",
"@rushstack/eslint-patch": "^1.0.6",
"@typescript-eslint/parser": "^4.20.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
37 changes: 37 additions & 0 deletions packages/eslint-plugin-next/lib/rules/no-server-import-in-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path')

module.exports = {
meta: {
docs: {
description:
'Disallow importing next/server outside of pages/_middleware.js',
recommended: true,
url: 'https://nextjs.org/docs/messages/no-server-import-in-page',
},
},
create: function (context) {
return {
ImportDeclaration(node) {
if (node.source.value !== 'next/server') {
return
}

const paths = context.getFilename().split('pages')
const page = paths[paths.length - 1]

if (
!page ||
page.startsWith(`${path.sep}_middleware`) ||
page.startsWith(`${path.posix.sep}_middleware`)
) {
return
}

context.report({
node,
message: `next/server should not be imported outside of pages/_middleware.js. See https://nextjs.org/docs/messages/no-server-import-in-page.`,
})
},
}
},
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions packages/next/build/swc/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function getBaseSWCOptions({
styledComponents,
paths,
baseUrl,
importSource,
}) {
const isTSFile = filename.endsWith('.ts')
const isTypeScript = isTSFile || filename.endsWith('.tsx')
Expand All @@ -30,6 +31,7 @@ function getBaseSWCOptions({

transform: {
react: {
importSource: importSource || 'react',
runtime: 'automatic',
pragma: 'React.createElement',
pragmaFrag: 'React.Fragment',
Expand All @@ -44,6 +46,10 @@ function getBaseSWCOptions({
typeofs: {
window: globalWindow ? 'object' : 'undefined',
},
envs: {
NODE_ENV: development ? '"development"' : '"production"',
},
// TODO: handle process.browser to match babel replacing as well
},
},
regenerator: {
Expand Down Expand Up @@ -103,13 +109,15 @@ export function getLoaderSWCOptions({
isPageFile,
hasReactRefresh,
styledComponents,
importSource,
}) {
let baseOptions = getBaseSWCOptions({
filename,
development,
globalWindow: !isServer,
hasReactRefresh,
styledComponents,
importSource,
})

const isNextDist = nextDistPath.test(filename)
Expand Down
10 changes: 5 additions & 5 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ export default async function getBaseWebpackConfig(
runWebpackSpan: Span
}
): Promise<webpack.Configuration> {
const { useTypeScript, jsConfig, resolvedBaseUrl } = await loadJsConfig(
dir,
config
)
const supportedBrowsers = await getSupportedBrowsers(dir, dev)
const hasRewrites =
rewrites.beforeFiles.length > 0 ||
Expand Down Expand Up @@ -438,6 +442,7 @@ export default async function getBaseWebpackConfig(
pagesDir,
hasReactRefresh: !isMiddleware && hasReactRefresh,
styledComponents: config.experimental.styledComponents,
importSource: jsConfig?.compilerOptions?.jsxImportSource,
},
}
: {
Expand Down Expand Up @@ -521,11 +526,6 @@ export default async function getBaseWebpackConfig(
} as ClientEntries)
: undefined

const { useTypeScript, jsConfig, resolvedBaseUrl } = await loadJsConfig(
dir,
config
)

function getReactProfilingInProduction() {
if (reactProductionProfiling) {
return {
Expand Down
10 changes: 8 additions & 2 deletions packages/next/build/webpack/loaders/next-swc-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {

let loaderOptions = this.getOptions() || {}

const { isServer, pagesDir, hasReactRefresh, styledComponents } =
loaderOptions
const {
isServer,
pagesDir,
hasReactRefresh,
styledComponents,
importSource,
} = loaderOptions
const isPageFile = filename.startsWith(pagesDir)

const swcOptions = getLoaderSWCOptions({
Expand All @@ -47,6 +52,7 @@ async function loaderTransform(parentTrace, source, inputSourceMap) {
development: this.mode === 'development',
hasReactRefresh,
styledComponents,
importSource,
})

const programmaticOptions = {
Expand Down
12 changes: 6 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -70,10 +70,10 @@
"@babel/runtime": "7.15.4",
"@hapi/accept": "5.0.2",
"@napi-rs/triples": "1.0.3",
"@next/env": "12.0.4-canary.9",
"@next/polyfill-module": "12.0.4-canary.9",
"@next/react-dev-overlay": "12.0.4-canary.9",
"@next/react-refresh-utils": "12.0.4-canary.9",
"@next/env": "12.0.4-canary.10",
"@next/polyfill-module": "12.0.4-canary.10",
"@next/react-dev-overlay": "12.0.4-canary.10",
"@next/react-refresh-utils": "12.0.4-canary.10",
"acorn": "8.5.0",
"assert": "2.0.0",
"browserify-zlib": "0.2.0",
Expand Down Expand Up @@ -156,7 +156,7 @@
"@babel/traverse": "7.15.0",
"@babel/types": "7.15.0",
"@napi-rs/cli": "1.2.1",
"@next/polyfill-nomodule": "12.0.4-canary.9",
"@next/polyfill-nomodule": "12.0.4-canary.10",
"@peculiar/webcrypto": "1.1.7",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,9 @@ export default class Server {
})

for (let [key, value] of result.response.headers) {
allHeaders.append(key, value)
if (key !== 'x-middleware-next') {
allHeaders.append(key, value)
}
}

if (!this.renderOpts.dev) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/web/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function getFetchHeaders(middleware: string, init: RequestInit) {
}

function getFetchURL(input: RequestInfo, headers: NodeHeaders = {}): string {
const initurl = isRequestLike(input) ? input.url : input
const initurl = isRequestLike(input) ? input.url : String(input)
if (initurl.startsWith('/')) {
const host = headers.host?.toString()
const localhost =
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "12.0.4-canary.9",
"version": "12.0.4-canary.10",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
35 changes: 35 additions & 0 deletions test/development/basic/theme-ui.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { join } from 'path'
import webdriver from 'next-webdriver'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'

describe('theme-ui SWC option', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: {
'jsconfig.json': new FileRef(join(__dirname, 'theme-ui/jsconfig.json')),
pages: new FileRef(join(__dirname, 'theme-ui/pages')),
'theme.js': new FileRef(join(__dirname, 'theme-ui/theme.js')),
},
dependencies: {
'theme-ui': '0.12.0',
},
})
})
afterAll(() => next.destroy())

it('should have theme provided styling', async () => {
let browser
try {
browser = await webdriver(next.appPort, '/')
const color = await browser.elementByCss('#hello').getComputedCss('color')
expect(color).toBe('rgb(51, 51, 238)')
} finally {
if (browser) {
await browser.close()
}
}
})
})
5 changes: 5 additions & 0 deletions test/development/basic/theme-ui/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsxImportSource": "theme-ui"
}
}
13 changes: 13 additions & 0 deletions test/development/basic/theme-ui/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// basic usage
import { ThemeProvider } from 'theme-ui'
import theme from '../theme'

function MyApp({ Component, pageProps }) {
return (
<ThemeProvider theme={theme}>
<Component {...pageProps} />
</ThemeProvider>
)
}

export default MyApp

0 comments on commit 0ab1d04

Please sign in to comment.