Skip to content

Commit

Permalink
Merge branch 'canary' into hotfix/fix-web-vitals
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Oct 16, 2020
2 parents 0466701 + 4b126cc commit a1c8328
Show file tree
Hide file tree
Showing 38 changed files with 746 additions and 85 deletions.
2 changes: 1 addition & 1 deletion examples/with-expo-typescript/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @generated: @expo/next-adapter@2.1.9
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-nextjs.md#withexpo
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/guides/using-nextjs.md

const { withExpo } = require('@expo/next-adapter')

Expand Down
2 changes: 1 addition & 1 deletion examples/with-expo/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @generated: @expo/next-adapter@2.1.5
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-nextjs.md#withexpo
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/guides/using-nextjs.md

const { withExpo } = require('@expo/next-adapter')

Expand Down
6 changes: 4 additions & 2 deletions examples/with-prisma/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Prisma.io maintains it's own Next.Js examples

- [Javascript](https://github.com/prisma/prisma-examples/tree/master/javascript/rest-nextjs)
- [Typescript](https://github.com/prisma/prisma-examples/tree/master/typescript/rest-nextjs)
- [Typescript-GraphQL](https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-nextjs)
- [Typescript: rest-api-routes-auth](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-api-routes-auth)
- [Typescript: rest-api-routes](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-api-routes)
- [Typescript: rest-api-express](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-express)
- [Typescript: graphql](https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-nextjs)
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": "9.5.6-canary.0"
"version": "9.5.6-canary.2"
}
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": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"keywords": [
"react",
"next",
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": "9.5.6-canary.0",
"version": "9.5.6-canary.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"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": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"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": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"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": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-google-analytics"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-sentry"
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": "9.5.6-canary.0",
"version": "9.5.6-canary.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.2",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
30 changes: 25 additions & 5 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type PrerenderManifest = {
version: 2
routes: { [route: string]: SsgRoute }
dynamicRoutes: { [route: string]: DynamicSsgRoute }
notFoundRoutes: string[]
preview: __ApiPreviewProps
}

Expand Down Expand Up @@ -306,6 +307,15 @@ export default async function build(
dataRouteRegex: string
namedDataRouteRegex?: string
}>
i18n?: {
locales: string[]
defaultLocale: string[]
domains: Array<{
domain: string
defaultLocale: string
locales: string[]
}>
}
} = {
version: 3,
pages404: true,
Expand All @@ -325,6 +335,7 @@ export default async function build(
}
}),
dataRoutes: [],
i18n: config.experimental.i18n || undefined,
}

await promises.mkdir(distDir, { recursive: true })
Expand Down Expand Up @@ -703,6 +714,7 @@ export default async function build(

const finalPrerenderRoutes: { [route: string]: SsgRoute } = {}
const tbdPrerenderRoutes: string[] = []
let ssgNotFoundPaths: string[] = []

if (postCompileSpinner) postCompileSpinner.stopAndPersist()

Expand All @@ -720,6 +732,7 @@ export default async function build(
const exportConfig: any = {
...config,
initialPageRevalidationMap: {},
ssgNotFoundPaths: [] as string[],
// Default map will be the collection of automatic statically exported
// pages and incremental pages.
// n.b. we cannot handle this above in combinedPages because the dynamic
Expand Down Expand Up @@ -785,7 +798,7 @@ export default async function build(
const outputPath = `/${locale}${page === '/' ? '' : page}`

defaultMap[outputPath] = {
page: defaultMap[page].page,
page: defaultMap[page]?.page || page,
query: { __nextLocale: locale },
}

Expand All @@ -811,6 +824,7 @@ export default async function build(
const postBuildSpinner = createSpinner({
prefixText: `${Log.prefixes.info} Finalizing page optimization`,
})
ssgNotFoundPaths = exportConfig.ssgNotFoundPaths

// remove server bundles that were exported
for (const page of staticPages) {
Expand Down Expand Up @@ -864,11 +878,12 @@ export default async function build(
}

const { i18n } = config.experimental
const isNotFound = ssgNotFoundPaths.includes(page)

// for SSG files with i18n the non-prerendered variants are
// output with the locale prefixed so don't attempt moving
// without the prefix
if (!i18n || additionalSsgFile) {
if ((!i18n || additionalSsgFile) && !isNotFound) {
await promises.mkdir(path.dirname(dest), { recursive: true })
await promises.rename(orig, dest)
} else if (i18n && !isSsg) {
Expand All @@ -881,9 +896,14 @@ export default async function build(
if (additionalSsgFile) return

for (const locale of i18n.locales) {
const curPath = `/${locale}${page === '/' ? '' : page}`
const localeExt = page === '/' ? path.extname(file) : ''
const relativeDestNoPages = relativeDest.substr('pages/'.length)

if (isSsg && ssgNotFoundPaths.includes(curPath)) {
continue
}

const updatedRelativeDest = path.join(
'pages',
locale + localeExt,
Expand All @@ -903,9 +923,7 @@ export default async function build(
)

if (!isSsg) {
pagesManifest[
`/${locale}${page === '/' ? '' : page}`
] = updatedRelativeDest
pagesManifest[curPath] = updatedRelativeDest
}
await promises.mkdir(path.dirname(updatedDest), { recursive: true })
await promises.rename(updatedOrig, updatedDest)
Expand Down Expand Up @@ -1056,6 +1074,7 @@ export default async function build(
version: 2,
routes: finalPrerenderRoutes,
dynamicRoutes: finalDynamicRoutes,
notFoundRoutes: ssgNotFoundPaths,
preview: previewProps,
}

Expand All @@ -1075,6 +1094,7 @@ export default async function build(
routes: {},
dynamicRoutes: {},
preview: previewProps,
notFoundRoutes: [],
}
await promises.writeFile(
path.join(distDir, PRERENDER_MANIFEST),
Expand Down
14 changes: 13 additions & 1 deletion packages/next/build/webpack/loaders/next-serverless-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ const nextServerlessLoader: loader.Loader = function () {
${handleBasePath}
// remove ?amp=1 from request URL if rendering for export
if (fromExport && parsedUrl.query.amp) {
const queryNoAmp = Object.assign({}, origQuery)
delete queryNoAmp.amp
req.url = formatUrl({
...parsedUrl,
search: undefined,
query: queryNoAmp
})
}
if (parsedUrl.pathname.match(/_next\\/data/)) {
const {
default: getrouteNoAssetPath,
Expand All @@ -558,7 +570,7 @@ const nextServerlessLoader: loader.Loader = function () {
isDataReq: _nextData,
locale: detectedLocale,
locales,
defaultLocale,
defaultLocale: i18n.defaultLocale,
},
options,
)
Expand Down
39 changes: 26 additions & 13 deletions packages/next/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type LinkProps = {
shallow?: boolean
passHref?: boolean
prefetch?: boolean
locale?: string
}
type LinkPropsRequired = RequiredKeys<LinkProps>
type LinkPropsOptional = OptionalKeys<LinkProps>
Expand Down Expand Up @@ -125,7 +126,8 @@ function linkClicked(
as: string,
replace?: boolean,
shallow?: boolean,
scroll?: boolean
scroll?: boolean,
locale?: string
): void {
const { nodeName } = e.currentTarget

Expand All @@ -142,7 +144,7 @@ function linkClicked(
}

// replace state instead of push if prop is present
router[replace ? 'replace' : 'push'](href, as, { shallow }).then(
router[replace ? 'replace' : 'push'](href, as, { shallow, locale }).then(
(success: boolean) => {
if (!success) return
if (scroll) {
Expand Down Expand Up @@ -202,21 +204,28 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
shallow: true,
passHref: true,
prefetch: true,
locale: true,
} as const
const optionalProps: LinkPropsOptional[] = Object.keys(
optionalPropsGuard
) as LinkPropsOptional[]
optionalProps.forEach((key: LinkPropsOptional) => {
const valType = typeof props[key]

if (key === 'as') {
if (
props[key] &&
typeof props[key] !== 'string' &&
typeof props[key] !== 'object'
) {
if (props[key] && valType !== 'string' && valType !== 'object') {
throw createPropError({
key,
expected: '`string` or `object`',
actual: typeof props[key],
actual: valType,
})
}
} else if (key === 'locale') {
if (props[key] && valType !== 'string') {
throw createPropError({
key,
expected: '`string`',
actual: valType,
})
}
} else if (
Expand All @@ -226,11 +235,11 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
key === 'passHref' ||
key === 'prefetch'
) {
if (props[key] != null && typeof props[key] !== 'boolean') {
if (props[key] != null && valType !== 'boolean') {
throw createPropError({
key,
expected: '`boolean`',
actual: typeof props[key],
actual: valType,
})
}
} else {
Expand Down Expand Up @@ -285,7 +294,7 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
}
}, [p, childElm, href, as, router])

let { children, replace, shallow, scroll } = props
let { children, replace, shallow, scroll, locale } = props
// Deprecated. Warning shown by propType check. If the children provided is a string (<Link>example</Link>) we wrap it in an <a> tag
if (typeof children === 'string') {
children = <a>{children}</a>
Expand Down Expand Up @@ -314,7 +323,7 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
child.props.onClick(e)
}
if (!e.defaultPrevented) {
linkClicked(e, router, href, as, replace, shallow, scroll)
linkClicked(e, router, href, as, replace, shallow, scroll, locale)
}
},
}
Expand All @@ -333,7 +342,11 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
// defined, we specify the current 'href', so that repetition is not needed by the user
if (props.passHref || (child.type === 'a' && !('href' in child.props))) {
childProps.href = addBasePath(
addLocale(as, router && router.locale, router && router.defaultLocale)
addLocale(
as,
locale || (router && router.locale),
router && router.defaultLocale
)
)
}

Expand Down

0 comments on commit a1c8328

Please sign in to comment.