Skip to content

Commit

Permalink
Merge branch 'canary' into edge-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 23, 2022
2 parents 85e7771 + 5d9f390 commit ea4db73
Show file tree
Hide file tree
Showing 75 changed files with 1,043 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Expand Up @@ -1008,7 +1008,7 @@ jobs:
- run: npm i -g pnpm@${PNPM_VERSION}
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: ./scripts/publish-native.js $GITHUB_REF
- run: ./scripts/publish-release.sh
- run: ./scripts/publish-release.js

testDeployE2E:
name: E2E (deploy)
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-features/static-html-export.md
Expand Up @@ -45,7 +45,7 @@ The majority of core Next.js features needed to build a static site are supporte
- [Client-side data fetching](/docs/basic-features/data-fetching/client-side.md)
- [`getStaticProps`](/docs/basic-features/data-fetching/get-static-props.md)
- [`getStaticPaths`](/docs/basic-features/data-fetching/get-static-paths.md)
- [Image Optimization](/docs/basic-features/image-optimization.md) using a [custom loader](/docs/basic-features/image-optimization.md#loader)
- [Image Optimization](/docs/basic-features/image-optimization.md) using a [custom loader](/docs/basic-features/image-optimization.md#loaders)

## Unsupported Features

Expand Down
34 changes: 34 additions & 0 deletions errors/react-hydration-error.md
Expand Up @@ -37,6 +37,40 @@ function MyComponent() {
}
```

Another example:

Invalid HTML may cause hydration mismatch such as div inside p.

```jsx
export const IncorrectComponent = () => {
return (
<p>
<div>
This is not correct and should never be done because the p tag has been
abused
</div>
<Image src="/vercel.svg" alt="" width="30" height="30" />
</p>
)
}
```

How to fix it:

```jsx
export const CorrectComponent = () => {
return (
<div>
<div>
This is correct and should work because a div is really good for this
task.
</div>
<Image src="/vercel.svg" alt="" width="30" height="30" />
</div>
)
}
```

Common causes with css-in-js libraries:

- When using Styled Components / Emotion
Expand Down
25 changes: 25 additions & 0 deletions examples/with-google-analytics/pages/_document.js
@@ -0,0 +1,25 @@
import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />

{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
`,
}}
/>
</body>
</Html>
)
}
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.3.2-canary.3"
"version": "12.3.2-canary.7"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.3.2-canary.3",
"version": "12.3.2-canary.7",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.3.2-canary.3",
"version": "12.3.2-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.3.2-canary.3",
"@next/eslint-plugin-next": "12.3.2-canary.7",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.21.0",
"eslint-import-resolver-node": "^0.3.6",
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.3.2-canary.3",
"version": "12.3.2-canary.7",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions packages/font/local/index.d.ts
@@ -0,0 +1 @@
export { default } from '../dist/local/index'
1 change: 1 addition & 0 deletions packages/font/local/index.js
@@ -0,0 +1 @@
throw new Error('@next/font/local is not correctly setup')
1 change: 1 addition & 0 deletions packages/font/local/loader.d.ts
@@ -0,0 +1 @@
export { default } from '../dist/local/loader'
1 change: 1 addition & 0 deletions packages/font/local/loader.js
@@ -0,0 +1 @@
module.exports = require('../dist/local/loader')
8 changes: 3 additions & 5 deletions packages/font/package.json
@@ -1,22 +1,20 @@
{
"name": "@next/font",
"version": "12.3.2-canary.3",
"version": "12.3.2-canary.7",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
},
"files": [
"dist",
"google"
"google",
"local"
],
"license": "MIT",
"scripts": {
"build": "rm -rf dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json"
},
"publishConfig": {
"access": "public"
}
}
6 changes: 1 addition & 5 deletions packages/font/src/google/index.ts
@@ -1,9 +1,5 @@
import type { FontModule } from 'next/font'
type Display = 'auto' | 'block' | 'swap' | 'fallback' | 'optional'
type FontModule = {
className: string
variable: string
style: { fontFamily: string; fontWeight?: number; fontStyle?: string }
}
export declare function ABeeZee(options: {
variant: '400' | '400-italic'
display?: Display
Expand Down
14 changes: 5 additions & 9 deletions packages/font/src/google/loader.ts
@@ -1,3 +1,4 @@
import type { FontLoader } from 'next/font'
// @ts-ignore
import fetch from 'next/dist/compiled/node-fetch'
// @ts-ignore
Expand All @@ -9,19 +10,12 @@ import {
validateData,
} from './utils'

type FontLoaderOptions = {
functionName: string
data: any[]
config: any
emitFontFile: (content: Buffer, ext: string, preload: boolean) => string
}

export default async function downloadGoogleFonts({
const downloadGoogleFonts: FontLoader = async ({
functionName,
data,
config,
emitFontFile,
}: FontLoaderOptions) {
}) => {
if (!config?.subsets) {
throw new Error(
'Please specify subsets for `@next/font/google` in your `next.config.js`'
Expand Down Expand Up @@ -119,3 +113,5 @@ export default async function downloadGoogleFonts({
fallbackFonts: fallback,
}
}

export default downloadGoogleFonts
24 changes: 24 additions & 0 deletions packages/font/src/local/index.ts
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { FontModule } from 'next/font'
type Display = 'auto' | 'block' | 'swap' | 'fallback' | 'optional'
type LocalFont = {
src: string | Array<{ file: string; unicodeRange: string }>
display?: Display
weight?: string
style?: string
fallback?: string[]
preload?: boolean

ascentOverride?: string
descentOverride?: string
fontStretch?: string
fontVariant?: string
fontFeatureSettings?: string
fontVariationSettings?: string
lineGapOverride?: string
sizeAdjust?: string
}

export default function localFont(options: LocalFont): FontModule {
throw new Error()
}
67 changes: 67 additions & 0 deletions packages/font/src/local/loader.ts
@@ -0,0 +1,67 @@
import type { FontLoader } from 'next/font'

import { promisify } from 'util'
import { validateData } from './utils'

const fetchFonts: FontLoader = async ({
functionName,
data,
emitFontFile,
resolve,
fs,
}) => {
const {
family,
files,
display,
weight,
style,
fallback,
preload,
ascentOverride,
descentOverride,
lineGapOverride,
fontStretch,
fontFeatureSettings,
sizeAdjust,
} = validateData(functionName, data)

const fontFaces = await Promise.all(
files.map(async ({ file, ext, format, unicodeRange }) => {
const resolved = await resolve(file)
const fileBuffer = await promisify(fs.readFile)(resolved)

const fontUrl = emitFontFile(fileBuffer, ext, preload)

const fontFaceProperties = [
['font-family', `'${family}'`],
['src', `url(${fontUrl}) format('${format}')`],
['font-display', display],
...(weight ? [['font-weight', weight]] : []),
...(style ? [['font-style', style]] : []),
...(ascentOverride ? [['ascent-override', ascentOverride]] : []),
...(descentOverride ? [['descent-override', descentOverride]] : []),
...(lineGapOverride ? [['line-gap-override', lineGapOverride]] : []),
...(fontStretch ? [['font-stretch', fontStretch]] : []),
...(fontFeatureSettings
? [['font-feature-settings', fontFeatureSettings]]
: []),
...(sizeAdjust ? [['size-adjust', sizeAdjust]] : []),
...(unicodeRange ? [['unicode-range', unicodeRange]] : ''),
]

return `@font-face {
${fontFaceProperties
.map(([property, value]) => `${property}: ${value};`)
.join('\n')}
}`
})
)

return {
css: fontFaces.join('\n'),
fallbackFonts: fallback,
}
}

export default fetchFonts

0 comments on commit ea4db73

Please sign in to comment.