Skip to content

[eprh] Fix LRUCache.get() overwriting entries when promoting a hit - #38439

Open
lazerg wants to merge 2 commits into
react:mainfrom
lazerg:fix/issue-38437-lru-cache
Open

lazerg wants to merge 2 commits into
react:mainfrom
lazerg:fix/issue-38437-lru-cache

Conversation

@lazerg

@lazerg lazerg commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

LRUCache.get() shifted entries forward starting from the head when moving a hit to the front. That overwrote the slot right behind the head before it was read and then copied the old head into every following slot. The loop bound also used the raw array index instead of the distance from the head. So reading a cached file that wasn't the most recent one evicted other cached files, and with 10 entries the cache could drop to 2 unique files. Editors and watch mode that switch between files kept recompiling files that were already cached.

This shifts backward from the hit to the head over the circular distance, so the other entries keep their order.

Fixes #38437

How did you test this change?

Added LRUCache-test.js, covering a non-head hit, a hit across the end of the array, and LRU eviction order. All three fail before the change and pass after it. yarn workspace eslint-plugin-react-hooks test passes.

@meta-cla meta-cla Bot added the CLA Signed label Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Comparing: edae846...a692d50

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 7.35 kB 7.35 kB +0.05% 1.96 kB 1.96 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 628.58 kB 628.58 kB = 110.98 kB 110.98 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.36 kB 7.36 kB = 1.96 kB 1.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 699.69 kB 699.69 kB = 122.41 kB 122.41 kB
facebook-www/ReactDOM-prod.classic.js = 717.77 kB 717.77 kB = 125.46 kB 125.47 kB
facebook-www/ReactDOM-prod.modern.js = 708.11 kB 708.11 kB = 123.88 kB 123.88 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by sizebot against a692d50

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[eslint-plugin-react-hooks] LRUCache.get() overwrites cached entries when promoting a non-head hit

1 participant