Skip to content

Commit

Permalink
Merge branch 'canary' into fix-image-preload-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Sep 2, 2020
2 parents f8b4462 + aa568a5 commit d2ce0ec
Show file tree
Hide file tree
Showing 53 changed files with 658 additions and 753 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
steps:
- run: exit 0

testWebpack5:
name: webpack 5 (Basic, Production, Acceptance)
testFutureDependencies:
name: React 17 + webpack 5 (Basic, Production, Acceptance)
runs-on: ubuntu-latest
env:
NEXT_TELEMETRY_DISABLED: 1
Expand All @@ -108,6 +108,8 @@ jobs:
- uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- run: cat package.json | jq '.resolutions.webpack = "^5.0.0-beta.22"' > package.json.tmp && mv package.json.tmp package.json
- run: cat package.json | jq '.resolutions.react = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- run: cat package.json | jq '.resolutions."react-dom" = "^17.0.0-rc.1"' > package.json.tmp && mv package.json.tmp package.json
- run: yarn install --check-files
- run: node run-tests.js test/integration/production/test/index.test.js
- run: node run-tests.js test/integration/basic/test/index.test.js
Expand Down
7 changes: 7 additions & 0 deletions docs/basic-features/fast-refresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ description:

# Fast Refresh

<details open>
<summary><b>Examples</b></summary>
<ul>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/fast-refresh-demo">Fast Refresh Demo</a></li>
</ul>
</details>

Fast Refresh is a Next.js feature that gives you instantaneous feedback on
edits made to your React components. Fast Refresh is enabled by default in all
Next.js applications on **9.4 or newer**. With Next.js Fast Refresh enabled,
Expand Down
34 changes: 34 additions & 0 deletions examples/fast-refresh-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
23 changes: 23 additions & 0 deletions examples/fast-refresh-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Fast Refresh Demo

Next.js ships with [Fast Refresh](https://nextjs.org/docs/basic-features/fast-refresh) which gives you instantaneous feedback on edits made to your React components.

This demos shows how the state of an auto incrementing value and a classic counter is preserved after edits or if there are errors.

## Deploy your own

Deploy the example using [Vercel](https://vercel.com):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/fast-refresh-demo)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example fast-refresh-demo fast-refresh-demo
# or
yarn create next-app --example fast-refresh-demo fast-refresh-demo
```

Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
5 changes: 5 additions & 0 deletions examples/fast-refresh-demo/components/Button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styles from './Button.module.css'

export default function Button(props) {
return <button type="button" className={styles.btn} {...props} />
}
32 changes: 32 additions & 0 deletions examples/fast-refresh-demo/components/Button.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
button.btn {
margin: 0;
border: 1px solid #d1d1d1;
border-radius: 5px;
padding: 0.5em;
vertical-align: middle;
white-space: normal;
background: none;
line-height: 1;
font-size: 1rem;
font-family: inherit;
transition: all 0.2s ease;
}

button.btn {
padding: 0.65em 1em;
background: #0076ff;
color: #fff;
border: none;
cursor: pointer;
transition: all 0.2s ease;
}
button.btn:focus {
outline: 0;
border-color: #0076ff;
}
button.btn:hover {
background: rgba(0, 118, 255, 0.8);
}
button.btn:focus {
box-shadow: 0 0 0 2px rgba(0, 118, 255, 0.5);
}
11 changes: 11 additions & 0 deletions examples/fast-refresh-demo/components/ClickCount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useCallback, useState } from 'react'
import Button from './Button'

export default function ClickCount() {
const [count, setCount] = useState(0)
const increment = useCallback(() => {
setCount((v) => v + 1)
}, [setCount])

return <Button onClick={increment}>Clicks: {count}</Button>
}
14 changes: 14 additions & 0 deletions examples/fast-refresh-demo/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica',
'Arial', sans-serif;
margin: 0 auto;
font-size: 16px;
line-height: 1.65;
word-break: break-word;
font-kerning: auto;
font-variant: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
hyphens: auto;
}
15 changes: 15 additions & 0 deletions examples/fast-refresh-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "fast-refresh-demo",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"license": "MIT"
}
5 changes: 5 additions & 0 deletions examples/fast-refresh-demo/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../global.css'

export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
71 changes: 71 additions & 0 deletions examples/fast-refresh-demo/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useCallback, useEffect, useState } from 'react'
import Button from '../components/Button'
import ClickCount from '../components/ClickCount'
import styles from '../styles/home.module.css'

function throwError() {
console.log(
// The function body() is not defined
document.body()
)
}

function Home() {
const [count, setCount] = useState(0)
const increment = useCallback(() => {
setCount((v) => v + 1)
}, [setCount])

useEffect(() => {
const r = setInterval(() => {
increment()
}, 1000)

return () => {
clearInterval(r)
}
}, [increment])

return (
<main className={styles.main}>
<h1>Fast Refresh Demo</h1>
<p>
Fast Refresh is a Next.js feature that gives you instantaneous feedback
on edits made to your React components, without ever losing component
state.
</p>
<hr className={styles.hr} />
<div>
<p>
Auto incrementing value. The counter won't reset after edits or if
there are errors.
</p>
<p>Current value: {count}</p>
</div>
<hr className={styles.hr} />
<div>
<p>Component with state.</p>
<ClickCount />
</div>
<hr className={styles.hr} />
<div>
<p>
The button below will throw 2 errors. You'll see the error overlay to
let you know about the errors but it won't break the page or reset
your state.
</p>
<Button
onClick={(e) => {
setTimeout(() => document.parentNode(), 0)
throwError()
}}
>
Throw an Error
</Button>
</div>
<hr className={styles.hr} />
</main>
)
}

export default Home
11 changes: 11 additions & 0 deletions examples/fast-refresh-demo/styles/home.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.main {
padding: 20px 20px 60px;
max-width: 680px;
margin: 0 auto;
}

.hr {
border: none;
border-bottom: 1px solid #efefef;
margin: 3em auto;
}
8 changes: 4 additions & 4 deletions examples/with-framer-motion/components/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Thumbnail = ({ id, i }) => (
>
<Link href="/image/[index]" as={`/image/${i}`} scroll={false}>
<motion.img
src={`https://static1.squarespace.com/static/5b475b2c50a54f54f9b4e1dc/t/${id}.jpg?format=1500w`}
src={`https://images.unsplash.com/${id}?auto=format&fit=crop&w=1500`}
alt="The Barbican"
variants={imageVariants}
transition={transition}
Expand Down Expand Up @@ -69,7 +69,7 @@ const Thumbnail = ({ id, i }) => (

const Gallery = () => (
<>
<h1>Barbican</h1>
<h1>Motion</h1>
<div className="gallery">
<motion.div
className="thumbnails"
Expand Down Expand Up @@ -118,14 +118,14 @@ const Gallery = () => (
bottom: -130px;
}
}
@media screen and (min-width: 800px) {
h1 {
font-size: 180px;
bottom: -170px;
}
}
@media screen and (min-width: 1000px) {
h1 {
font-size: 220px;
Expand Down
2 changes: 1 addition & 1 deletion examples/with-framer-motion/components/SingleImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const SingleImage = ({ index }) => (
<motion.div className="single" initial="exit" animate="enter" exit="exit">
<motion.img
variants={imageVariants}
src={`https://static1.squarespace.com/static/5b475b2c50a54f54f9b4e1dc/t/${images[index]}.jpg?format=1500w`}
src={`https://images.unsplash.com/${images[index]}?auto=format&fit=crop&w=1500`}
alt="The Barbican"
/>
<motion.div className="back" variants={backVariants}>
Expand Down
12 changes: 6 additions & 6 deletions examples/with-framer-motion/constants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const images = [
'5b5a3938562fa764113169a6/1532639559620/DSCF3338',
'5b5a3628f950b7390fbfc5f8/1532639027872/DSCF3246',
'5b5a3741575d1fccb5ac6b3f/1532639066455/DSCF3268',
'5b5a376b0e2e728eeeaca8e4/1532683586969/DSCF3274',
'5b5c228403ce64f3c80d4d8e/1532764845121/DSCF3348',
'5b5a3b800e2e728eeead9575/1532640158813/DSCF3375',
'photo-1520517601640-32ec514e4a15',
'photo-1518780535463-bc357fa46e64',
'photo-1555068178-89125fb6356d',
'photo-1553503359-d4ff2537a6ea',
'photo-1585211751845-37663b4ab614',
'photo-1496467115032-c504ef76521b',
]
1 change: 0 additions & 1 deletion examples/with-framer-motion/pages/image/[index].js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function getStaticProps({ params }) {
export async function getStaticPaths() {
return {
paths: images.map((_id, index) => {
console.log(index)
return {
params: {
index: `${index}`,
Expand Down
10 changes: 5 additions & 5 deletions examples/with-react-intl/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"11754": "An example app integrating React Intl with Next.js",
"65a8e": "Hello, World!",
"8cf04": "Home",
"8f7f4": "About",
"9c817": "React Intl Next.js Example"
"AvQcw8": "React Intl Next.js Example",
"N015Sp": "Hello, World!",
"ejEGdx": "Home",
"fnfXnF": "An example app integrating React Intl with Next.js",
"g5pX+a": "About"
}
10 changes: 5 additions & 5 deletions examples/with-react-intl/lang/fr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"11754": "Un exemple d'application intégrant React Intl avec Next.js",
"65a8e": "Bonjour le monde!",
"8cf04": "Accueil",
"8f7f4": "À propos de nous",
"9c817": "React Intl Next.js Exemple"
"AvQcw8": "Un exemple d'application intégrant React Intl avec Next.js",
"N015Sp": "Bonjour le monde!",
"ejEGdx": "Accueil",
"fnfXnF": "À propos de nous",
"g5pX+a": "React Intl Next.js Exemple"
}
2 changes: 1 addition & 1 deletion examples/with-react-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"dev": "cross-env NODE_ICU_DATA=node_modules/full-icu ts-node --project tsconfig.server.json server.ts",
"build": "npm run extract:i18n && npm run compile:i18n && next build && tsc -p tsconfig.server.json",
"extract:i18n": "formatjs extract '{pages,components}/*.{js,ts,tsx}' --format simple --out-file lang/en.json",
"extract:i18n": "formatjs extract '{pages,components}/*.{js,ts,tsx}' --format simple --id-interpolation-pattern '[sha512:contenthash:base64:6]' --out-file lang/en.json",
"compile:i18n": "formatjs compile-folder --ast --format simple lang/ compiled-lang/",
"start": "cross-env NODE_ENV=production NODE_ICU_DATA=node_modules/full-icu node dist/server"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/with-react-intl/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const getInitialProps: typeof App.getInitialProps = async appContext => {
const {
ctx: {req},
} = appContext;
const locale = (req as any)?.locale ?? 'en';
const locale = (req as any)?.locale || (window as any).LOCALE || 'en';

const [appProps, messages] = await Promise.all([
polyfill(locale),
Expand Down
Loading

0 comments on commit d2ce0ec

Please sign in to comment.