koajs / ejs

a koa view render middleware, support all feature of ejs
MIT License
248 stars 57 forks source link

when cache is true, something wrong will be #69

Closed fangxu864 closed 1 year ago

fangxu864 commented 2 years ago

line79 if (settings.cache && cache[viewPath]) return cache[viewPath](options.scope, options)

should be

return cache[viewPath].call()

hckhanh commented 1 year ago

The same with me, the cache is not found. Can you check on that, @titanism?

titanism commented 1 year ago

Please provide a working example or a test that demonstrates this is a bug.

jalfonso commented 1 year ago

This occurs for me with @koa/ejs@5.0.0 when using cache + layout.

Using the example code with cache: true and a simple layout template:

<%- body %>

The first render is successful but subsequent calls throw:

  ReferenceError: body is not defined
      at eval (eval at compile (/tmp/koa-ejs-cache-issue/node_modules/ejs/lib/ejs.js:673:12), <anonymous>:6:17)
      at Object.template [as /tmp/koa-ejs-cache-issue/view/template.html] (/tmp/koa-ejs-cache-issue/node_modules/ejs/lib/ejs.js:703:17)
      at render (/tmp/koa-ejs-cache-issue/node_modules/@koa/ejs/index.js:79:66)
      at app.context.render (/tmp/koa-ejs-cache-issue/node_modules/@koa/ejs/index.js:108:20)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async /tmp/koa-ejs-cache-issue/index.js:15:3
kissycn commented 1 year ago

I have encountered the same problem