[Flight Reply] Encode Objects Returned to the Client by Reference
Stacked on #28997.
We can use the technique of referencing an object by its row + property name path for temporary references - like we do for deduping. That way we don't need to generate an ID for temporary references. Instead, they can just be an opaque marker in the slot and it has the implicit ID of the row + path.
Then we can stash all objects, even the ones that are actually available to read on the server, as temporary references. Without adding anything to the payload since the IDs are implicit. If the same object is returned to the client, it can be referenced by reference instead of serializing it back to the client. This also helps preserve object identity.
We assume that the objects are immutable when they pass the boundary.
I'm not sure if this is worth it but with this mechanism, if you return the FormData payload from a useActionState it doesn't have to be serialized on the way back to the client. This is a common pattern for having access to the last submission as "default value" to the form fields. However you can still control it by replacing it with another object if you want. In MPA mode, the temporary references are not configured and so it needs to be serialized in that case. That's required anyway for hydration purposes.
I'm not sure if people will actually use this in practice though or if FormData will always be destructured into some other object like with a library that turns it into typed data, and back. If so, the object identity is lost.
The size diff is too large to display in a single comment. The CircleCI job contains an artifact called 'sizebot-message.md' with the full message.
Generated by :no_entry_sign: dangerJS against 7c6944927cbc7b530fbf0bc25110517f0db0e2a0
It's not directly related to this PR but the previous ones. In particular, if you use a : as a property name that's in a cycle - it'll error since the cycle can't be expressed. So that's a known bug.
I'm not going to do it imminently fix it. It's an exercise left for the reader.