Skip to content

Commit

Permalink
Merge branch 'canary' into docs/out-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jun 27, 2020
2 parents a2a2fb0 + bd24b70 commit 395ab22
Show file tree
Hide file tree
Showing 32 changed files with 469 additions and 442 deletions.
18 changes: 18 additions & 0 deletions errors/rewrite-auto-export-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Rewriting to Auto Export or Fallback Dynamic Route

#### Why This Error Occurred

One of your rewrites in your `next.config.js` point to a [dynamic route](https://nextjs.org/docs/routing/dynamic-routes) that is automatically statically optimized or is a [fallback SSG page](https://nextjs.org/docs/basic-features/data-fetching#the-fallback-key-required).

Rewriting to these pages are not yet supported since rewrites are not available client-side and the dynamic route params are unable to be parsed. Support for this may be added in a future release.

#### Possible Ways to Fix It

For fallback SSG pages you can add the page to the list of [prerendered paths](https://nextjs.org/docs/basic-features/data-fetching#the-paths-key-required).

For static dynamic routes, you will currently need to either rewrite to non-dynamic route or opt the page out of the static optimization with [`getServerSideProps`](https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering)

### Useful Links

- [Dynamic Routes Documentation](https://nextjs.org/docs/routing/dynamic-routes)
- [Fallback Documentation](https://nextjs.org/docs/basic-features/data-fetching#the-fallback-key-required)
28 changes: 12 additions & 16 deletions errors/routes-must-be-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ Make sure to return an array that contains the routes.
```js
// next.config.js
module.exports = {
experimental: {
async rewrites() {
return {
source: '/feedback',
destination: '/feedback/general',
}
},
async rewrites() {
return {
source: '/feedback',
destination: '/feedback/general',
}
},
}
```
Expand All @@ -28,15 +26,13 @@ module.exports = {

```js
module.exports = {
experimental: {
async rewrites() {
return [
{
source: '/feedback',
destination: '/feedback/general',
},
]
},
async rewrites() {
return [
{
source: '/feedback',
destination: '/feedback/general',
},
]
},
}
```
28 changes: 13 additions & 15 deletions examples/custom-routes-proxying/next.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module.exports = {
experimental: {
async rewrites() {
return [
// we need to define a no-op rewrite to trigger checking
// all pages/static files before we attempt proxying
{
source: '/:path*',
destination: '/:path*',
},
{
source: '/:path*',
destination: `https://custom-routes-proxying-endpoint.vercel.app/:path*`,
},
]
},
async rewrites() {
return [
// we need to define a no-op rewrite to trigger checking
// all pages/static files before we attempt proxying
{
source: '/:path*',
destination: '/:path*',
},
{
source: '/:path*',
destination: `https://custom-routes-proxying-endpoint.vercel.app/:path*`,
},
]
},
}
16 changes: 7 additions & 9 deletions examples/with-next-offline/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ module.exports = withOffline({
},
],
},
experimental: {
async rewrites() {
return [
{
source: '/service-worker.js',
destination: '/_next/static/service-worker.js',
},
]
},
async rewrites() {
return [
{
source: '/service-worker.js',
destination: '/_next/static/service-worker.js',
},
]
},
})
2 changes: 1 addition & 1 deletion examples/with-tailwindcss/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
purge: ['./components/**/*.js', './pages/**/*.js'],
purge: ['./components/**/*.{js,ts,jsx,tsx}', './pages/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
Expand Down
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.4.5-canary.20"
"version": "9.4.5-canary.21"
}
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.4.5-canary.20",
"version": "9.4.5-canary.21",
"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.4.5-canary.20",
"version": "9.4.5-canary.21",
"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.4.5-canary.20",
"version": "9.4.5-canary.21",
"main": "index.js",
"license": "MIT",
"repository": {
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.4.5-canary.20",
"version": "9.4.5-canary.21",
"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.4.5-canary.20",
"version": "9.4.5-canary.21",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-google-analytics"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.4.5-canary.20",
"version": "9.4.5-canary.21",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-material-ui"
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.4.5-canary.20",
"version": "9.4.5-canary.21",
"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.4.5-canary.20",
"version": "9.4.5-canary.21",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
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.4.5-canary.20",
"version": "9.4.5-canary.21",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { findPageFile } from '../server/lib/find-page-file'
import { GetStaticPaths } from 'next/types'
import { denormalizePagePath } from '../next-server/server/normalize-page-path'
import { BuildManifest } from '../next-server/server/get-page-files'
import { normalizeTrailingSlash } from '../next-server/lib/router/normalize-trailing-slash'

const fileGzipStats: { [k: string]: Promise<number> } = {}
const fsStatGzip = (file: string) => {
Expand Down Expand Up @@ -573,6 +574,7 @@ export async function buildStaticPaths(
// For a string-provided path, we must make sure it matches the dynamic
// route.
if (typeof entry === 'string') {
entry = normalizeTrailingSlash(entry)
const result = _routeMatcher(entry)
if (!result) {
throw new Error(
Expand Down
12 changes: 6 additions & 6 deletions packages/next/lib/load-custom-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,28 +310,28 @@ export interface CustomRoutes {
}

async function loadRedirects(config: any) {
if (typeof config.experimental.redirects !== 'function') {
if (typeof config.redirects !== 'function') {
return []
}
const _redirects = await config.experimental.redirects()
const _redirects = await config.redirects()
checkCustomRoutes(_redirects, 'redirect')
return _redirects
}

async function loadRewrites(config: any) {
if (typeof config.experimental.rewrites !== 'function') {
if (typeof config.rewrites !== 'function') {
return []
}
const _rewrites = await config.experimental.rewrites()
const _rewrites = await config.rewrites()
checkCustomRoutes(_rewrites, 'rewrite')
return _rewrites
}

async function loadHeaders(config: any) {
if (typeof config.experimental.headers !== 'function') {
if (typeof config.headers !== 'function') {
return []
}
const _headers = await config.experimental.headers()
const _headers = await config.headers()
checkCustomRoutes(_headers, 'header')
return _headers
}
Expand Down
11 changes: 5 additions & 6 deletions packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,14 @@ export async function renderToHTML(
pageIsDynamic &&
didRewrite
) {
// TODO: add err.sh when rewrites go stable
// Behavior might change before then (prefer SSR in this case).
// If we decide to ship rewrites to the client we could solve this
// by running over the rewrites and getting the params.
// TODO: If we decide to ship rewrites to the client we could
// solve this by running over the rewrites and getting the params.
throw new Error(
`Rewrites don't support${
isFallback ? ' ' : ' auto-exported '
}dynamic pages${isFallback ? ' with getStaticProps ' : ' '}yet. ` +
`Using this will cause the page to fail to parse the params on the client`
}dynamic pages${isFallback ? ' with getStaticProps ' : ' '}yet.\n` +
`Using this will cause the page to fail to parse the params on the client\n` +
`See more info: https://err.sh/next.js/rewrite-auto-export-fallback`
)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.4.5-canary.20",
"version": "9.4.5-canary.21",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -76,8 +76,8 @@
"@babel/preset-typescript": "7.9.0",
"@babel/runtime": "7.9.6",
"@babel/types": "7.9.6",
"@next/react-dev-overlay": "9.4.5-canary.20",
"@next/react-refresh-utils": "9.4.5-canary.20",
"@next/react-dev-overlay": "9.4.5-canary.21",
"@next/react-refresh-utils": "9.4.5-canary.21",
"babel-plugin-syntax-jsx": "6.18.0",
"babel-plugin-transform-define": "2.0.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
Expand Down Expand Up @@ -114,7 +114,7 @@
"react-dom": "^16.6.0"
},
"devDependencies": {
"@next/polyfill-nomodule": "9.4.5-canary.20",
"@next/polyfill-nomodule": "9.4.5-canary.21",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
"@taskr/watch": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "9.4.5-canary.20",
"version": "9.4.5-canary.21",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "9.4.5-canary.20",
"version": "9.4.5-canary.21",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
16 changes: 7 additions & 9 deletions test/integration/custom-routes-catchall/next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module.exports = {
experimental: {
rewrites() {
return [
{
source: '/docs/:path*',
destination: '/:path*',
},
]
},
rewrites() {
return [
{
source: '/docs/:path*',
destination: '/:path*',
},
]
},
}
10 changes: 5 additions & 5 deletions test/integration/custom-routes-catchall/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ let appPort
let app

const runTests = () => {
it('should rewrite and render page correctly', async () => {
const html = await renderViaHTTP(appPort, '/docs/hello')
expect(html).toMatch(/hello world/)
})

it('should rewrite to /_next/static correctly', async () => {
const bundlePath = await join(
'/docs/_next/static/',
Expand All @@ -29,11 +34,6 @@ const runTests = () => {
expect(data).toContain('/hello')
})

it('should rewrite and render page correctly', async () => {
const html = await renderViaHTTP(appPort, '/docs/hello')
expect(html).toMatch(/hello world/)
})

it('should rewrite to public/static correctly', async () => {
const data = await renderViaHTTP(appPort, '/docs/static/data.json')
expect(data).toContain('some data...')
Expand Down
Loading

0 comments on commit 395ab22

Please sign in to comment.