Skip to content

Commit

Permalink
Merge branch 'canary' into kt/41064
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Dec 13, 2022
2 parents 244deb4 + be90c0b commit f5b8291
Show file tree
Hide file tree
Showing 130 changed files with 2,232 additions and 626 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

/packages/next/build/ @timneutkens @ijjk @shuding @padmaia @huozhi
/packages/next/telemetry/ @timneutkens @ijjk @shuding @padmaia
/packages/next-swc/ @timneutkens @ijjk @shuding @padmaia
/packages/next-swc/ @timneutkens @ijjk @shuding @vercel/web-tooling
/packages/next/build/swc/ @timneutkens @ijjk @shuding @vercel/web-tooling

# Image Component (@styfle)

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/issue-validator/canary.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If the issue does not reproduce with the `canary` version, then it has already b

### **How can I quickly verify if my issue has been fixed in `canary`?**

The safest way is to install `next@canary` in your project and test it, but you can also search through [closed Next.js issues](https://github.com/vercel/next.js/issues?q=is%3Aissue+is%3Aclosed) for duplicates or check the [Next.js releases](https://github.com/vercel/next.js/releases).
The safest way is to install `next@canary` in your project and test it, but you can also search through [closed Next.js issues](https://github.com/vercel/next.js/issues?q=is%3Aissue+is%3Aclosed) for duplicates or check the [Next.js releases](https://github.com/vercel/next.js/releases). You can also use the GitHub [template](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) (preferred), or the [CodeSandbox](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template) or [StackBlitz](https://stackblitz.com/fork/github/vercel/next.js/tree/canary/examples/reproduction-template) templates to create a reproduction with `canary` from scratch.

### **My issue has been open for a long time, why do I need to verify `canary` now?**

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ jobs:
- run: RESET_VC_PROJECT=true node scripts/reset-vercel-project.mjs
name: Reset test project

- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && ls && curl https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} && xvfb-run node run-tests.js --type e2e >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && ls && curl https://install-node.vercel.app/v16 | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} && xvfb-run node run-tests.js --type e2e >> /proc/1/fd/1"
name: Run test/e2e (deploy)

- name: Upload test trace
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ coverage
# test output
test/**/out*
test/**/next-env.d.ts
test/**/tsconfig.json
.DS_Store
/e2e-tests
test/tmp/**
Expand All @@ -46,4 +47,4 @@ test-timings.json

# Cache
*.tsbuildinfo
.swc/
.swc/
24 changes: 24 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"recommendations": [
// Linting / Formatting
"rust-lang.rust-analyzer",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"usernamehw.errorlens",

// Testing
"orta.vscode-jest",

// PR management / Reviewing
"github.vscode-pull-request-github",

// Showing todo comments
"gruntfuggly.todo-tree",

// Collaborating
"ms-vsliveshare.vsliveshare",

// Debugging
"ms-vscode.vscode-js-profile-flame"
]
}
47 changes: 43 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
{
// Formatting using Prettier by default for all languages
"editor.defaultFormatter": "esbenp.prettier-vscode",
// Formatting using Prettier for JavaScript, overrides VSCode default.
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// Formatting using Rust-Analyzer for Rust.
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
// Linting using ESLint.
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
"typescript",
"typescriptreact"
],
"debug.javascript.unmapMissingSources": true,
// Disable Jest autoRun as otherwise it will start running all tests the first time.
"jest.autoRun": "off",

// Debugging.
"debug.javascript.unmapMissingSources": true,

"files.exclude": {
"**/node_modules": false,
"node_modules": true,
"*[!test]**/node_modules": true
}
},

// Ensure enough terminal history is preserved when running tests.
"terminal.integrated.scrollback": 10000,

// Configure todo-tree to exclude node_modules, dist, and compiled.
"todo-tree.filtering.excludeGlobs": [
"**/node_modules",
"**/dist",
"**/compiled"
],
// Match TODO-APP in addition to other TODOs.
"todo-tree.general.tags": [
"BUG",
"HACK",
"FIXME",
"TODO",
"XXX",
"[ ]",
"[x]",
"TODO-APP"
],

// Disable TypeScript surveys.
"typescript.surveys.enabled": false
}
2 changes: 1 addition & 1 deletion docs/advanced-features/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = {

### Jest

Jest support not only includes the transformation previously provided by Babel, but also simplifies configuring Jest together with Next.js including:
The Next.js Compiler transpiles your tests and simplifies configuring Jest together with Next.js including:

- Auto mocking of `.css`, `.module.css` (and their `.scss` variants), and image imports
- Automatically sets up `transform` using SWC
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/eslint.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/
| ✔️ | [@next/next/no-head-element](/docs/messages/no-head-element.md) | Prevent usage of `<head>` element. |
| ✔️ | [@next/next/no-head-import-in-document](/docs/messages/no-head-import-in-document.md) | Prevent usage of `next/head` in `pages/_document.js`. |
| ✔️ | [@next/next/no-html-link-for-pages](/docs/messages/no-html-link-for-pages.md) | Prevent usage of `<a>` elements to navigate to internal Next.js pages. |
| ✔️ | [@next/next/no-img-element](/docs/messages/no-img-element.md) | Prevent usage of `<img>` element to prevent layout shift. |
| ✔️ | [@next/next/no-img-element](/docs/messages/no-img-element.md) | Prevent usage of `<img>` element due to slower LCP and higher bandwidth. |
| ✔️ | [@next/next/no-page-custom-font](/docs/messages/no-page-custom-font.md) | Prevent page-only custom fonts. |
| ✔️ | [@next/next/no-script-component-in-head](/docs/messages/no-script-component-in-head.md) | Prevent usage of `next/script` in `next/head` component. |
| ✔️ | [@next/next/no-styled-jsx-in-document](/docs/messages/no-styled-jsx-in-document.md) | Prevent usage of `styled-jsx` in `pages/_document.js`. |
Expand Down
30 changes: 30 additions & 0 deletions errors/context-in-server-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# createContext in a Server Component

#### Why This Error Occurred

You are using `createContext` in a Server Component but it only works in Client Components.

#### Possible Ways to Fix It

Mark the component using `createContext` as a Client Component by adding `'use client'` at the top of the file.

##### Before

```jsx
import { createContext } from 'react'

const Context = createContext()
```

##### After

```jsx
'use client'
import { createContext } from 'react'

const Context = createContext()
```

### Useful Links

[Server and Client Components](https://beta.nextjs.org/docs/rendering/server-and-client-components#context)
4 changes: 4 additions & 0 deletions errors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,10 @@
{
"title": "fast-refresh-reload",
"path": "/errors/fast-refresh-reload.md"
},
{
"title": "context-in-server-component",
"path": "/errors/context-in-server-component.md"
}
]
}
Expand Down
46 changes: 27 additions & 19 deletions errors/no-img-element.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
# No Img Element
# No img element

> Prevent usage of `<img>` element to prevent layout shift.
> Prevent usage of `<img>` element to prevent layout shift and favor [optimized images](https://nextjs.org/docs/basic-features/image-optimization).
### Why This Error Occurred

An `<img>` element was used to display an image. Use either `<picture>` in conjunction with `<img>` element, or use `next/image` that has better performance and automatic Image Optimization over `<img>`.
An `<img>` element was used to display an image.

### Possible Ways to Fix It

Import and use the `<Image />` component:
Use [`next/image`](https://nextjs.org/docs/api-reference/next/image) to improve performance with automatic [Image Optimization](https://nextjs.org/docs/basic-features/image-optimization).

> Note: If deploying to a [managed hosting provider](https://nextjs.org/docs/deployment), remember to check pricing since optimized images might be charged differently that the original images. If self-hosting, remember to install [`sharp`](https://www.npmjs.com/package/sharp) and check if your server has enough storage to cache the optimized images.
```jsx
import Image from 'next/image'

function Home() {
return (
<>
<Image
src="https://example.com/test"
alt="Landscape picture"
width={500}
height={500}
/>
</>
<Image
src="https://example.com/hero.jpg"
alt="Landscape picture"
width={800}
height={500}
/>
)
}

export default Home
```

If you would like to use `next/image` featrues such as blur-up placeholders but disable Image Optimization, you can do so using [unoptimized](https://nextjs.org/docs/api-reference/next/image#unoptimized).

<br />

Use `<picture>` in conjunction with `<img>` element:
Or, use a `<picture>` element with the nested `<img>` element:

```jsx
function Home() {
return (
<>
<picture>
<source srcSet="https://example.com/test" type="image/webp" />
<img src="https://example.com/test" alt="Landscape picture" />
</picture>
</>
<picture>
<source srcSet="https://example.com/hero.avif" type="image/avif" />
<source srcSet="https://example.com/hero.webp" type="image/webp" />
<img
src="https://example.com/hero.jpg"
alt="Landscape picture"
width={800}
height={500}
/>
</picture>
)
}
```

### Useful Links

- [Image Component and Image Optimization](https://nextjs.org/docs/basic-features/image-optimization)
- [next/image API Reference](https://nextjs.org/docs/api-reference/next/image)
- [Largest Contentful Paint (LCP)](https://nextjs.org/learn/seo/web-performance/lcp)
2 changes: 1 addition & 1 deletion examples/github-pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pnpm create next-app --example github-pages nextjs-github-pages
1. Edit `next.config.js` to match your GitHub repository name.
1. Push the starter code to the `main` branch.
1. Run the `deploy` script (e.g. `npm run deploy`) to create the `gh-pages` branch.
1. On GitHub, go to **Settings** > **Pages** > **Source**, and choose `gh-pages` as the branch with the `/root` folder. Hit **Save**.
1. On GitHub, go to **Settings** > **Pages** > **Branch**, and choose `gh-pages` as the branch with the `/root` folder. Hit **Save**.
1. Make a change.
1. Run the `deploy` script again to push the changes to GitHub Pages.

Expand Down
6 changes: 3 additions & 3 deletions examples/reproduction-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.14",
"typescript": "^4.7.4"
"@types/node": "^18.11.13",
"@types/react": "^18.0.26",
"typescript": "^4.9.4"
}
}
10 changes: 5 additions & 5 deletions examples/with-google-analytics/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />

<Head>
{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
dangerouslySetInnerHTML={{
Expand All @@ -19,6 +15,10 @@ export default function Document() {
`,
}}
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useEffect, useRef } from 'react'
import { gsap } from 'gsap'

const Content = () => {
export default function Content() {
let line1 = useRef(null)

useEffect(() => {
gsap.from([line1], 0.6, {
gsap.from([line1.current], 0.6, {
delay: 0.9,
ease: 'power3.out',
y: 24,
Expand All @@ -15,7 +16,7 @@ const Content = () => {
}, [line1])

return (
<p ref={(el) => (line1 = el)} className="line">
<p ref={line1} className="line">
A Simple example using{' '}
<a
href="https://greensock.com/gsap/"
Expand All @@ -33,5 +34,3 @@ const Content = () => {
</p>
)
}

export default Content
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Title from './Title'
import Content from './Content'

const Home = () => {
export default function Home() {
return (
<div className="inner">
<Title lineContent="With-GSAP" lineContent2="Using NEXT" />
Expand All @@ -15,5 +15,3 @@ const Home = () => {
</div>
)
}

export default Home
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { useEffect, useRef } from 'react'
import { gsap } from 'gsap'

const Title = ({ lineContent, lineContent2 }) => {
type TitleProps = {
lineContent: string
lineContent2: string
}

export default function Title({ lineContent, lineContent2 }: TitleProps) {
let line1 = useRef(null)
let line2 = useRef(null)

useEffect(() => {
gsap.from([line1, line2], 0.8, {
gsap.from([line1.current, line2.current], 0.8, {
delay: 0.8,
ease: 'power3.out',
y: 64,
Expand All @@ -14,20 +20,19 @@ const Title = ({ lineContent, lineContent2 }) => {
},
})
}, [line1, line2])

return (
<h1 className="page-title">
<div className="line-wrap">
<div ref={(el) => (line1 = el)} className="line">
<div ref={line1} className="line">
{lineContent}
</div>
</div>
<div className="line-wrap">
<div ref={(el) => (line2 = el)} className="line">
<div ref={line2} className="line">
{lineContent2}
</div>
</div>
</h1>
)
}

export default Title

0 comments on commit f5b8291

Please sign in to comment.