Skip to content

Commit

Permalink
Merge branch 'canary' of https://github.com/hanneslund/next.js into c…
Browse files Browse the repository at this point in the history
…lient-only-error
  • Loading branch information
Hannes Bornö committed Feb 6, 2023
2 parents b625ada + c76380f commit 6319ce8
Show file tree
Hide file tree
Showing 104 changed files with 3,824 additions and 731 deletions.
144 changes: 124 additions & 20 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,131 @@ module.exports = (actionInfo) => {
}
},
async linkPackages({ repoDir, nextSwcVersion }) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})

const pkgPaths = new Map()
const pkgs = await fs.readdir(path.join(repoDir, 'packages'))

pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(repoDir, 'packages', pkgDirname, `packed-${pkgDirname}.tgz`)
let useTestPack = process.env.NEXT_TEST_PACK

if (useTestPack) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})

const pkgPaths = new Map()
const pkgs = (await fs.readdir(path.join(repoDir, 'packages'))).filter(
(item) => !item.startsWith('.')
)
})
return pkgPaths

pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(
repoDir,
'packages',
pkgDirname,
`packed-${pkgDirname}.tgz`
)
)
})
return pkgPaths
} else {
// TODO: remove after next stable release (current v13.1.2)
const pkgPaths = new Map()
const pkgDatas = new Map()
let pkgs

try {
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('no packages to link')
return pkgPaths
}
throw err
}

for (const pkg of pkgs) {
const pkgPath = path.join(repoDir, 'packages', pkg)
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)

const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
require('console').log(`Skipping ${pkgDataPath}`)
continue
}
const pkgData = require(pkgDataPath)
const { name } = pkgData
pkgDatas.set(name, {
pkgDataPath,
pkg,
pkgPath,
pkgData,
packedPkgPath,
})
pkgPaths.set(name, packedPkgPath)
}

for (const pkg of pkgDatas.keys()) {
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)

for (const pkg of pkgDatas.keys()) {
const { packedPkgPath } = pkgDatas.get(pkg)
if (!pkgData.dependencies || !pkgData.dependencies[pkg]) continue
pkgData.dependencies[pkg] = packedPkgPath
}

// make sure native binaries are included in local linking
if (pkg === '@next/swc') {
if (!pkgData.files) {
pkgData.files = []
}
pkgData.files.push('native')
require('console').log(
'using swc binaries: ',
await exec(`ls ${path.join(path.dirname(pkgDataPath), 'native')}`)
)
}

if (pkg === 'next') {
if (nextSwcVersion) {
Object.assign(pkgData.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native')
}
}
}

await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
)
}

// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkg, pkgPath } = pkgDatas.get(pkgName)
await exec(
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
true
)
})
)

return pkgPaths
}
},
}
}
32 changes: 22 additions & 10 deletions docs/advanced-features/preview-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ https://<your-site>/api/preview?secret=<token>&slug=<path>

> **Note**: during rendering `next/router` exposes an `isPreview` flag, see the [router object docs](/docs/api-reference/next/router.md#router-object) for more info.
### Specify the Preview Mode duration

`setPreviewData` takes an optional second parameter which should be an options object. It accepts the following keys:

- `maxAge`: Specifies the number (in seconds) for the preview session to last for.
- `path`: Specifies the path the cookie should be applied under. Defaults to `/` enabling preview mode for all paths.

```js
setPreviewData(data, {
maxAge: 60 * 60, // The preview mode cookies expire in 1 hour
path: '/about', // The preview mode cookies apply to paths with /about
})
```

### Clear the Preview Mode cookies

By default, no expiration date is set for Preview Mode cookies, so the preview session ends when the browser is closed.
Expand All @@ -186,24 +200,22 @@ To clear the Preview Mode cookies manually, create an API route that calls `clea
// pages/api/clear-preview-mode-cookies.js

export default function handler(req, res) {
res.clearPreviewData()
res.clearPreviewData({})
}
```

Then, send a request to `/api/clear-preview-mode-cookies` to invoke the API Route. If calling this route using [`next/link`](/docs/api-reference/next/link.md), you must pass `prefetch={false}` to prevent calling `clearPreviewData` during link prefetching.

### Specify the Preview Mode duration
If a path was specified in the `setPreviewData` call, you must pass the same path to `clearPreviewData`:

`setPreviewData` takes an optional second parameter which should be an options object. It accepts the following keys:
```js
// pages/api/clear-preview-mode-cookies.js

- `maxAge`: Specifies the number (in seconds) for the preview session to last for.
- `path`: Specifies the path the cookie should be applied under. Defaults to `/` enabling preview mode for all paths.
export default function handler(req, res) {
const { path } = req.query

```js
setPreviewData(data, {
maxAge: 60 * 60, // The preview mode cookies expire in 1 hour
path: '/about', // The preview mode cookies apply to paths with /about
})
res.clearPreviewData({ path })
}
```

### `previewData` size limits
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": "13.1.7-canary.4"
"version": "13.1.7-canary.6"
}
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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -12,7 +12,7 @@
"test-pack": "cd ../../ && pnpm test-pack eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "13.1.7-canary.4",
"@next/eslint-plugin-next": "13.1.7-canary.6",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.42.0",
"eslint-import-resolver-node": "^0.3.6",
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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"description": "ESLint plugin for NextJS.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"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": "13.1.7-canary.4",
"version": "13.1.7-canary.6",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
Loading

0 comments on commit 6319ce8

Please sign in to comment.