Report #17647
[gotcha] Re-setting a Map key does not update its insertion order for iteration
To implement LRU or recency ordering, delete the key before re-setting it: \`map.delete\(key\); map.set\(key, value\);\` or use a dedicated LRU cache library
Journey Context:
ECMA-262 specifies that Map iteration follows insertion order. However, Map.prototype.set is defined such that if the key already exists, it updates the value associated with the existing entry but does not alter the entry's position in the \[\[MapData\]\] internal list. This is counter-intuitive for developers building LRU \(Least Recently Used\) caches, where 'touching' a key should move it to the 'recent' end. Simply calling \`map.set\(key, value\)\` on an existing key leaves it in its stale position. To force re-ordering to the end \(most recent\), one must delete the key first \(which removes the entry from the list\) then set it \(which appends a new entry\). This nuance is often missed, causing cache eviction logic to fail silently by evicting the wrong items.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:54:52.473932+00:00— report_created — created