Skip to content

Commit

Permalink
Merge branch 'canary' into remove-concurrency-from-next-export
Browse files Browse the repository at this point in the history
  • Loading branch information
ctavan committed Oct 27, 2019
2 parents 10ceab7 + 1c11ffd commit 3a53c79
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ commands:
- run:
name: Installing Dependencies
command: yarn install --frozen-lockfile --check-files
- run:
name: Install correct Chrome Driver version
command: yarn add chromedriver@76 -W
- run: google-chrome --version
- run: chromedriver --version
yarn_lint:
steps:
- run:
Expand Down
4 changes: 4 additions & 0 deletions examples/with-react-native-web/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['next/babel'],
plugins: [['react-native-web', { commonjs: true }]]
}
3 changes: 2 additions & 1 deletion examples/with-react-native-web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
webpack: config => {
webpack: (config, { defaultLoaders }) => {
config.resolve.alias = {
...(config.resolve.alias || {}),
// Transform all direct `react-native` imports to `react-native-web`
'react-native$': 'react-native-web'
}
config.resolve.extensions.push('.web.js', '.web.ts', '.web.tsx')
return config
}
}
3 changes: 3 additions & 0 deletions examples/with-react-native-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-native-web": "^0.11.6"
},
"devDependencies": {
"babel-plugin-react-native-web": "^0.11.7"
}
}
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.1.2-canary.8"
"version": "9.1.2-canary.9"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"babel-jest": "24.8.0",
"browserstack-local": "1.4.0",
"cheerio": "0.22.0",
"chromedriver": "75.1.0",
"chromedriver": "76.0.1",
"clone": "2.1.2",
"coveralls": "3.0.3",
"cross-spawn": "6.0.5",
Expand Down
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.1.2-canary.8",
"version": "9.1.2-canary.9",
"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.1.2-canary.8",
"version": "9.1.2-canary.9",
"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.1.2-canary.8",
"version": "9.1.2-canary.9",
"main": "index.js",
"license": "MIT",
"repository": {
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 @@ -724,6 +724,9 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
config.exportTrailingSlash
),
'process.env.__NEXT_DEFER_SCRIPTS': JSON.stringify(
config.experimental.deferScripts
),
'process.env.__NEXT_MODERN_BUILD': JSON.stringify(
config.experimental.modern && !dev
),
Expand Down
10 changes: 9 additions & 1 deletion packages/next/next-server/server/api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ export function getQueryParser({ url }: IncomingMessage) {

const query: { [key: string]: string | string[] } = {}
for (const [key, value] of params) {
query[key] = value
if (query[key]) {
if (Array.isArray(query[key])) {
;(query[key] as string[]).push(value)
} else {
query[key] = [query[key], value]
}
} else {
query[key] = value
}
}

return query
Expand Down
1 change: 1 addition & 0 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const defaultConfig: { [key: string]: any } = {
profiling: false,
publicDirectory: false,
sprFlushToDisk: true,
deferScripts: false,
},
future: {
excludeDefaultMomentLocales: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.1.2-canary.8",
"version": "9.1.2-canary.9",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down
19 changes: 13 additions & 6 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ export class NextScript extends Component<OriginProps> {

return (
<script
async
defer={process.env.__NEXT_DEFER_SCRIPTS as any}
async={!process.env.__NEXT_DEFER_SCRIPTS as any}
key={bundle.file}
src={`${assetPrefix}/_next/${encodeURI(
bundle.file
Expand Down Expand Up @@ -561,7 +562,8 @@ export class NextScript extends Component<OriginProps> {
file
)}${_devOnlyInvalidateCacheQueryString}`}
nonce={this.props.nonce}
async
defer={process.env.__NEXT_DEFER_SCRIPTS as any}
async={!process.env.__NEXT_DEFER_SCRIPTS as any}
crossOrigin={this.props.crossOrigin || process.crossOrigin}
{...modernProps}
/>
Expand Down Expand Up @@ -594,6 +596,7 @@ export class NextScript extends Component<OriginProps> {
devFiles,
__NEXT_DATA__,
} = this.context._documentProps
const deferScripts: any = process.env.__NEXT_DEFER_SCRIPTS
const { _devOnlyInvalidateCacheQueryString } = this.context

if (inAmpMode) {
Expand Down Expand Up @@ -648,7 +651,8 @@ export class NextScript extends Component<OriginProps> {

const pageScript = [
<script
async
defer={deferScripts}
async={!deferScripts}
data-next-page={page}
key={page}
src={
Expand All @@ -662,7 +666,8 @@ export class NextScript extends Component<OriginProps> {
/>,
process.env.__NEXT_MODERN_BUILD && (
<script
async
defer={deferScripts}
async={!deferScripts}
data-next-page={page}
key={`${page}-modern`}
src={
Expand All @@ -681,7 +686,8 @@ export class NextScript extends Component<OriginProps> {

const appScript = [
<script
async
defer={deferScripts}
async={!deferScripts}
data-next-page="/_app"
src={
assetPrefix +
Expand All @@ -695,7 +701,8 @@ export class NextScript extends Component<OriginProps> {
/>,
process.env.__NEXT_MODERN_BUILD && (
<script
async
defer={deferScripts}
async={!deferScripts}
data-next-page="/_app"
src={
assetPrefix +
Expand Down
3 changes: 3 additions & 0 deletions test/integration/api-support/pages/api/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default (req, res) => {
res.status(200).send(req.query)
}
17 changes: 17 additions & 0 deletions test/integration/api-support/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ function runTests (serverless = false) {
expect(data).toEqual({ message: 'Parsed body' })
})

it('should return empty query object', async () => {
const data = await fetchViaHTTP(appPort, '/api/query', null, {}).then(
res => res.ok && res.json()
)
expect(data).toEqual({})
})

it('should parse query correctly', async () => {
const data = await fetchViaHTTP(
appPort,
'/api/query?a=1&b=2&a=3',
null,
{}
).then(res => res.ok && res.json())
expect(data).toEqual({ a: ['1', '3'], b: '2' })
})

it('should return empty cookies object', async () => {
const data = await fetchViaHTTP(appPort, '/api/cookies', null, {}).then(
res => res.ok && res.json()
Expand Down
9 changes: 9 additions & 0 deletions test/integration/defer-scripts/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60
},
experimental: {
deferScripts: true
}
}
1 change: 1 addition & 0 deletions test/integration/defer-scripts/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <h1>Hello World</h1>
53 changes: 53 additions & 0 deletions test/integration/defer-scripts/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import {
nextServer,
runNextCommand,
startApp,
stopApp,
renderViaHTTP
} from 'next-test-utils'
import cheerio from 'cheerio'
const appDir = join(__dirname, '../')
let appPort
let server
let app
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5

const context = {}

describe('Defer Scripts', () => {
beforeAll(async () => {
await runNextCommand(['build', appDir])

app = nextServer({
dir: join(__dirname, '../'),
dev: false,
quiet: true
})

server = await startApp(app)
context.appPort = appPort = server.address().port
})
afterAll(() => stopApp(server))

it('should have defer on all script tags', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
let missing = false

for (const script of $('script').toArray()) {
const { defer, type } = script.attribs
// application/json doesn't need defer
if (type === 'application/json') {
continue
}

if (defer !== '') {
missing = true
}
}
expect(missing).toBe(false)
})
})
18 changes: 18 additions & 0 deletions test/integration/production/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,24 @@ describe('Production Usage', () => {
}
})

it('should have async on all script tags', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
let missing = false

for (const script of $('script').toArray()) {
// application/json doesn't need defer
if (script.attribs.type === 'application/json') {
continue
}

if (script.attribs.async !== '') {
missing = true
}
}
expect(missing).toBe(false)
})

dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))

processEnv(context)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4174,10 +4174,10 @@ chrome-trace-event@^1.0.2:
dependencies:
tslib "^1.9.0"

chromedriver@75.1.0:
version "75.1.0"
resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-75.1.0.tgz#edfef5d7a9b16b6f8a12ddb58cbac76ae52732fd"
integrity sha512-N2P0fg6FS4c+tTG0R7cCOD5qiVo+E6uAz6xVjmbZesYv1xs1iGdcCUo0IqOY+ppD/4OOObG+XWV1CFWXT6UIgA==
chromedriver@76.0.1:
version "76.0.1"
resolved "https://registry.yarnpkg.com/chromedriver/-/chromedriver-76.0.1.tgz#65283299c3b34b1212eef272c32bd826c6bdebd3"
integrity sha512-+8BCemJLKPF2w/UpzA1uNgLWQrg1IgIO4ZYcsAjYYgqD8zUcvQ+RfwA/0TR1Zwv9Mkd8fdzTe21eZ2FyZ83DAg==
dependencies:
del "^4.1.1"
extract-zip "^1.6.7"
Expand Down

0 comments on commit 3a53c79

Please sign in to comment.