Skip to content

Commit

Permalink
Merge branch 'canary' into with-tailwincss
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jan 17, 2020
2 parents 603414b + 15cffd0 commit 539633d
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/with-sitemap-and-robots-express-server/README.md
Expand Up @@ -22,7 +22,7 @@ yarn create next-app --example with-sitemap-and-robots-express-server with-sitem
Download the example:

```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-sitemap-and-robots-expres-server
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-sitemap-and-robots-express-server
cd with-sitemap-and-robots-express-server
```

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.1-canary.0"
"version": "9.2.1-canary.2"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"nextjs": {
"name": "Material UI",
"required-env": []
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
11 changes: 10 additions & 1 deletion packages/next/build/entries.ts
Expand Up @@ -115,10 +115,19 @@ export function createEntrypoints(
}

if (!isApiRoute) {
client[bundlePath] = `next-client-pages-loader?${stringify({
const pageLoader = `next-client-pages-loader?${stringify({
page,
absolutePagePath,
})}!`

// Make sure next/router is a dependency of _app or else granularChunks
// might cause the router to not be able to load causing hydration
// to fail

client[bundlePath] =
page === '/_app'
? [pageLoader, require.resolve('../client/router')]
: pageLoader
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.2.1-canary.0",
"version": "9.2.1-canary.2",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down
1 change: 0 additions & 1 deletion packages/next/pages/_app.tsx
Expand Up @@ -7,7 +7,6 @@ import {
AppPropsType,
} from '../next-server/lib/utils'
import { Router } from '../client/router'
import '../client/router'

export { AppInitialProps }

Expand Down
12 changes: 6 additions & 6 deletions packages/next/pages/_document.tsx
Expand Up @@ -570,7 +570,7 @@ export class NextScript extends Component<OriginProps> {

return (
<script
defer
async
key={bundle.file}
src={`${assetPrefix}/_next/${encodeURI(
bundle.file
Expand Down Expand Up @@ -611,7 +611,7 @@ export class NextScript extends Component<OriginProps> {
file
)}${_devOnlyInvalidateCacheQueryString}`}
nonce={this.props.nonce}
defer
async
crossOrigin={this.props.crossOrigin || process.crossOrigin}
{...modernProps}
/>
Expand Down Expand Up @@ -720,7 +720,7 @@ export class NextScript extends Component<OriginProps> {

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

const appScript = [
<script
defer
async
data-next-page="/_app"
src={
assetPrefix +
Expand All @@ -767,7 +767,7 @@ export class NextScript extends Component<OriginProps> {
/>,
process.env.__NEXT_MODERN_BUILD && (
<script
defer
async
data-next-page="/_app"
src={
assetPrefix +
Expand Down
1 change: 1 addition & 0 deletions test/integration/hydration/pages/_app.js
@@ -0,0 +1 @@
export default ({ Component, pageProps }) => <Component {...pageProps} />
16 changes: 16 additions & 0 deletions test/integration/hydration/pages/_document.js
@@ -0,0 +1,16 @@
import Document, { Head, Html, Main, NextScript } from 'next/document'
import React from 'react'

class WeddingDocument extends Document {
render() {
return (
<Html lang="en-GB">
<Head />
<Main />
<NextScript />
</Html>
)
}
}

export default WeddingDocument
6 changes: 6 additions & 0 deletions test/integration/hydration/pages/details.js
@@ -0,0 +1,6 @@
export default () => {
if (typeof window !== 'undefined') {
window.didHydrate = true
}
return 'details'
}
6 changes: 6 additions & 0 deletions test/integration/hydration/pages/index.js
@@ -0,0 +1,6 @@
export default () => {
if (typeof window !== 'undefined') {
window.didHydrate = true
}
return 'index'
}
33 changes: 33 additions & 0 deletions test/integration/hydration/test/index.test.js
@@ -0,0 +1,33 @@
/* eslint-env jest */
/* global jasmine */
import path from 'path'
import fs from 'fs-extra'
import webdriver from 'next-webdriver'
import {
nextBuild,
nextStart,
findPort,
waitFor,
killApp,
} from 'next-test-utils'

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

describe('Hydration', () => {
beforeAll(async () => {
await fs.remove(path.join(appDir, '.next'))
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))

it('Hydrates correctly', async () => {
const browser = await webdriver(appPort, '/')
await waitFor(2000)
expect(await browser.eval('window.didHydrate')).toBe(true)
})
})
6 changes: 3 additions & 3 deletions test/integration/production/test/index.test.js
Expand Up @@ -678,21 +678,21 @@ describe('Production Usage', () => {
}
})

it('should have defer on all script tags', async () => {
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
// application/json doesn't need async
if (
script.attribs.type === 'application/json' ||
script.attribs.src.includes('polyfills')
) {
continue
}

if (script.attribs.async === '' || script.attribs.defer !== '') {
if (script.attribs.defer === '' || script.attribs.async !== '') {
missing = true
}
}
Expand Down

0 comments on commit 539633d

Please sign in to comment.