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 3-line change adds method binding inside the What the fix solves Without this change, calling prototype methods on built-in types stored in actor state throws a Critical issue: mutation tracking silently broken for array/object methods The binding is applied unconditionally to every function, including methods on plain arrays and objects. This breaks write-through mutation tracking. Before this PR: After this PR: The same regression applies to Suggested fix Only bind to get(innerTarget, property, receiver) {
const result = Reflect.get(innerTarget, property, receiver);
if (typeof result === "function") {
const internalSlotTypes = [Date, Map, Set, WeakMap, WeakSet, RegExp, ArrayBuffer, DataView];
if (internalSlotTypes.some(T => innerTarget instanceof T)) {
return result.bind(innerTarget);
}
return result.bind(proxy);
}
return result && typeof result === "object"
? wrap(result as object)
: result;
},( Additional concerns
Summary The intent is correct. Bound receivers are required for built-in types with internal slots. But binding unconditionally to all functions silently disables write-through mutation tracking for arrays and objects, which is the core purpose of this proxy. Please scope the binding to known internal-slot types, add test coverage for both the fixed case and the mutation-tracking case, and fill in the PR description before merging. |
b150344 to
fc4756e
Compare
af6e0e4 to
3be897d
Compare
3be897d to
c39972c
Compare
fc4756e to
5ec0839
Compare
5ec0839 to
4ff7adb
Compare
c39972c to
add44af
Compare

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