Skip to content

Commit

Permalink
Merge branch 'canary' into dev/check-getstaticpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 20, 2020
2 parents 487e20d + 16b3a54 commit c32861d
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 77 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ jobs:
runs-on: ubuntu-latest
needs: build
env:
NEXT_TELEMETRY_DISABLED: 1
BROWSERSTACK: true
NEXT_TELEMETRY_DISABLED: 1
SKIP_LOCAL_SELENIUM_SERVER: true
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
Expand All @@ -95,6 +95,25 @@ jobs:
key: ${{ github.sha }}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || yarn testsafari --forceExit test/integration/production/'

testSafariOld:
name: Test Safari 10.1 (nav)
runs-on: ubuntu-latest
needs: [build, testSafari]
env:
BROWSERSTACK: true
LEGACY_SAFARI: true
NEXT_TELEMETRY_DISABLED: 1
SKIP_LOCAL_SELENIUM_SERVER: true
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
steps:
- uses: actions/cache@v1
id: restore-build
with:
path: '.'
key: ${{ github.sha }}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || yarn testsafari --forceExit test/integration/production-nav/'

publishRelease:
name: Potentially publish release
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.3-canary.6"
"version": "9.2.3-canary.8"
}
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.2.3-canary.6",
"version": "9.2.3-canary.8",
"keywords": [
"react",
"next",
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.2.3-canary.6",
"version": "9.2.3-canary.8",
"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.2.3-canary.6",
"version": "9.2.3-canary.8",
"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.2.3-canary.6",
"version": "9.2.3-canary.8",
"nextjs": {
"name": "Google Analytics",
"required-env": [
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.2.3-canary.6",
"version": "9.2.3-canary.8",
"nextjs": {
"name": "Material UI",
"required-env": []
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.2.3-canary.6",
"version": "9.2.3-canary.8",
"nextjs": {
"name": "Sentry",
"required-env": [
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.2.3-canary.6",
"version": "9.2.3-canary.8",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ export default async function getBaseWebpackConfig(
].filter(Boolean),
},
context: dir,
node: {
setImmediate: false,
},
// Kept as function to be backwards compatible
entry: async () => {
return {
Expand Down
111 changes: 59 additions & 52 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,64 @@ export default class Router implements BaseRouter {
return Promise.resolve(cachedRouteInfo)
}

const handleError = (
err: Error & { code: any; cancelled: boolean },
loadErrorFail?: boolean
) => {
return new Promise(resolve => {
if (err.code === 'PAGE_LOAD_ERROR' || loadErrorFail) {
// If we can't load the page it could be one of following reasons
// 1. Page doesn't exists
// 2. Page does exist in a different zone
// 3. Internal error while loading the page

// So, doing a hard reload is the proper way to deal with this.
window.location.href = as

// Changing the URL doesn't block executing the current code path.
// So, we need to mark it as a cancelled error and stop the routing logic.
err.cancelled = true
// @ts-ignore TODO: fix the control flow here
return resolve({ error: err })
}

if (err.cancelled) {
// @ts-ignore TODO: fix the control flow here
return resolve({ error: err })
}

resolve(
this.fetchComponent('/_error')
.then(Component => {
const routeInfo: RouteInfo = { Component, err }
return new Promise(resolve => {
this.getInitialProps(Component, {
err,
pathname,
query,
} as any).then(
props => {
routeInfo.props = props
routeInfo.error = err
resolve(routeInfo)
},
gipErr => {
console.error(
'Error in error page `getInitialProps`: ',
gipErr
)
routeInfo.error = err
routeInfo.props = {}
resolve(routeInfo)
}
)
}) as Promise<RouteInfo>
})
.catch(err => handleError(err, true))
)
}) as Promise<RouteInfo>
}

return (new Promise((resolve, reject) => {
if (cachedRouteInfo) {
return resolve(cachedRouteInfo)
Expand Down Expand Up @@ -542,58 +600,7 @@ export default class Router implements BaseRouter {
return routeInfo
})
})
.catch(err => {
return new Promise(resolve => {
if (err.code === 'PAGE_LOAD_ERROR') {
// If we can't load the page it could be one of following reasons
// 1. Page doesn't exists
// 2. Page does exist in a different zone
// 3. Internal error while loading the page

// So, doing a hard reload is the proper way to deal with this.
window.location.href = as

// Changing the URL doesn't block executing the current code path.
// So, we need to mark it as a cancelled error and stop the routing logic.
err.cancelled = true
// @ts-ignore TODO: fix the control flow here
return resolve({ error: err })
}

if (err.cancelled) {
// @ts-ignore TODO: fix the control flow here
return resolve({ error: err })
}

resolve(
this.fetchComponent('/_error').then(Component => {
const routeInfo: RouteInfo = { Component, err }
return new Promise(resolve => {
this.getInitialProps(Component, {
err,
pathname,
query,
} as any).then(
props => {
routeInfo.props = props
routeInfo.error = err
resolve(routeInfo)
},
gipErr => {
console.error(
'Error in error page `getInitialProps`: ',
gipErr
)
routeInfo.error = err
routeInfo.props = {}
resolve(routeInfo)
}
)
}) as Promise<RouteInfo>
})
)
}) as Promise<RouteInfo>
})
.catch(handleError)
}

set(
Expand Down
4 changes: 2 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.2.3-canary.6",
"version": "9.2.3-canary.8",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -73,7 +73,7 @@
"@babel/preset-typescript": "7.7.2",
"@babel/runtime": "7.7.2",
"@babel/types": "7.7.4",
"@next/polyfill-nomodule": "9.2.3-canary.6",
"@next/polyfill-nomodule": "9.2.3-canary.8",
"amphtml-validator": "1.0.30",
"async-retry": "1.2.3",
"async-sema": "3.0.0",
Expand Down
7 changes: 7 additions & 0 deletions test/integration/error-load-fail/pages/broken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const Page = () => 'oops'

Page.getInitialProps = () => {
throw new Error('oops')
}

export default Page
9 changes: 9 additions & 0 deletions test/integration/error-load-fail/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default () => (
<>
<Link href="/broken">
<a id="to-broken">to oops</a>
</Link>
</>
)
36 changes: 36 additions & 0 deletions test/integration/error-load-fail/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env jest */
/* global jasmine */
import path from 'path'
import webdriver from 'next-webdriver'
import {
nextBuild,
nextStart,
findPort,
killApp,
waitFor,
} from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = path.join(__dirname, '..')

describe('Failing to load _error', () => {
it('handles failing to load _error correctly', async () => {
await nextBuild(appDir)
const appPort = await findPort()
const app = await nextStart(appDir, appPort)

const browser = await webdriver(appPort, '/')
await browser.eval(`window.beforeNavigate = true`)

await browser.elementByCss('#to-broken').moveTo()
await browser.waitForElementByCss('script[src*="broken.js"')

// stop app so that _error can't be loaded
await killApp(app)

await browser.elementByCss('#to-broken').click()
await waitFor(2000)

expect(await browser.eval('window.beforeNavigate')).toBeFalsy()
})
})
9 changes: 9 additions & 0 deletions test/integration/production-nav/pages/another.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default () => (
<>
<Link href="/">
<a id="to-index">Index</a>
</Link>
</>
)
9 changes: 9 additions & 0 deletions test/integration/production-nav/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default () => (
<>
<Link href="/another">
<a id="to-another">Another</a>
</Link>
</>
)
35 changes: 35 additions & 0 deletions test/integration/production-nav/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-env jest */
/* global jasmine */
import { nextBuild, nextStart, killApp, waitFor } from 'next-test-utils'
import getPort from 'get-port'
import webdriver from 'next-webdriver'
import { join } from 'path'

const appDir = join(__dirname, '../')
let appPort
let app
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1

describe('Production Usage', () => {
beforeAll(async () => {
await nextBuild(appDir)
// use compatible port: https://www.browserstack.com/question/664
appPort = await getPort({
port: [8080, 8081, 8888, 8899],
})
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))

it('should navigate forward and back correctly', async () => {
const browser = await webdriver(appPort, '/')
await browser.eval('window.beforeNav = true')
await browser.elementByCss('#to-another').click()
// waitForElement doesn't seem to work properly in safari 10
await waitFor(2000)
expect(await browser.eval('window.beforeNav')).toBe(true)
await browser.elementByCss('#to-index').click()
await waitFor(2000)
expect(await browser.eval('window.beforeNav')).toBe(true)
})
})
2 changes: 1 addition & 1 deletion test/integration/size-limit/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Production response size', () => {
)

// These numbers are without gzip compression!
const delta = responseSizesBytes - 241 * 1024
const delta = responseSizesBytes - 238 * 1024
expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
})
Expand Down
6 changes: 5 additions & 1 deletion test/jest-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class CustomEnvironment extends NodeEnvironment {
this.server.close()
}
if (this.global.wd) {
await this.global.wd.quit()
try {
await this.global.wd.quit()
} catch (err) {
console.log(`Failed to quit webdriver instance`, err)
}
}
// must come after wd.quit()
if (this.seleniumServer) {
Expand Down
Loading

0 comments on commit c32861d

Please sign in to comment.