Skip to content

Commit 61d6cf3

Browse files
mweststrateMichel Weststrate
andauthored
fix: Don't rewrap setters on the prototype (#4563)
Co-authored-by: Michel Weststrate <mweststrate@meta.com>
1 parent a9cf1fe commit 61d6cf3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/fair-houses-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mobx": patch
3+
---
4+
5+
Fixed memory leak where makeAutoObservable would keep wrapping setters defined on the prototype. Fixes #4553

packages/mobx/src/types/autoannotation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
autoAction,
1111
isGenerator,
1212
MakeResult,
13-
die
13+
die,
14+
isAction
1415
} from "../internal"
1516

1617
const AUTO = "true"
@@ -40,7 +41,9 @@ function make_(
4041
// lone setter -> action setter
4142
if (descriptor.set) {
4243
// TODO make action applicable to setter and delegate to action.make_
43-
const set = createAction(key.toString(), descriptor.set) as (v: any) => void
44+
const set = isAction(descriptor.set)
45+
? descriptor.set // See #4553
46+
: (createAction(key.toString(), descriptor.set) as (v: any) => void)
4447
// own
4548
if (source === adm.target_) {
4649
return adm.defineProperty_(key, {

0 commit comments

Comments
 (0)