Why don't you assign "locals" to "ctx.state"?
fengxinming opened this issue · 5 comments
fengxinming commented
origin:
const state = Object.assign(locals, options, ctx.state || {})
turn into:
const state = Object.assign({}, options, ctx.state || {}, locals)
Would it be better?
int64ago commented
@fengxinming hi, any case to prove ?
fengxinming commented
@int64ago for example:
state.title = '1';
ctx.render('index', {title: 2});
#{ title } => title === '1'
int64ago commented
@fengxinming Hi, I think this is a break change, and options
should not be covered by locals
fengxinming commented
@int64ago or locals
cover options
Yaojian commented
const state = Object.assign(locals, options, ctx.state || {})
may lead bug when locals
is contained (directly or indirectly) by ctx.state
.
I think
const state = Object.assign({}, locals, options, ctx.state || {})
is more safe for client code.