Skip to content

Commit

Permalink
Merge branch 'canary' into add/update-css-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Jan 10, 2020
2 parents 29e23bb + 12665cb commit 118b42e
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 40 deletions.
7 changes: 2 additions & 5 deletions examples/with-higher-order-component/README.md
Expand Up @@ -30,16 +30,13 @@ Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```

**yarn**

```bash
npm install
npm run dev
yarn
yarn dev
```

Deploy it to the cloud with [now](https://zeit.co/now)
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.1.8-canary.9"
"version": "9.1.8-canary.11"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.1.8-canary.9",
"version": "9.1.8-canary.11",
"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.1.8-canary.9",
"version": "9.1.8-canary.11",
"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.1.8-canary.9",
"version": "9.1.8-canary.11",
"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.1.8-canary.9",
"version": "9.1.8-canary.11",
"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.1.8-canary.9",
"version": "9.1.8-canary.11",
"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.1.8-canary.9",
"version": "9.1.8-canary.11",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/utils.ts
Expand Up @@ -343,7 +343,7 @@ async function computeFromManifest(

// Add well-known shared file
files.set(
path.join(
path.posix.join(
`static/${buildId}/pages/`,
`/_app${isModern ? '.module' : ''}.js`
),
Expand Down
47 changes: 26 additions & 21 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -647,30 +647,35 @@ export default class Server {
}

protected generatePublicRoutes(): Route[] {
const routes: Route[] = []
const publicFiles = recursiveReadDirSync(this.publicDir)

publicFiles.forEach(path => {
const unixPath = path.replace(/\\/g, '/')
// Only include public files that will not replace a page path
// this should not occur now that we check this during build
if (!this.pagesManifest![unixPath]) {
routes.push({
match: route(unixPath),
type: 'route',
name: 'public catchall',
fn: async (req, res, _params, parsedUrl) => {
const p = join(this.publicDir, unixPath)
await this.serveStatic(req, res, p, parsedUrl)
const publicFiles = new Set(
recursiveReadDirSync(this.publicDir).map(p => p.replace(/\\/g, '/'))
)

return [
{
match: route('/:path*'),
name: 'public folder catchall',
fn: async (req, res, params, parsedUrl) => {
const path = `/${(params.path || []).join('/')}`

if (publicFiles.has(path)) {
await this.serveStatic(
req,
res,
// we need to re-encode it since send decodes it
join(this.dir, 'public', encodeURIComponent(path)),
parsedUrl
)
return {
finished: true,
}
},
})
}
})

return routes
}
return {
finished: false,
}
},
} as Route,
]
}

protected getDynamicRoutes() {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.1.8-canary.9",
"version": "9.1.8-canary.11",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down
11 changes: 6 additions & 5 deletions packages/next/server/next-dev-server.ts
Expand Up @@ -258,14 +258,14 @@ export default class DevServer extends Server {
protected async _beforeCatchAllRender(
req: IncomingMessage,
res: ServerResponse,
_params: Params,
params: Params,
parsedUrl: UrlWithParsedQuery
) {
const { pathname } = parsedUrl

const path = `/${(params.path || []).join('/')}`
// check for a public file, throwing error if there's a
// conflicting page
if (await this.hasPublicFile(pathname!)) {
if (await this.hasPublicFile(path)) {
if (await this.hasPage(pathname!)) {
const err = new Error(
`A conflicting public file and page file was found for path ${pathname} https://err.sh/zeit/next.js/conflicting-public-file-page`
Expand All @@ -274,7 +274,7 @@ export default class DevServer extends Server {
await this.renderError(err, req, res, pathname!, {})
return true
}
await this.servePublic(req, res, pathname!)
await this.servePublic(req, res, path)
return true
}

Expand Down Expand Up @@ -484,7 +484,8 @@ export default class DevServer extends Server {
}

servePublic(req: IncomingMessage, res: ServerResponse, path: string) {
const p = join(this.publicDir, path)
const p = join(this.publicDir, encodeURIComponent(path))
// we need to re-encode it since send decodes it
return this.serveStatic(req, res, p)
}

Expand Down
6 changes: 6 additions & 0 deletions test/integration/build-output/test/index.test.js
Expand Up @@ -30,6 +30,7 @@ describe('Build Output', () => {
expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_app')
expect(stdout).not.toContain(' /_error')
expect(stdout).not.toContain('<buildId>')

expect(stdout).toContain('○ /')
})
Expand All @@ -55,6 +56,7 @@ describe('Build Output', () => {

expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_error')
expect(stdout).not.toContain('<buildId>')

expect(stdout).toContain(' /_app')
expect(stdout).toContain('○ /')
Expand Down Expand Up @@ -82,6 +84,7 @@ describe('Build Output', () => {

expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_error')
expect(stdout).not.toContain('<buildId>')

expect(stdout).toContain('○ /')
})
Expand All @@ -107,6 +110,7 @@ describe('Build Output', () => {

expect(stdout).not.toContain(' /_document')
expect(stdout).not.toContain(' /_app')
expect(stdout).not.toContain('<buildId>')

expect(stdout).toContain(' /_error')
expect(stdout).toContain('○ /')
Expand All @@ -126,6 +130,7 @@ describe('Build Output', () => {
stdout: true,
})
expect(stdout).toContain('○ /_error')
expect(stdout).not.toContain('<buildId>')
})

// This test is not really correct.
Expand All @@ -135,6 +140,7 @@ describe('Build Output', () => {
stdout: true,
})
expect(stdout).toContain('λ /_error')
expect(stdout).not.toContain('<buildId>')
})
})
})
1 change: 1 addition & 0 deletions test/integration/dynamic-routing/public/hello copy.txt
@@ -0,0 +1 @@
hello world copy
1 change: 1 addition & 0 deletions test/integration/dynamic-routing/public/hello%20copy.txt
@@ -0,0 +1 @@
hello world %20
1 change: 1 addition & 0 deletions test/integration/dynamic-routing/public/hello+copy.txt
@@ -0,0 +1 @@
hello world +
32 changes: 32 additions & 0 deletions test/integration/dynamic-routing/test/index.test.js
Expand Up @@ -350,6 +350,34 @@ function runTests(dev) {
expect(data).toMatch(/hello world/)
})

it('should serve file with space from public folder', async () => {
const res = await fetchViaHTTP(appPort, '/hello copy.txt')
const text = (await res.text()).trim()
expect(text).toBe('hello world copy')
expect(res.status).toBe(200)
})

it('should serve file with plus from public folder', async () => {
const res = await fetchViaHTTP(appPort, '/hello+copy.txt')
const text = (await res.text()).trim()
expect(text).toBe('hello world +')
expect(res.status).toBe(200)
})

it('should serve file from public folder encoded', async () => {
const res = await fetchViaHTTP(appPort, '/hello%20copy.txt')
const text = (await res.text()).trim()
expect(text).toBe('hello world copy')
expect(res.status).toBe(200)
})

it('should serve file with %20 from public folder', async () => {
const res = await fetchViaHTTP(appPort, '/hello%2520copy.txt')
const text = (await res.text()).trim()
expect(text).toBe('hello world %20')
expect(res.status).toBe(200)
})

if (dev) {
it('should work with HMR correctly', async () => {
const browser = await webdriver(appPort, '/post-1/comments')
Expand Down Expand Up @@ -389,6 +417,10 @@ function runTests(dev) {
join(appDir, '.next/routes-manifest.json')
)

for (const route of manifest.dynamicRoutes) {
route.regex = normalizeRegEx(route.regex)
}

expect(manifest).toEqual({
version: 1,
basePath: '',
Expand Down

0 comments on commit 118b42e

Please sign in to comment.