From 0926129a86f6ac71e9d3ecb56fc90da1e5518f0a Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Tue, 16 May 2017 12:46:47 -0700 Subject: [PATCH 01/13] Release 2.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 11532b5070549..0efc653a711a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "2.3.1", + "version": "2.3.2", "description": "Minimalistic framework for server-rendered React applications", "main": "./dist/server/next.js", "license": "MIT", From b00525897d4e14a3564fc7e6756707f01a86a826 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Wed, 17 May 2017 09:48:40 -0700 Subject: [PATCH 02/13] Release 2.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0efc653a711a5..70dc9c1236ecf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next", - "version": "2.3.2", + "version": "2.4.0", "description": "Minimalistic framework for server-rendered React applications", "main": "./dist/server/next.js", "license": "MIT", From 1703ad302ca0dd4ae97d04fe593385c83c550fa5 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Wed, 17 May 2017 10:40:14 -0700 Subject: [PATCH 03/13] remove old fly task related to `eval-script.js` (#1997) --- flyfile.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/flyfile.js b/flyfile.js index 2eb490396cb98..7b5c37319e8d1 100644 --- a/flyfile.js +++ b/flyfile.js @@ -4,7 +4,6 @@ const isWindows = /^win/.test(process.platform) export async function compile(fly) { await fly.parallel(['bin', 'server', 'lib', 'client']) - await fly.start('unrestrict') } export async function bin(fly, opts) { @@ -27,14 +26,6 @@ export async function client(fly, opts) { notify('Compiled client files') } -export async function unrestrict(fly) { - await fly.source('dist/lib/eval-script.js').babel({ - babelrc: false, - plugins: ['babel-plugin-transform-remove-strict-mode'] - }).target('dist/lib') - notify('Completed removing strict mode for eval script') -} - export async function copy(fly) { await fly.source('pages/**/*.js').target('dist/pages') } From 443dceaeec307070ec1fa3974b8d201abff330fd Mon Sep 17 00:00:00 2001 From: Ardani Rohman Date: Thu, 18 May 2017 00:41:54 +0700 Subject: [PATCH 04/13] improve example fallback translation and add new sample locale for lang id (#1983) --- examples/with-i18next/components/Title.js | 2 +- examples/with-i18next/pages/index.js | 7 +++++-- examples/with-i18next/static/locales/id/common.json | 3 +++ examples/with-i18next/static/locales/pt/common.json | 3 ++- examples/with-i18next/tools/startI18n.js | 3 ++- 5 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 examples/with-i18next/static/locales/id/common.json diff --git a/examples/with-i18next/components/Title.js b/examples/with-i18next/components/Title.js index ed6a37f6a0f3a..3af705a65f30d 100644 --- a/examples/with-i18next/components/Title.js +++ b/examples/with-i18next/components/Title.js @@ -1,2 +1,2 @@ import { translate } from 'react-i18next' -export default translate(['common'])((props) => (

{props.t('hello')}

)) +export default translate(['common'])((props) => (

{props.t('hello')}, {props.t('morning')}

)) diff --git a/examples/with-i18next/pages/index.js b/examples/with-i18next/pages/index.js index 2d429a86a79bf..c5eb77e5ee6fd 100644 --- a/examples/with-i18next/pages/index.js +++ b/examples/with-i18next/pages/index.js @@ -4,9 +4,12 @@ import startI18n from '../tools/startI18n' import { getTranslation } from '../tools/translationHelpers' import Title from '../components/Title' +// get language from query parameter or url path +const lang = 'id' + export default class Homepage extends Component { static async getInitialProps () { - const translations = await getTranslation('pt', 'common', 'http://localhost:3000/static/locales/') + const translations = await getTranslation(lang, 'common', 'http://localhost:3000/static/locales/') return { translations } } @@ -14,7 +17,7 @@ export default class Homepage extends Component { constructor (props) { super(props) - this.i18n = startI18n(props.translations) + this.i18n = startI18n(props.translations, lang) } render (props) { diff --git a/examples/with-i18next/static/locales/id/common.json b/examples/with-i18next/static/locales/id/common.json new file mode 100644 index 0000000000000..d90a19f9cffee --- /dev/null +++ b/examples/with-i18next/static/locales/id/common.json @@ -0,0 +1,3 @@ +{ + "hello": "halo" +} \ No newline at end of file diff --git a/examples/with-i18next/static/locales/pt/common.json b/examples/with-i18next/static/locales/pt/common.json index c8f9b7c041bbd..cbdf277358c47 100644 --- a/examples/with-i18next/static/locales/pt/common.json +++ b/examples/with-i18next/static/locales/pt/common.json @@ -1,3 +1,4 @@ { - "hello": "e ae tche" + "hello": "e ae tche", + "morning": "manha" } \ No newline at end of file diff --git a/examples/with-i18next/tools/startI18n.js b/examples/with-i18next/tools/startI18n.js index 791d2c93a684f..db65b27f12f30 100644 --- a/examples/with-i18next/tools/startI18n.js +++ b/examples/with-i18next/tools/startI18n.js @@ -1,6 +1,7 @@ import i18n from 'i18next' -const startI18n = file => i18n.init({ +const startI18n = (file, lang) => i18n.init({ + lng: lang, // active language http://i18next.com/translate/ fallbackLng: 'pt', resources: file, ns: ['common'], From 9346c96b398727edc5681044b3b41d7e2d4f7fd3 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 18 May 2017 12:00:39 +0530 Subject: [PATCH 05/13] Update react-hot-loader to 3.0.0-beta.7 (#2004) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 70dc9c1236ecf..8815f765c8203 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "path-match": "1.2.4", "pkg-up": "2.0.0", "prop-types": "15.5.10", - "react-hot-loader": "3.0.0-beta.6", + "react-hot-loader": "3.0.0-beta.7", "send": "0.15.2", "source-map-support": "0.4.15", "strip-ansi": "3.0.1", From 23a480964e8b6b291178200f1c39621a3cc0faf1 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Fri, 19 May 2017 14:02:11 +0200 Subject: [PATCH 06/13] Update layout.js (#2018) --- examples/layout-component/components/layout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/layout-component/components/layout.js b/examples/layout-component/components/layout.js index 2194b5838a5bd..d96a8434c6c5a 100644 --- a/examples/layout-component/components/layout.js +++ b/examples/layout-component/components/layout.js @@ -19,7 +19,7 @@ export default ({ children, title = 'This is the default title' }) => ( { children }
- I`m here to stay + {'I`m here to stay'}
) From d36118ab022765f9fb79514b30cb158b8d077cca Mon Sep 17 00:00:00 2001 From: Xuezheng Ma Date: Fri, 19 May 2017 15:02:01 -0700 Subject: [PATCH 07/13] Check if _document.js returns a react element before using (#2013) * Check if _document.js returns a react element before using * Use capital letter R in 'React' --- server/render.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/render.js b/server/render.js index 75ac75a2d8930..a7199589cfd79 100644 --- a/server/render.js +++ b/server/render.js @@ -90,6 +90,7 @@ async function doRender (req, res, pathname, query, { if (res.finished) return + if (!Document.prototype || !Document.prototype.isReactComponent) throw new Error('_document.js is not exporting a React element') const doc = createElement(Document, { __NEXT_DATA__: { props, From 3c95f21d8c48a8aa2cfac3c93c715830db35ce9d Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Tue, 23 May 2017 23:00:14 +0530 Subject: [PATCH 08/13] Do not try to server unnessesary files in either dev or prod. (#2048) --- server/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/index.js b/server/index.js index 687091f7e25a1..9c7039890c037 100644 --- a/server/index.js +++ b/server/index.js @@ -100,24 +100,32 @@ export default class Server { }, '/_next/:hash/manifest.js': async (req, res, params) => { + if (!this.dev) return this.send404(res) + this.handleBuildHash('manifest.js', params.hash, res) const p = join(this.dir, `${this.dist}/manifest.js`) await this.serveStatic(req, res, p) }, '/_next/:hash/main.js': async (req, res, params) => { + if (!this.dev) return this.send404(res) + this.handleBuildHash('main.js', params.hash, res) const p = join(this.dir, `${this.dist}/main.js`) await this.serveStatic(req, res, p) }, '/_next/:hash/commons.js': async (req, res, params) => { + if (!this.dev) return this.send404(res) + this.handleBuildHash('commons.js', params.hash, res) const p = join(this.dir, `${this.dist}/commons.js`) await this.serveStatic(req, res, p) }, '/_next/:hash/app.js': async (req, res, params) => { + if (this.dev) return this.send404(res) + this.handleBuildHash('app.js', params.hash, res) const p = join(this.dir, `${this.dist}/app.js`) await this.serveStatic(req, res, p) @@ -341,4 +349,9 @@ export default class Server { res.setHeader('Cache-Control', 'max-age=365000000, immutable') } + + send404 (res) { + res.statusCode = 404 + res.end('404 - Not Found') + } } From 9121a9d22e36b0f19e2614d2f1ba522e34b8ac1e Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 25 May 2017 21:58:08 +0530 Subject: [PATCH 09/13] Never cache assets and HTML in the dev mode. (#2045) * Never cache assets and HTML in the dev mode. * Move etags test to the production. Now it won't work in dev because of no-cache settings. --- server/document.js | 8 ++++---- server/index.js | 5 +++-- server/render.js | 19 +++++++++++++++---- test/integration/basic/test/misc.js | 10 ---------- .../integration/production/test/index.test.js | 10 ++++++++++ 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/server/document.js b/server/document.js index de7a6795d36de..d3f49708b3507 100644 --- a/server/document.js +++ b/server/document.js @@ -36,8 +36,8 @@ export class Head extends Component { getChunkPreloadLink (filename) { const { __NEXT_DATA__ } = this.context._documentProps - let { buildStats, assetPrefix } = __NEXT_DATA__ - const hash = buildStats ? buildStats[filename].hash : '-' + let { buildStats, assetPrefix, buildId } = __NEXT_DATA__ + const hash = buildStats ? buildStats[filename].hash : buildId return ( { @@ -13,14 +12,5 @@ export default function (context) { const html = await context.app.renderToHTML({}, res, '/finish-response', {}) expect(html).toBeFalsy() }) - - test('allow etag header support', async () => { - const url = `http://localhost:${context.appPort}/stateless` - const etag = (await fetch(url)).headers.get('ETag') - - const headers = { 'If-None-Match': etag } - const res2 = await fetch(url, { headers }) - expect(res2.status).toBe(304) - }) }) } diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index b15c02eedb8ee..f8f798a3f1519 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -9,6 +9,7 @@ import { renderViaHTTP } from 'next-test-utils' import webdriver from 'next-webdriver' +import fetch from 'node-fetch' const appDir = join(__dirname, '../') let appPort @@ -35,6 +36,15 @@ describe('Production Usage', () => { const html = await renderViaHTTP(appPort, '/') expect(html).toMatch(/Hello World/) }) + + it('should allow etag header support', async () => { + const url = `http://localhost:${appPort}/` + const etag = (await fetch(url)).headers.get('ETag') + + const headers = { 'If-None-Match': etag } + const res2 = await fetch(url, { headers }) + expect(res2.status).toBe(304) + }) }) describe('With navigation', () => { From 787a110b75b46f625d135e9f7a22a5f17512d718 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 25 May 2017 21:59:03 +0530 Subject: [PATCH 10/13] Fix issue related to 404 and no default exports. (#2063) Just after a 404 page, if we created a page with no default exports. It'll throw an error. And it'll crash internal webpack state. So, once we have it we need to do a hard reload to recover it. --- client/webpack-hot-middleware-client.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/webpack-hot-middleware-client.js b/client/webpack-hot-middleware-client.js index f97c5853f7c5a..ac8a7fc045d96 100644 --- a/client/webpack-hot-middleware-client.js +++ b/client/webpack-hot-middleware-client.js @@ -30,7 +30,16 @@ export default () => { return } - const { err } = Router.components[route] || {} + const { err, Component } = Router.components[route] || {} + + if (!Component) { + // This only happens when we create a new page without a default export. + // If you removed a default export from a exising viewing page, this has no effect. + console.log(`Hard reloading due to no default component in page: ${route}`) + window.location.reload() + return + } + if (err) { // reload to recover from runtime errors Router.reload(route) From f21dd6120fbedc86b319498d1fd93f6411ce2a78 Mon Sep 17 00:00:00 2001 From: mateosilguero Date: Thu, 25 May 2017 22:03:39 -0300 Subject: [PATCH 11/13] johnny five example --- examples/with-johnnyFive/README.md | 25 ++++++++++ examples/with-johnnyFive/package.json | 17 +++++++ examples/with-johnnyFive/pages/index.js | 32 +++++++++++++ examples/with-johnnyFive/server.js | 61 +++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 examples/with-johnnyFive/README.md create mode 100644 examples/with-johnnyFive/package.json create mode 100644 examples/with-johnnyFive/pages/index.js create mode 100644 examples/with-johnnyFive/server.js diff --git a/examples/with-johnnyFive/README.md b/examples/with-johnnyFive/README.md new file mode 100644 index 0000000000000..1b35df46f31c5 --- /dev/null +++ b/examples/with-johnnyFive/README.md @@ -0,0 +1,25 @@ +[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-socket.io) + +# Socket.io example + +## How to use + +Download the example [or clone the repo](https://github.com/zeit/next.js): + +```bash +curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-socket.io +cd with-socket.io +``` + +Install it and run: + +```bash +npm install +npm run dev +``` + +## The idea behind the example + +This example show how to use [socket.io](https://socket.io/) inside a Next.js application. It uses `getInitialProps` to fetch the old messages from a HTTP endpoint as if it was a Rest API. The example combine the WebSocket server with the Next server, in a production application you should split them as different services. + +**Example:** [https://next-socket-io.now.sh/](https://next-socket-io.now.sh/) diff --git a/examples/with-johnnyFive/package.json b/examples/with-johnnyFive/package.json new file mode 100644 index 0000000000000..4425f45b1389f --- /dev/null +++ b/examples/with-johnnyFive/package.json @@ -0,0 +1,17 @@ +{ + "dependencies": { + "express": "^4.15.2", + "isomorphic-fetch": "^2.2.1", + "johnny-five": "^0.10.13", + "next": "latest", + "react": "^15.5.4", + "react-dom": "^15.5.4", + "socket.io": "^1.7.3", + "socket.io-client": "^1.7.3" + }, + "scripts": { + "dev": "node server.js", + "build": "next build", + "start": "NODE_ENV=production node server.js" + } +} diff --git a/examples/with-johnnyFive/pages/index.js b/examples/with-johnnyFive/pages/index.js new file mode 100644 index 0000000000000..0e27fd9b87bc6 --- /dev/null +++ b/examples/with-johnnyFive/pages/index.js @@ -0,0 +1,32 @@ +import { Component } from 'react' +import io from 'socket.io-client' +import fetch from 'isomorphic-fetch' + +class HomePage extends Component { + // init state with the prefetched messages + state = { + ledState: 0 + } + + // connect to WS server and listen event + componentDidMount () { + this.socket = io('http://localhost:3000/') + } + + handleLed(state) { + this.socket.emit('led', state) + } + + render () { + return ( +
+
+ + +
+
+ ) + } +} + +export default HomePage diff --git a/examples/with-johnnyFive/server.js b/examples/with-johnnyFive/server.js new file mode 100644 index 0000000000000..d299818d08413 --- /dev/null +++ b/examples/with-johnnyFive/server.js @@ -0,0 +1,61 @@ +const app = require('express')() +const server = require('http').Server(app) +const io = require('socket.io')(server) +const next = require('next') +//http://johnny-five.io/ +const five = require('johnny-five'); + +const dev = process.env.NODE_ENV !== 'production' +const nextApp = next({ dev }) +const nextHandler = nextApp.getRequestHandler() + +let led = null; + +five.Board().on('ready', function() { + console.log('Arduino is ready.'); + + // Initial state + let state = { + value: 0 + }; + + // Map pins to digital inputs on the board + led = new five.Led(13); + +}); + +nextApp.prepare().then(() => { + + app.get('*', (req, res) => { + return nextHandler(req, res) + }) + + var setState = function(st) { + if(st == 1){ + led.on(); + }else { + led.off(); + } + }; + + io.on('connection', function(client) { + client.on('join', function(handshake) { + console.log(handshake); + }); + + client.on('led', function(data) { + // Set the new colors + setState(data); + + //client.emit('led', data); + //client.broadcast.emit('led', data); + }); + }); + + //You should change 'localhost' by you ip adress. + //change it on the index.js too. + server.listen(3000, 'localhost', (err) => { + if (err) throw err + console.log('> Ready on http://localhost:3000') + }) +}) From 602d3b1db887af3b67b8cc6e4fad2971fa3a1ef4 Mon Sep 17 00:00:00 2001 From: mateosilguero Date: Thu, 25 May 2017 22:48:03 -0300 Subject: [PATCH 12/13] johnny five example --- examples/with-johnnyFive/package.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/with-johnnyFive/package.json b/examples/with-johnnyFive/package.json index 4425f45b1389f..5ebf600ee18bb 100644 --- a/examples/with-johnnyFive/package.json +++ b/examples/with-johnnyFive/package.json @@ -1,4 +1,9 @@ { + "name": "next", + "version": "3.0.0-beta6", + "description": "Minimalistic framework for server-rendered React applications", + "main": "./dist/server/next.js", + "license": "MIT", "dependencies": { "express": "^4.15.2", "isomorphic-fetch": "^2.2.1", @@ -7,7 +12,10 @@ "react": "^15.5.4", "react-dom": "^15.5.4", "socket.io": "^1.7.3", - "socket.io-client": "^1.7.3" + "socket.io-client": "^1.7.3", + "react-hot-loader": "3.0.0-beta.6", + "recursive-copy": "^2.0.6", + "send": "0.15.3", }, "scripts": { "dev": "node server.js", From 67ceae6b18bfe8878cfcf7e02ef605d53ec24863 Mon Sep 17 00:00:00 2001 From: mateosilguero Date: Thu, 25 May 2017 22:58:01 -0300 Subject: [PATCH 13/13] johnny five example --- examples/with-johnnyFive/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/with-johnnyFive/package.json b/examples/with-johnnyFive/package.json index 5ebf600ee18bb..7fd1176cfcc77 100644 --- a/examples/with-johnnyFive/package.json +++ b/examples/with-johnnyFive/package.json @@ -1,7 +1,6 @@ { "name": "next", "version": "3.0.0-beta6", - "description": "Minimalistic framework for server-rendered React applications", "main": "./dist/server/next.js", "license": "MIT", "dependencies": {