From 4c077738776d5fc7ba0f108805a9ec816c2709b9 Mon Sep 17 00:00:00 2001 From: Antoine Eskaros Date: Wed, 16 Oct 2024 23:20:04 +1100 Subject: [PATCH] Fix(mobx): Safer method to consume Iterator.prototype (#3943) * Fix browser incompatability issue introduced in mobx 6.13.4 * No need for bracket notiation * Proper fallback --- .changeset/five-news-hammer.md | 5 +++++ packages/mobx/src/utils/iterable.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/five-news-hammer.md diff --git a/.changeset/five-news-hammer.md b/.changeset/five-news-hammer.md new file mode 100644 index 000000000..e7f7792a4 --- /dev/null +++ b/.changeset/five-news-hammer.md @@ -0,0 +1,5 @@ +--- +"mobx": patch +--- + +Fix browser compatability issue introduced in 6.13.4 release diff --git a/packages/mobx/src/utils/iterable.ts b/packages/mobx/src/utils/iterable.ts index c05384ef0..59463bb47 100644 --- a/packages/mobx/src/utils/iterable.ts +++ b/packages/mobx/src/utils/iterable.ts @@ -1,5 +1,15 @@ +import { getGlobal } from "../internal" + +// safely get iterator prototype if available +const maybeIteratorPrototype = getGlobal().Iterator?.prototype || {} + export function makeIterable( iterator: Iterator ): IteratorObject { - return Object.assign(Object.create(Iterator.prototype), iterator) + iterator[Symbol.iterator] = getSelf + return Object.assign(Object.create(maybeIteratorPrototype), iterator) +} + +function getSelf() { + return this }