Improve description of locals on guides/middleware#5522
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
sarah11918
left a comment
There was a problem hiding this comment.
Thank you for jumping in and helping us get this example just right, @Fryuni ! I'm not sure we're quite there yet, so I've left my thoughts so we can keep workshopping it. See what you think!
| ### Storing data in `context.locals` | ||
|
|
||
| `context.locals` is an object containing data from a `Response` that can be manipulated inside middleware. | ||
| `context.locals` is an object that can be manipulated inside the middleware. Adapters _might_ add data to it. |
There was a problem hiding this comment.
"Adapters might add data to it" is a little too vague to be helpful.
It's not clear whether the reader should take this as some kind of warning (i.e. if you're writing your own middleware , beware that there might be something else that's also manipulating the data in context.locals), or it's being used as an example of something that manipulates context.locals to provide real-usage context, or something else entirely.... fun fact! Did you know...! 😄
Can you reword that statement in a way that makes it clear why they are being told that?
There was a problem hiding this comment.
I think this could be added on a tip. What do you think of removing that last sentence and adding this:
:::tip[Adapter-provided properties]
Adapters may provide extra runtime information and functionality through the `locals` object.
For example, SSR adapters may include information about the request or runtime.
:::We can link to some examples. Of the official integrations, 4 modify the locals object.
There was a problem hiding this comment.
I still don't know why you're telling me this, though? Again, it's not clear why I should care about this, whether it's something for me to watch out for...
There was a problem hiding this comment.
I think it is a mix of everything. It is something to be aware:
- An integration may provide something that you are checking manually
- Something you write might override a value used by an integration
- Information that would be hard to access or infer otherwise might already be included there (like CloudFlare's runtime)
Maybe it would be clearer with examples
There was a problem hiding this comment.
OK, gotcha! No, I don't want examples here to clutter this up. The reasoning/why I should care is way more important. I think what you mentioned above is the kind of content that would be good to go inside a note!
There was a problem hiding this comment.
I sent a new version with a different tip. WDYT?
|
So @Fryuni , happy if you add a new note based on the "why I need to know/care" ideas and then adjust the two code samples accordingly! Let me know when you'd like me to take another look! |
There is a separate section explaining and demonstrating how to use the result of `next()` to transform the response after rendering.
sarah11918
left a comment
There was a problem hiding this comment.
Looks great, @Fryuni ! Thanks for your patience and cooperation during a particularly stressful docs time! 😅
Happy to have this improvement in the docs! 🥳
Update French Translation with PR #5522 Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
Update French Translation with PR #5522 Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
Description (required)
Change the comments and description of the
localsobject onguides/middleware.Related issues & labels (optional)
localsdocumentation on Middleware #4207improve documentation