Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-seals-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

Fix regression from #4639 where isComputedProp returned false for lazy @computed properties before first read
16 changes: 15 additions & 1 deletion packages/mobx/__tests__/decorators_20223/stage3-decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
IAtom,
createAtom,
runInAction,
makeObservable
makeObservable,
isComputedProp
} from "../../src/mobx"
import { $mobx, type ObservableArrayAdministration } from "../../src/internal"
import * as mobx from "../../src/mobx"
Expand Down Expand Up @@ -1191,6 +1192,19 @@ test("4616 - @computed decorator should be lazy", () => {
expect(computeCount).toBe(0)
})

test("4616 - isComputedProp reports lazy @computed before first read", () => {
class Order {
@computed
get total() {
return 3
}
}

const o = new Order()

t.equal(isComputedProp(o, "total"), true)
})

test("4616 - observe on @computed before first read materialises it", () => {
class Order {
@observable accessor price: number = 3
Expand Down
6 changes: 5 additions & 1 deletion packages/mobx/src/api/iscomputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export function _isComputed(value, property?: PropertyKey): boolean {
if (isObservableObject(value) === false) {
return false
}
if (!value[$mobx].values_.has(property)) {
const adm = value[$mobx]
if (adm.lazyComputedKeys_?.has(property)) {
return true
}
if (!adm.values_.has(property)) {
return false
}
const atom = getAtom(value, property)
Expand Down