Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded #14

Closed
daniel-jonathan opened this issue Nov 5, 2015 · 7 comments
Closed

Maximum call stack size exceeded #14

daniel-jonathan opened this issue Nov 5, 2015 · 7 comments

Comments

@daniel-jonathan
Copy link

Hi,

I keep getting this error when I call this.render using koa-jade:


server error [RangeError: Maximum call stack size exceeded] { request:
{ method: 'GET',
url: '/daniel',
header:
{ 'x-real-ip': '10.211.55.2',
'x-forwarded-for': '10.211.55.2',
host: 'docs.sandbox.local:80',
'x-nginx-proxy': 'true',
connection: 'close',
'cache-control': 'max-age=0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
'accept-encoding': 'gzip, deflate, sdch',
'accept-language': 'en-US,en;q=0.8',
cookie: '_ga=GA1.2.1728672733.1439768627' } },
response:
{ status: 200,
message: 'OK',
header:
{ 'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET,HEAD,PUT,POST,DELETE',
'cache-control': 'no-cache',
'content-type': 'text/html; charset=utf-8',
'content-length': '19' } },
app: { subdomainOffset: 2, env: 'development' },
originalUrl: '/daniel',
req: '',
res: '',
socket: '' }


This is the code:

'use strict';
'use esnext';

function *base(route, next) {
yield this.render('base', {
title: 'Docs',
styles: [
// materialize
'/materialize.min.css',

        // material icons
        '/css/materialdesignicons.min.css',

        // graphkit
        '/app.css'
    ],
    vendors: [
        // jquery
        '/jquery.min.js',

        // angular
        '/angular.min.js',
        '/angular-aria.min.js',
        '/angular-route.min.js',

        // materialize
        '/materialize.min.js',

        // d3
        '/d3.min.js'
    ],
    packages: [
        // app
        '/app.js',
        '/auth.js',
        '/connect.js',
        '/http.js',
        '/router.js'
    ]
}, true);

if (undefined !== next) {
    yield next;
}

}

function *index(route, next) {
yield this.render('routes/index', {}, true);
}

function *profile(route, next) {
yield this.render('routes/profile', {}, true);
}

function *error(route, next) {
yield this.render('routes/error404', {}, true);
}

module.exports = function(app) {
const koaRoute = require('koa-route');
const koaJade = require('koa-jade');
const jade = new koaJade({
viewPath: __dirname + '/src/views',
debug: 'development' == app.env,
pretty: 'development' == app.env,
compileDebug: 'development' == app.env,
locals: {
title: 'Docs'
},
basedir: '/',
noCache: true,
helperPath: [
//'path/to/jade/helpers',
//{ random: 'path/to/lib.js' },
]
});

app.use(jade.middleware);

// base
app.use(koaRoute.get('/', base));
app.use(koaRoute.get('/a/welcome', base));
app.use(koaRoute.get('/:username', base));

// index
app.use(koaRoute.get('/route/index', index));

// profile
app.use(koaRoute.get('/route/profile', profile));

};

@qw3r
Copy link

qw3r commented Nov 8, 2015

@DanielDahan Can you, please explain how did you managed to solve this issue?

@albertogasparin
Copy link

I've solved it by removing yeld:

router.get('/', function *() {
  this.render('index', { a: b });
});

However it might not be the behaviour you want.

@watzon
Copy link

watzon commented Dec 15, 2015

Can we reopen this until there is a fix that doesn't require removing yield statements? They're kind of important

@daniel-jonathan
Copy link
Author

I looked over my code, and I also removed the yield call.

@chrisyip
Copy link
Owner

this.render doesn't require yield statement, it just a normal function.

Here's the reasons:

Normal function is faster than generator function:
iojs 1.6.4
Normal function x 163,231 ops/sec ±1.33% (180 runs sampled)
Generator function x 74,904 ops/sec ±1.86% (173 runs sampled)
Koa team encourages to use normal functions (see v2):
app.use(ctx => {
  ctx.body = 'Hello World';
})

I'll update the doc.

@ladytellur
Copy link

@chrisyip some of us just wants to use koa@1 until async/await will become native in stable Node version

@chrisyip
Copy link
Owner

@ladytellur koa-pug supports koa@1 and koa@2, just use this.render() without yield:

const app = new Koa
const pug = new Pug({ /* options */ })
pug.use(app)

app.use(function* () {
  this.render('index')
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants