Skip to content

Commit b1a299e

Browse files
committed
Merge branch 'canary' of github.com:zeit/next.js into add/reliable-page-loading
2 parents 2d8aeee + f85a0bd commit b1a299e

File tree

12 files changed

+183
-32
lines changed

12 files changed

+183
-32
lines changed

build/babel/preset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = (context, opts = {}) => ({
3333
[require('@babel/preset-env').default, {
3434
// In the test environment `modules` is often needed to be set to true, babel figures that out by itself using the `'auto'` option
3535
// In production/development this option is set to `false` so that webpack can handle import/export with tree-shaking
36-
modules: isDevelopment && isProduction ? false : 'auto',
36+
modules: isDevelopment || isProduction ? false : 'auto',
3737
...opts['preset-env']
3838
}],
3939
[require('@babel/preset-react'), {

build/webpack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default async function getBaseWebpackConfig (dir: string, {dev = false, i
113113
const defaultLoaders = {
114114
babel: {
115115
loader: 'next-babel-loader',
116-
options: {dev, isServer}
116+
options: {dev, isServer, cwd: dir}
117117
},
118118
hotSelfAccept: {
119119
loader: 'hot-self-accept-loader',

examples/with-webpack-bundle-analyzer/next.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
21
const { ANALYZE } = process.env
32

43
module.exports = {
54
webpack: function (config, { isServer }) {
65
if (ANALYZE) {
6+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
7+
78
config.plugins.push(new BundleAnalyzerPlugin({
89
analyzerMode: 'server',
910
analyzerPort: isServer ? 8888 : 8889,

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next",
3-
"version": "7.0.0-canary.13",
3+
"version": "7.0.0-canary.15",
44
"description": "Minimalistic framework for server-rendered React applications",
55
"main": "./dist/server/next.js",
66
"license": "MIT",
@@ -75,7 +75,7 @@
7575
"ansi-html": "0.0.7",
7676
"autodll-webpack-plugin": "0.4.2",
7777
"babel-core": "7.0.0-bridge.0",
78-
"babel-loader": "8.0.0",
78+
"babel-loader": "8.0.2",
7979
"babel-plugin-react-require": "3.0.0",
8080
"babel-plugin-transform-react-remove-prop-types": "0.4.15",
8181
"case-sensitive-paths-webpack-plugin": "2.1.2",
@@ -87,7 +87,7 @@
8787
"fresh": "0.5.2",
8888
"friendly-errors-webpack-plugin": "1.7.0",
8989
"glob": "7.1.2",
90-
"hoist-non-react-statics": "2.5.0",
90+
"hoist-non-react-statics": "2.5.5",
9191
"htmlescape": "1.1.1",
9292
"http-errors": "1.6.2",
9393
"http-status": "1.0.1",

server/index.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -150,36 +150,42 @@ export default class Server {
150150
}
151151
}
152152

153-
if (this.nextConfig.useFileSystemPublicRoutes) {
154-
// Makes `next export` exportPathMap work in development mode.
155-
// So that the user doesn't have to define a custom server reading the exportPathMap
156-
if (this.dev && this.nextConfig.exportPathMap) {
157-
console.log('Defining routes from exportPathMap')
158-
const exportPathMap = await this.nextConfig.exportPathMap({}, {dev: true, dir: this.dir, outDir: null, distDir: this.distDir, buildId: this.buildId}) // In development we can't give a default path mapping
159-
for (const path in exportPathMap) {
160-
const {page, query = {}} = exportPathMap[path]
161-
routes[path] = async (req, res, params, parsedUrl) => {
162-
const { query: urlQuery } = parsedUrl
163-
164-
Object.keys(urlQuery)
165-
.filter(key => query[key] === undefined)
166-
.forEach(key => console.warn(`Url defines a query parameter '${key}' that is missing in exportPathMap`))
167-
168-
const mergedQuery = {...urlQuery, ...query}
169-
170-
await this.render(req, res, page, mergedQuery, parsedUrl)
171-
}
172-
}
153+
// In development we expose all compiled files for react-error-overlay's line show feature
154+
if (this.dev) {
155+
routes['/_next/development/:path*'] = async (req, res, params) => {
156+
const p = join(this.distDir, ...(params.path || []))
157+
console.log('page', p)
158+
await this.serveStatic(req, res, p)
173159
}
160+
}
174161

175-
// In development we expose all compiled files for react-error-overlay's line show feature
176-
if (this.dev) {
177-
routes['/_next/development/:path*'] = async (req, res, params) => {
178-
const p = join(this.distDir, ...(params.path || []))
179-
await this.serveStatic(req, res, p)
162+
// This path is needed because `render()` does a check for `/_next` and the calls the routing again
163+
routes['/_next/:path*'] = async (req, res, params, parsedUrl) => {
164+
await this.render404(req, res, parsedUrl)
165+
}
166+
167+
// Makes `next export` exportPathMap work in development mode.
168+
// So that the user doesn't have to define a custom server reading the exportPathMap
169+
if (this.dev && this.nextConfig.exportPathMap) {
170+
console.log('Defining routes from exportPathMap')
171+
const exportPathMap = await this.nextConfig.exportPathMap({}, {dev: true, dir: this.dir, outDir: null, distDir: this.distDir, buildId: this.buildId}) // In development we can't give a default path mapping
172+
for (const path in exportPathMap) {
173+
const {page, query = {}} = exportPathMap[path]
174+
routes[path] = async (req, res, params, parsedUrl) => {
175+
const { query: urlQuery } = parsedUrl
176+
177+
Object.keys(urlQuery)
178+
.filter(key => query[key] === undefined)
179+
.forEach(key => console.warn(`Url defines a query parameter '${key}' that is missing in exportPathMap`))
180+
181+
const mergedQuery = {...urlQuery, ...query}
182+
183+
await this.render(req, res, page, mergedQuery, parsedUrl)
180184
}
181185
}
186+
}
182187

188+
if (this.nextConfig.useFileSystemPublicRoutes) {
183189
// It's very important keep this route's param optional.
184190
// (but it should support as many as params, seperated by '/')
185191
// Othewise this will lead to a pretty simple DOS attack.

test/integration/basic/test/rendering.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import cheerio from 'cheerio'
44

5-
export default function ({ app }, suiteName, render, fetch) {
5+
export default function ({ app }, suiteName, render, fetch, appPort) {
66
async function get$ (path, query) {
77
const html = await render(path, query)
88
return cheerio.load(html)
@@ -123,6 +123,24 @@ export default function ({ app }, suiteName, render, fetch) {
123123
expect(res.headers.get('Content-Type')).toMatch('text/html; charset=iso-8859-2')
124124
})
125125

126+
test('should render 404 for _next routes that do not exist', async () => {
127+
const res = await fetch('/_next/abcdef')
128+
expect(res.status).toBe(404)
129+
})
130+
131+
test('should expose the compiled page file in development', async () => {
132+
await fetch('/stateless') // make sure the stateless page is built
133+
const clientSideJsRes = await fetch('/_next/development/static/development/pages/stateless.js')
134+
expect(clientSideJsRes.status).toBe(200)
135+
const clientSideJsBody = await clientSideJsRes.text()
136+
expect(clientSideJsBody).toMatch(/My component!/)
137+
138+
const serverSideJsRes = await fetch('/_next/development/server/static/development/pages/stateless.js')
139+
expect(serverSideJsRes.status).toBe(200)
140+
const serverSideJsBody = await serverSideJsRes.text()
141+
expect(serverSideJsBody).toMatch(/My component!/)
142+
})
143+
126144
test('allows to import .json files', async () => {
127145
const html = await render('/json')
128146
expect(html.includes('Zeit')).toBeTruthy()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
onDemandEntries: {
3+
// Make sure entries are not getting disposed.
4+
maxInactiveAge: 1000 * 60 * 60
5+
},
6+
useFileSystemPublicRoutes: false,
7+
exportPathMap () {
8+
return {
9+
'/exportpathmap-route': {page: '/exportpathmap-route'}
10+
}
11+
}
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => <div>exportpathmap was here</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => <div>Index</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const micro = require('micro')
2+
const next = require('next')
3+
4+
const dev = process.env.NODE_ENV !== 'production'
5+
const dir = __dirname
6+
const port = process.env.PORT || 3000
7+
8+
const app = next({ dev, dir })
9+
const handleNextRequests = app.getRequestHandler()
10+
11+
app.prepare().then(() => {
12+
const server = micro((req, res) => {
13+
if (/setAssetPrefix/.test(req.url)) {
14+
app.setAssetPrefix(`http://127.0.0.1:${port}`)
15+
} else if (/setEmptyAssetPrefix/.test(req.url)) {
16+
app.setAssetPrefix(null)
17+
} else {
18+
// This is to support multi-zones support in localhost
19+
// and may be in staging deployments
20+
app.setAssetPrefix('')
21+
}
22+
23+
handleNextRequests(req, res)
24+
})
25+
26+
server.listen(port, (err) => {
27+
if (err) {
28+
throw err
29+
}
30+
31+
console.log(`> Ready on http://localhost:${port}`)
32+
})
33+
})

0 commit comments

Comments
 (0)