Skip to content

Commit

Permalink
Merge branch 'canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Dec 17, 2020
2 parents 9425690 + 25cb43a commit 89ba07b
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 62 deletions.
20 changes: 12 additions & 8 deletions docs/api-reference/next/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ export default function Page() {

You can listen to different events happening inside the Next.js Router. Here's a list of supported events:

- `routeChangeStart(url)` - Fires when a route starts to change
- `routeChangeComplete(url)` - Fires when a route changed completely
- `routeChangeError(err, url)` - Fires when there's an error when changing routes, or a route load is cancelled
- `routeChangeStart(url, { shallow })` - Fires when a route starts to change
- `routeChangeComplete(url, { shallow })` - Fires when a route changed completely
- `routeChangeError(err, url, { shallow })` - Fires when there's an error when changing routes, or a route load is cancelled
- `err.cancelled` - Indicates if the navigation was cancelled
- `beforeHistoryChange(url)` - Fires just before changing the browser's history
- `hashChangeStart(url)` - Fires when the hash will change but not the page
- `hashChangeComplete(url)` - Fires when the hash has changed but not the page
- `beforeHistoryChange(url, { shallow })` - Fires just before changing the browser's history
- `hashChangeStart(url, { shallow })` - Fires when the hash will change but not the page
- `hashChangeComplete(url, { shallow })` - Fires when the hash has changed but not the page

> **Note:** Here `url` is the URL shown in the browser, including the [`basePath`](/docs/api-reference/next.config.js/basepath.md).
Expand All @@ -332,8 +332,12 @@ export default function MyApp({ Component, pageProps }) {
const router = useRouter()

useEffect(() => {
const handleRouteChange = (url) => {
console.log('App is changing to: ', url)
const handleRouteChange = (url, { shallow }) => {
console.log(
`App is changing to ${url} ${
shallow ? 'with' : 'without'
} shallow routing`
)
}

router.events.on('routeChangeStart', handleRouteChange)
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.0.4-canary.6"
"version": "10.0.4-canary.7"
}
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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/http-proxy/index.js

Large diffs are not rendered by default.

51 changes: 35 additions & 16 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import resolveRewrites from './utils/resolve-rewrites'
import { getRouteMatcher } from './utils/route-matcher'
import { getRouteRegex } from './utils/route-regex'

interface RouteProperties {
shallow: boolean
}

interface TransitionOptions {
shallow?: boolean
locale?: string | false
Expand Down Expand Up @@ -652,8 +656,11 @@ export default class Router implements BaseRouter {
performance.mark('routeChange')
}

const { shallow = false } = options
const routeProps = { shallow }

if (this._inFlightRoute) {
this.abortComponentLoad(this._inFlightRoute)
this.abortComponentLoad(this._inFlightRoute, routeProps)
}

as = addBasePath(
Expand All @@ -677,12 +684,12 @@ export default class Router implements BaseRouter {
// any time without notice.
if (!(options as any)._h && this.onlyAHashChange(cleanedAs)) {
this.asPath = cleanedAs
Router.events.emit('hashChangeStart', as)
Router.events.emit('hashChangeStart', as, routeProps)
// TODO: do we need the resolved href when only a hash change?
this.changeState(method, url, as, options)
this.scrollToHash(cleanedAs)
this.notify(this.components[this.route])
Router.events.emit('hashChangeComplete', as)
Router.events.emit('hashChangeComplete', as, routeProps)
return true
}

Expand Down Expand Up @@ -727,7 +734,6 @@ export default class Router implements BaseRouter {
}

let route = removePathTrailingSlash(pathname)
const { shallow = false } = options

// we need to resolve the as value using rewrites for dynamic SSG
// pages to allow building the data URL correctly
Expand Down Expand Up @@ -827,15 +833,15 @@ export default class Router implements BaseRouter {
}
}

Router.events.emit('routeChangeStart', as)
Router.events.emit('routeChangeStart', as, routeProps)

try {
const routeInfo = await this.getRouteInfo(
route,
pathname,
query,
as,
shallow
routeProps
)
let { error, props, __N_SSG, __N_SSP } = routeInfo

Expand Down Expand Up @@ -869,7 +875,7 @@ export default class Router implements BaseRouter {
return new Promise(() => {})
}

Router.events.emit('beforeHistoryChange', as)
Router.events.emit('beforeHistoryChange', as, routeProps)
this.changeState(method, url, as, options)

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -887,7 +893,7 @@ export default class Router implements BaseRouter {
)

if (error) {
Router.events.emit('routeChangeError', error, cleanedAs)
Router.events.emit('routeChangeError', error, cleanedAs, routeProps)
throw error
}

Expand All @@ -902,7 +908,7 @@ export default class Router implements BaseRouter {
document.documentElement.lang = this.locale
}
}
Router.events.emit('routeChangeComplete', as)
Router.events.emit('routeChangeComplete', as, routeProps)

return true
} catch (err) {
Expand Down Expand Up @@ -954,6 +960,7 @@ export default class Router implements BaseRouter {
pathname: string,
query: ParsedUrlQuery,
as: string,
routeProps: RouteProperties,
loadErrorFail?: boolean
): Promise<CompletePrivateRouteInfo> {
if (err.cancelled) {
Expand All @@ -962,7 +969,7 @@ export default class Router implements BaseRouter {
}

if (isAssetError(err) || loadErrorFail) {
Router.events.emit('routeChangeError', err, as)
Router.events.emit('routeChangeError', err, as, routeProps)

// If we can't load the page it could be one of following reasons
// 1. Page doesn't exists
Expand Down Expand Up @@ -1034,7 +1041,14 @@ export default class Router implements BaseRouter {

return routeInfo
} catch (routeInfoErr) {
return this.handleRouteInfoError(routeInfoErr, pathname, query, as, true)
return this.handleRouteInfoError(
routeInfoErr,
pathname,
query,
as,
routeProps,
true
)
}
}

Expand All @@ -1043,13 +1057,13 @@ export default class Router implements BaseRouter {
pathname: string,
query: any,
as: string,
shallow: boolean = false
routeProps: RouteProperties
): Promise<PrivateRouteInfo> {
try {
const existingRouteInfo: PrivateRouteInfo | undefined = this.components[
route
]
if (shallow && existingRouteInfo && this.route === route) {
if (routeProps.shallow && existingRouteInfo && this.route === route) {
return existingRouteInfo
}

Expand Down Expand Up @@ -1108,7 +1122,7 @@ export default class Router implements BaseRouter {
this.components[route] = routeInfo
return routeInfo
} catch (err) {
return this.handleRouteInfoError(err, pathname, query, as)
return this.handleRouteInfoError(err, pathname, query, as, routeProps)
}
}

Expand Down Expand Up @@ -1351,9 +1365,14 @@ export default class Router implements BaseRouter {
})
}

abortComponentLoad(as: string): void {
abortComponentLoad(as: string, routeProps: RouteProperties): void {
if (this.clc) {
Router.events.emit('routeChangeError', buildCancellationError(), as)
Router.events.emit(
'routeChangeError',
buildCancellationError(),
as,
routeProps
)
this.clc()
this.clc = null
}
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "10.0.4-canary.6",
"version": "10.0.4-canary.7",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -63,10 +63,10 @@
"@ampproject/toolbox-optimizer": "2.7.1-alpha.0",
"@babel/runtime": "7.12.5",
"@hapi/accept": "5.0.1",
"@next/env": "10.0.4-canary.6",
"@next/polyfill-module": "10.0.4-canary.6",
"@next/react-dev-overlay": "10.0.4-canary.6",
"@next/react-refresh-utils": "10.0.4-canary.6",
"@next/env": "10.0.4-canary.7",
"@next/polyfill-module": "10.0.4-canary.7",
"@next/react-dev-overlay": "10.0.4-canary.7",
"@next/react-refresh-utils": "10.0.4-canary.7",
"ast-types": "0.13.2",
"babel-plugin-transform-define": "2.0.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
Expand Down Expand Up @@ -129,7 +129,7 @@
"@babel/preset-react": "7.12.5",
"@babel/preset-typescript": "7.12.1",
"@babel/types": "7.12.6",
"@next/polyfill-nomodule": "10.0.4-canary.6",
"@next/polyfill-nomodule": "10.0.4-canary.7",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
"@taskr/watch": "1.1.0",
Expand Down Expand Up @@ -189,7 +189,7 @@
"find-up": "4.1.0",
"fresh": "0.5.2",
"gzip-size": "5.1.1",
"http-proxy": "1.18.0",
"http-proxy": "1.18.1",
"ignore-loader": "0.1.2",
"is-docker": "2.0.0",
"is-wsl": "2.2.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.0.4-canary.6",
"version": "10.0.4-canary.7",
"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.0.4-canary.6",
"version": "10.0.4-canary.7",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/basepath/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function useLoggedEvent(event, serializeArgs = (...args) => args) {
}, [event, router.events, serializeArgs])
}

function serializeErrorEventArgs(err, url) {
return [err.message, err.cancelled, url]
function serializeErrorEventArgs(err, url, properties) {
return [err.message, err.cancelled, url, properties]
}

export default function MyApp({ Component, pageProps }) {
Expand Down

0 comments on commit 89ba07b

Please sign in to comment.