Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3514: legacy array compat with Safari 9 #3516

Merged
merged 1 commit into from
Sep 7, 2022
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/fresh-suns-listen.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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