Skip to content

Commit

Permalink
Merge branch 'canary' into render-callback-context
Browse files Browse the repository at this point in the history
  • Loading branch information
devknoll committed Apr 16, 2021
2 parents 0428ec2 + fe0583e commit 1a49aa2
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 63 deletions.
1 change: 1 addition & 0 deletions docs/advanced-features/custom-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The `Component` prop is the active `page`, so whenever you navigate between rout

- If your app is running and you just added a custom `App`, you'll need to restart the development server. Only required if `pages/_app.js` didn't exist before.
- Adding a custom `getInitialProps` in your `App` will disable [Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization.md) in pages without [Static Generation](/docs/basic-features/data-fetching.md#getstaticprops-static-generation).
- When you add `getInitialProps` in your custom app, you must `import App from "next/app"`, call `App.getInitialProps(appContext)` inside `getInitialProps` and merge the returned object into the return value.
- `App` currently does not support Next.js [Data Fetching methods](/docs/basic-features/data-fetching.md) like [`getStaticProps`](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) or [`getServerSideProps`](/docs/basic-features/data-fetching.md#getserversideprops-server-side-rendering).

### TypeScript
Expand Down
20 changes: 9 additions & 11 deletions examples/with-typescript-graphql/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Link from 'next/link'
import { useState } from 'react'
import {
ViewerQuery,
useViewerQuery,
useUpdateNameMutation,
ViewerDocument,
Expand All @@ -19,21 +20,18 @@ const Index = () => {
},
//Follow apollo suggestion to update cache
//https://www.apollographql.com/docs/angular/features/cache-updates/#update
update: (
store,
{
data: {
updateName: { name },
},
}
) => {
update: (cache, mutationResult) => {
const { data } = mutationResult
if (!data) return // Cancel updating name in cache if no data is returned from mutation.
// Read the data from our cache for this query.
const { viewer } = store.readQuery({ query: ViewerDocument })
const { viewer } = cache.readQuery({
query: ViewerDocument,
}) as ViewerQuery
const newViewer = { ...viewer }
// Add our comment from the mutation to the end.
newViewer.name = name
newViewer.name = data.updateName.name
// Write our data back to the cache.
store.writeQuery({ query: ViewerDocument, data: { viewer: newViewer } })
cache.writeQuery({ query: ViewerDocument, data: { viewer: newViewer } })
},
})
}
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": "10.1.4-canary.8"
"version": "10.1.4-canary.9"
}
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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"main": "index.js",
"license": "MIT",
"repository": {
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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-google-analytics"
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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
38 changes: 33 additions & 5 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,11 @@ export default class Server {
parsedUrl.query.__nextLocale = localePathResult.detectedLocale
}
}
const bubbleNoFallback = !!query._nextBubbleNoFallback

if (pathname === '/api' || pathname.startsWith('/api/')) {
delete query._nextBubbleNoFallback

const handled = await this.handleApiRequest(
req as NextApiRequest,
res as NextApiResponse,
Expand All @@ -1010,9 +1013,19 @@ export default class Server {
}
}

await this.render(req, res, pathname, query, parsedUrl)
return {
finished: true,
try {
await this.render(req, res, pathname, query, parsedUrl)

return {
finished: true,
}
} catch (err) {
if (err instanceof NoFallbackError && bubbleNoFallback) {
return {
finished: false,
}
}
throw err
}
},
}
Expand Down Expand Up @@ -1861,6 +1874,9 @@ export default class Server {
pathname: string,
query: ParsedUrlQuery = {}
): Promise<string | null> {
const bubbleNoFallback = !!query._nextBubbleNoFallback
delete query._nextBubbleNoFallback

try {
const result = await this.findPageComponents(pathname, query)
if (result) {
Expand All @@ -1873,7 +1889,9 @@ export default class Server {
{ ...this.renderOpts }
)
} catch (err) {
if (!(err instanceof NoFallbackError)) {
const isNoFallbackError = err instanceof NoFallbackError

if (!isNoFallbackError || (isNoFallbackError && bubbleNoFallback)) {
throw err
}
}
Expand Down Expand Up @@ -1901,14 +1919,24 @@ export default class Server {
{ ...this.renderOpts, params }
)
} catch (err) {
if (!(err instanceof NoFallbackError)) {
const isNoFallbackError = err instanceof NoFallbackError

if (
!isNoFallbackError ||
(isNoFallbackError && bubbleNoFallback)
) {
throw err
}
}
}
}
}
} catch (err) {
const isNoFallbackError = err instanceof NoFallbackError

if (isNoFallbackError && bubbleNoFallback) {
throw err
}
if (err && err.code === 'DECODE_FAILED') {
this.logError(err)
res.statusCode = 400
Expand Down
8 changes: 4 additions & 4 deletions packages/next/next-server/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ export default class Router {

// Matched a page or dynamic route so render it using catchAllRoute
if (matchedPage) {
checkParsedUrl.pathname = fsPathname

const pageParams = this.catchAllRoute.match(checkParsedUrl.pathname)
checkParsedUrl.pathname = fsPathname
checkParsedUrl.query._nextBubbleNoFallback = '1'

await this.catchAllRoute.fn(
const result = await this.catchAllRoute.fn(
req,
res,
pageParams as Params,
checkParsedUrl
)
return true
return result.finished
}
}

Expand Down
12 changes: 6 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -62,10 +62,10 @@
"dependencies": {
"@babel/runtime": "7.12.5",
"@hapi/accept": "5.0.1",
"@next/env": "10.1.4-canary.8",
"@next/polyfill-module": "10.1.4-canary.8",
"@next/react-dev-overlay": "10.1.4-canary.8",
"@next/react-refresh-utils": "10.1.4-canary.8",
"@next/env": "10.1.4-canary.9",
"@next/polyfill-module": "10.1.4-canary.9",
"@next/react-dev-overlay": "10.1.4-canary.9",
"@next/react-refresh-utils": "10.1.4-canary.9",
"@opentelemetry/api": "0.14.0",
"assert": "2.0.0",
"ast-types": "0.13.2",
Expand Down Expand Up @@ -148,7 +148,7 @@
"@babel/preset-typescript": "7.12.7",
"@babel/traverse": "^7.12.10",
"@babel/types": "7.12.12",
"@next/polyfill-nomodule": "10.1.4-canary.8",
"@next/polyfill-nomodule": "10.1.4-canary.9",
"@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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"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": "10.1.4-canary.8",
"version": "10.1.4-canary.9",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
30 changes: 7 additions & 23 deletions test/integration/create-next-app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import path from 'path'

const cli = require.resolve('create-next-app/dist/index.js')

const exampleRepo = 'https://github.com/vercel/next-learn-starter/tree/master'
const examplePath = 'navigate-between-pages-starter'

jest.setTimeout(1000 * 60 * 5)

const run = (args, options) => execa('node', [cli].concat(args), options)
Expand Down Expand Up @@ -92,11 +95,7 @@ describe('create next app', () => {
await usingTempDir(async (cwd) => {
const projectName = 'github-app'
const res = await run(
[
projectName,
'--example',
'https://github.com/zeit/next-learn-demo/tree/master/1-navigate-between-pages',
],
[projectName, '--example', `${exampleRepo}/${examplePath}`],
{
cwd,
}
Expand All @@ -109,9 +108,6 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/about.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
Expand All @@ -122,13 +118,7 @@ describe('create next app', () => {
await usingTempDir(async (cwd) => {
const projectName = 'github-example-path'
const res = await run(
[
projectName,
'--example',
'https://github.com/zeit/next-learn-demo/tree/master',
'--example-path',
'1-navigate-between-pages',
],
[projectName, '--example', exampleRepo, '--example-path', examplePath],
{
cwd,
}
Expand All @@ -141,9 +131,6 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/about.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
Expand All @@ -157,9 +144,9 @@ describe('create next app', () => {
[
projectName,
'--example',
'https://github.com/zeit/next-learn-demo/tree/master/1-navigate-between-pages',
`${exampleRepo}/${examplePath}`,
'--example-path',
'1-navigate-between-pages',
examplePath,
],
{
cwd,
Expand All @@ -173,9 +160,6 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/about.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
Expand Down
12 changes: 12 additions & 0 deletions test/integration/fallback-false-rewrite/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
rewrites() {
return {
fallback: [
{
source: '/:path*',
destination: '/another',
},
],
}
},
}
Loading

0 comments on commit 1a49aa2

Please sign in to comment.