Skip to content

Commit

Permalink
fix (#3516)
Browse files Browse the repository at this point in the history
  • Loading branch information
urugator committed Sep 7, 2022
1 parent f0e066f commit 7260cd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-suns-listen.md
@@ -0,0 +1,5 @@
---
"mobx": patch
---

fix regression #3514: LegacyObservableArray compat with Safari 9.\*
21 changes: 21 additions & 0 deletions packages/mobx/src/types/legacyobservablearray.ts
Expand Up @@ -14,6 +14,21 @@ import {
defineProperty
} from "../internal"

// Bug in safari 9.* (or iOS 9 safari mobile). See #364
const ENTRY_0 = createArrayEntryDescriptor(0)

const safariPrototypeSetterInheritanceBug = (() => {
let v = false
const p = {}
Object.defineProperty(p, "0", {
set: () => {
v = true
}
})
Object.create(p)["0"] = 1
return v === false
})()

/**
* This array buffer contains two lists of properties, so that all arrays
* can recycle their property definitions, which significantly improves performance of creating
Expand Down Expand Up @@ -57,6 +72,12 @@ class LegacyObservableArray<T> extends StubArray {
this.spliceWithArray(0, 0, initialValues)
allowStateChangesEnd(prev)
}

if (safariPrototypeSetterInheritanceBug) {
// Seems that Safari won't use numeric prototype setter untill any * numeric property is
// defined on the instance. After that it works fine, even if this property is deleted.
Object.defineProperty(this, "0", ENTRY_0)
}
}

concat(...arrays: T[][]): T[] {
Expand Down

0 comments on commit 7260cd4

Please sign in to comment.