fix(rivetkit): bind methods through createWriteThroughProxy#4987
Conversation
|
🚅 Deployed to the rivet-pr-4987 environment in rivet-frontend
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Code Review - fix(rivetkit): bind methods through createWriteThroughProxy Overview: This PR adds method binding in createWriteThroughProxy get trap so that functions retrieved from a proxied state object are called with the correct this (the raw inner target, not the proxy wrapper). What the Fix Solves: Without the fix, calling prototype methods on built-in types stored in actor state (Map, Set, Date, etc.) throws a TypeError because those built-ins use internal slots that proxies cannot satisfy. Binding to innerTarget makes those calls work. Critical Issue - Mutation Tracking Is Broken for Array Methods: The fix is too broad. By binding every function to innerTarget, mutations performed via method calls no longer flow through the proxy set trap, so commit is never called. Before this change, array.push() called with this=proxy caused the proxy set trap to fire (since push sets this[length]), so mutations were tracked. After the change, the raw array is mutated silently. Any user relying on in-place array mutations (push, pop, splice, sort, reverse, etc.) will silently lose state persistence. This is the core regression concern that needs to be resolved before merging. Possible Better Approach: Wrap the method call so mutations still reach the proxy, with a fallback to the raw target when built-in slots reject the proxy this. Alternatively, explicitly detect known incompatible built-ins (Map, Set, Date, RegExp, etc.) and only bind in those cases, preserving proxy-mediated mutation tracking for plain objects and arrays. Additional Concerns: (1) No tests - the change affects both array mutation tracking and built-in-type method calls. Tests should cover Map/Set calls through the proxy and Array push/splice triggering commit. (2) PR is a draft with description template unfilled and checklist unchecked. (3) Missing root cause description - knowing whether the target was Map/Set/Date would help scope the fix correctly. Summary: The intent is correct - bound receivers are required for certain built-in types - but the implementation is too broad and silently breaks write-through mutation tracking for array methods. Please add test coverage and reconsider the binding strategy before merging. |
b150344 to
fc4756e
Compare
af6e0e4 to
3be897d
Compare
3be897d to
c39972c
Compare
fc4756e to
5ec0839
Compare

Fixes an error that occurs when inspector state attempts to serialize non trivial values (ie
Date).