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

overriding request.context #115

Open
pi0 opened this issue Jan 29, 2025 · 0 comments
Open

overriding request.context #115

pi0 opened this issue Jan 29, 2025 · 0 comments

Comments

@pi0
Copy link
Member

pi0 commented Jan 29, 2025

Users might direclty update request.context in upgrade hook which is a wrong usecase.

Two possible solution:

  • hydrate request.context (reference) after calling hook (more hackable / if non object value assigned makes things bad)
  • make it a ready only getter (developers know they can't override)

          Thanks @sandros94, this gave me some much needed guidance! However, I found that setting the context to an object doesn't work, you have to set specific properties. For example (using `[email protected]`):

Trying to set request.context to a new object:

upgrade(request) {
  request.context = { data: 'test'}
},
open(peer) {
  console.log(peer.context) // logs {}
}

Setting a specific property in request.context:

upgrade(request) {
  request.context.data = 'test'
},
open(peer) {
  console.log(peer.context) // logs { data: 'test' }
}

Originally posted by @travis-r6s in #112 (comment)

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

1 participant