fix(rsc): member expression usage binds unserializable variables#1155
fix(rsc): member expression usage binds unserializable variables#1155james-elicx wants to merge 2 commits intovitejs:mainfrom
Conversation
hi-ogawa
left a comment
There was a problem hiding this comment.
Thanks for tackling this. The expected behavior around this isn't of course documented as React feature, but happy to have this after review. I think Next also had some old PR mentioning whether they go for it or not, so would be nice to check up if there was a rational for and against supporting this.
|
It's a massive 4,000 line file so a bit hard to navigate without working in it before, but I believe their binding candidates are represented as this Name struct which has a list of the parts to build up the full member expression. There's a So it seems like they definitely take the approach of binding full member expressions rather than bare variables where possible. |
|
I think the reference I had in mind was this vercel/next.js#66464. It looked like this was one simplification path which they didn't eventually take. Are the examples brought up there something relevant to this PR? |
|
Ah okay, it looks like that's indeed EDIT: Oh wait, so that's probably fixed in other PR by vercel/next.js#66601. |
Description
Objects that are used in server functions can contain fields that are not serializable for client components. However, the server function may only be accessing specific properties within the object.
This is another interesting bug I found when testing out Payload CMS with Vinext.
When this scenario happens, the member expression for the variable should be bound instead of the variable itself. This would allow a complex object to be passed around, while only accessing serializable fields on it.
For safety, it will fall back to binding the bare variable for computed member expressions and shadowed objects.
As before, regression tests mostly generated by AI, although I did do a couple of extra ones myself for additional cases.