Skip to content

Commit

Permalink
Merge branch 'canary' into fixLazyroot
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle authored Feb 7, 2022
2 parents 25658f1 + 938eb0e commit 73b9cc5
Show file tree
Hide file tree
Showing 30 changed files with 196 additions and 60 deletions.
26 changes: 26 additions & 0 deletions docs/basic-features/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,29 @@ export default async () => {
loadEnvConfig(projectDir)
}
```
## Environment Variable Load Order
Depending on the environment (as set by `NODE_ENV`), variables are loaded from the following sources in order from top-to-bottom. In all environments existing env is not overridden by following sources.
`NODE_ENV=production`
- `.env.production.local`
- `.env.local`
- `.env.production`
- `.env`
`NODE_ENV=development`
- `.env.development.local`
- `.env.local`
- `.env.development`
- `.env`
`NODE_ENV=test`
- `.env.test.local`
- `.env.test`
- `.env`
_(note: `.env.local` is not loaded when `NODE_ENV=test`)_
5 changes: 5 additions & 0 deletions examples/progressive-web-app/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
1 change: 1 addition & 0 deletions examples/progressive-web-app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('next').NextConfig} */
const withPWA = require('next-pwa')
const runtimeCaching = require('next-pwa/cache')

Expand Down
5 changes: 5 additions & 0 deletions examples/progressive-web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
"next-pwa": "^5.4.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/node": "17.0.4",
"@types/react": "17.0.38",
"typescript": "4.5.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Head from 'next/head'
import '../styles/globals.css'
import { AppProps } from 'next/app'

export default function MyApp({ Component, pageProps }) {
export default function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { NextApiRequest, NextApiResponse } from 'next'

const hello = (req, res) => {
const hello = (req: NextApiRequest, res: NextApiResponse) => {
res.status(200).json({ name: 'John Doe' })
}

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions examples/progressive-web-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions examples/with-apollo/lib/apolloClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function initializeApollo(initialState = null) {
// Get existing cache, loaded during client side data fetching
const existingCache = _apolloClient.extract()

// Merge the existing cache into data passed from getStaticProps/getServerSideProps
const data = merge(initialState, existingCache, {
// Merge the initialState from getStaticProps/getServerSideProps in the existing cache
const data = merge(existingCache, initialState, {
// combine arrays using object equality (like in sets)
arrayMerge: (destinationArray, sourceArray) => [
...sourceArray,
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.0.11-canary.6"
"version": "12.0.11-canary.7"
}
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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"@next/eslint-plugin-next": "12.0.11-canary.7",
"@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^5.0.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.0.11-canary.6",
"version": "12.0.11-canary.7",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
64 changes: 38 additions & 26 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,35 +685,47 @@ export default async function getBaseWebpackConfig(
)
}

const getPackagePath = (name: string, relativeToPath: string) => {
const packageJsonPath = require.resolve(`${name}/package.json`, {
paths: [relativeToPath],
})
// Include a trailing slash so that a `.startsWith(packagePath)` check avoids false positives
// when one package name starts with the full name of a different package.
// For example:
// "node_modules/react-slider".startsWith("node_modules/react") // true
// "node_modules/react-slider".startsWith("node_modules/react/") // false
return path.join(packageJsonPath, '../')
}

// Packages which will be split into the 'framework' chunk.
// Only top-level packages are included, e.g. nested copies like
// 'node_modules/meow/node_modules/object-assign' are not included.
const topLevelFrameworkPaths = [
getPackagePath('react', dir),
getPackagePath('react-dom', dir),
getPackagePath('scheduler', require.resolve('react-dom', { paths: [dir] })),
getPackagePath('object-assign', require.resolve('react', { paths: [dir] })),
getPackagePath(
'object-assign',
require.resolve('react-dom', { paths: [dir] })
),
getPackagePath(
'use-subscription',
require.resolve('next', { paths: [dir] })
),
]
const topLevelFrameworkPaths: string[] = []
const visitedFrameworkPackages = new Set<string>()

// Adds package-paths of dependencies recursively
const addPackagePath = (packageName: string, relativeToPath: string) => {
try {
if (visitedFrameworkPackages.has(packageName)) {
return
}
visitedFrameworkPackages.add(packageName)

const packageJsonPath = require.resolve(`${packageName}/package.json`, {
paths: [relativeToPath],
})

// Include a trailing slash so that a `.startsWith(packagePath)` check avoids false positives
// when one package name starts with the full name of a different package.
// For example:
// "node_modules/react-slider".startsWith("node_modules/react") // true
// "node_modules/react-slider".startsWith("node_modules/react/") // false
const directory = path.join(packageJsonPath, '../')

// Returning from the function in case the directory has already been added and traversed
if (topLevelFrameworkPaths.includes(directory)) return
topLevelFrameworkPaths.push(directory)

const dependencies = require(packageJsonPath).dependencies || {}
for (const name of Object.keys(dependencies)) {
addPackagePath(name, directory)
}
} catch (_) {
// don't error on failing to resolve framework packages
}
}

for (const packageName of ['react', 'react-dom']) {
addPackagePath(packageName, dir)
}

// Select appropriate SplitChunksPlugin config for this build
const splitChunksConfig: webpack.Options.SplitChunksOptions | false = dev
Expand Down
12 changes: 7 additions & 5 deletions packages/next/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ function linkClicked(

e.preventDefault()

// avoid scroll for urls with anchor refs
if (scroll == null && as.indexOf('#') >= 0) {
scroll = false
}

// replace state instead of push if prop is present
router[replace ? 'replace' : 'push'](href, as, {
shallow,
Expand Down Expand Up @@ -284,6 +279,13 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
} = {
ref: setRef,
onClick: (e: React.MouseEvent) => {
if (process.env.NODE_ENV !== 'production') {
if (!e) {
throw new Error(
`Component rendered inside next/link has to pass click event to "onClick" prop.`
)
}
}
if (child.props && typeof child.props.onClick === 'function') {
child.props.onClick(e)
}
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.0.11-canary.6",
"version": "12.0.11-canary.7",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@next/env": "12.0.11-canary.6",
"@next/env": "12.0.11-canary.7",
"caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5",
"styled-jsx": "5.0.0",
Expand Down Expand Up @@ -117,11 +117,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "1.2.1",
"@napi-rs/triples": "1.0.3",
"@next/polyfill-module": "12.0.11-canary.6",
"@next/polyfill-nomodule": "12.0.11-canary.6",
"@next/react-dev-overlay": "12.0.11-canary.6",
"@next/react-refresh-utils": "12.0.11-canary.6",
"@next/swc": "12.0.11-canary.6",
"@next/polyfill-module": "12.0.11-canary.7",
"@next/polyfill-nomodule": "12.0.11-canary.7",
"@next/react-dev-overlay": "12.0.11-canary.7",
"@next/react-refresh-utils": "12.0.11-canary.7",
"@next/swc": "12.0.11-canary.7",
"@peculiar/webcrypto": "1.1.7",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
11 changes: 8 additions & 3 deletions packages/next/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ export default class Router implements BaseRouter {
performance.mark('routeChange')
}

const { shallow = false } = options
const { shallow = false, scroll = true } = options
const routeProps = { shallow }

if (this._inFlightRoute) {
Expand Down Expand Up @@ -1045,8 +1045,13 @@ export default class Router implements BaseRouter {
this.asPath = cleanedAs
Router.events.emit('hashChangeStart', as, routeProps)
// TODO: do we need the resolved href when only a hash change?
this.changeState(method, url, as, options)
this.scrollToHash(cleanedAs)
this.changeState(method, url, as, {
...options,
scroll: false,
})
if (scroll) {
this.scrollToHash(cleanedAs)
}
this.notify(this.components[this.route], null)
Router.events.emit('hashChangeComplete', as, routeProps)
return true
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.11-canary.6",
"version": "12.0.11-canary.7",
"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.11-canary.6",
"version": "12.0.11-canary.7",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
Loading

0 comments on commit 73b9cc5

Please sign in to comment.