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

Initialize context.state sooner #1732

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ module.exports = class Application extends Emitter {
request.response = response
response.request = request
context.originalUrl = request.originalUrl = req.url
context.state = {}
context.state = Object.assign({}, context.state)
krisstern marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole point of ctx.state as I see it is to ensure there's no state bleed between requests.
As far as I see it, this change defeats this original purpose.

return context
}

Expand Down
1 change: 1 addition & 0 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const proto = module.exports = {
request: this.request.toJSON(),
response: this.response.toJSON(),
app: this.app.toJSON(),
state: this.state,
originalUrl: this.originalUrl,
req: '<original node req>',
res: '<original node res>',
Expand Down