question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map.prototype.forEach fires the callback for an empty Map

See original GitHub issue

This bug in the polyfill impacts React 16 users, and we are shipping React 16 very soon.

Specifically, Map.prototype.forEach attempts to skip deleted items but then always calls the callback. The problem is that it may be the case that all items were deleted, in which case it should have skipped the callback. In other words, this check should be done just before calling the callback as well.

Specific reproducing case:

var x = new Map();
x.set(42, 'hi');
x.delete(42);
x.forEach(function() {
  throw new Error('Should never get here!');
});

This breaks with the provided Map polyfill but works with the native implementation.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
JSteunoucommented, Oct 4, 2017

@green-arrow 3.22 was shipped with the fix

2reactions
gaearoncommented, Sep 27, 2017

Yeah, I didn’t meant to be pushing 😃. Just letting you know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Map.prototype.forEach() - JavaScript - MDN Web Docs - Mozilla
The forEach method executes the provided callback once for each key of the map which actually exist. It is not invoked for keys...
Read more >
Why when apply Map.prototype.forEach will return undefined?
It means the function forEach will execute the provided function f and nothing ... If the callback returns a value, this will be...
Read more >
Deep Dive into JavaScript's Array Map Method - Robin Wieruch
While forEach does iterate through the entire array and it does execute its callback function once for every item in the array, there's...
Read more >
Creating a .map() Method for Objects, Strings, Sets, and Maps
First, let's add an empty .map() method to the Object prototype. ... argument: the callback method we'd like to fire on each of...
Read more >
Map.prototype.forEach() - JavaScript - UDN Web Docs: MDN Backup
The forEach method executes the provided callback once for each key of the map which actually exist. It is not invoked for keys...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found