Skip to content

Iterator.prototype.flatMap FORCED check misses Safari 18.6 and 26.0.x bug(s) #1538

Closed

Description

@markedwards

Iterator.prototype.flatMap throws TypeError: undefined is not a function on Safari 18.6 and 26.0.x when consumed by a short-circuiting helper over arrays. With import "core-js/actual", the FORCED check sees a callable native and skips installation, so the buggy native runs.

Reproduction (throws on Safari 18.6 and 26.0.1, passes elsewhere):

[1].values().flatMap(() => [1]).find(() => true);

Cause:

Apple's Safari 26.2 release notes describe the 26.x bug: "Fixed Iterator.prototype.flatMap to properly handle iterators without a return method" (rdar://158783404). The 18.x failure is not separately documented but the same probe triggers and the same workaround resolves it — either the same bug exists undocumented in 18.x, or a different bug surfaces similarly. Either way, behavioral detection catches both.

Proposed fix:

Add a probe to the FORCED check for es.iterator.flat-map:

var FAILS_ON_INNER_RETURN = !function () {
  try {
    [1].values().flatMap(function () { return [1]; }).find(function () { return true; });
    return true;
  } catch (e) { return false; }
}();

Workaround currently in production use:

if (typeof Iterator !== "undefined" && typeof Iterator.prototype.flatMap === "function") {
  try { [1].values().flatMap(() => [1]).find(() => true); }
  catch { Reflect.deleteProperty(Iterator.prototype, "flatMap"); }
}
import "core-js/actual";

Environment:

core-js 3.49.0, Safari 18.6 and 26.0.1, Next.js 16.2 / Turbopack.

Activity

  1. zloirock commented on May 5, 2026

    @zloirock
    Owner

    Thanks. Could you add a PR?

  2. zloirock commented on Jul 25, 2026

    @zloirock
    Owner

    Are you sure that it's still present in the actual core-js version? Since that refers to https://bugs.webkit.org/show_bug.cgi?id=297532, which was fixed in core-js@3.48.

  3. zloirock commented on Jul 25, 2026

    @zloirock
    Owner

    It seems that in this WebKit ticket was only a part of this issue.

    Image
  4. added a commit that references this issue on Jul 25, 2026
    276de47
  5. markedwards commented on Jul 25, 2026

    @markedwards
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions