Skip to content

fix: use cache plugin#387

Merged
lazarv merged 2 commits intomainfrom
fix/use-cache-plugin
Apr 10, 2026
Merged

fix: use cache plugin#387
lazarv merged 2 commits intomainfrom
fix/use-cache-plugin

Conversation

@lazarv
Copy link
Copy Markdown
Owner

@lazarv lazarv commented Apr 10, 2026

The use-cache-inline plugin had several bugs in how it tracks closure variables and handles exported cached functions. The root cause was a flat locals array that accumulated variable names from all function scopes without any scoping — variables declared inside one function would leak into the closure capture list of completely unrelated sibling functions. This caused the plugin to emit invalid .bind() calls on module-level exported cached functions, producing parse errors like export __cache_name__.bind(null, src, selector, isolate) during production builds.

The fix replaces the flat locals array with a proper scope stack. Each non-cached function pushes a scope entry on enter and pops it on leave, so only variables from actual enclosing lexical scopes are considered for closure capture. Module-level cached functions now correctly see an empty scope stack and skip .bind() entirely.

Additional fixes included in this change: destructured binding patterns (ObjectPattern, ArrayPattern, AssignmentPattern, RestElement) are now properly walked when collecting local variable names. Function parameters in enclosing scopes are tracked for nested cached function closure capture. Identifiers in non-reference positions (object property keys, member expression properties, declaration ids, function names) are excluded from closure matching — this was necessary because the JSX transform runs before the cache plugin, turning JSX attribute names into regular Property key Identifiers that would otherwise be falsely captured. Exported cached functions are now wrapped in __react_cache__() at module level and get correct CACHE_KEY/CACHE_PROVIDER assignments using scoping-aware target resolution.

@github-actions
Copy link
Copy Markdown

⚡ Benchmark Results

PR 6073263 main 1c4cca1
Config 50 connections, 10s/test 50 connections, 10s/test
Benchmark Req/s vs main Avg Latency vs main P99 Latency Throughput
minimal 1354 🟢 +7.1% 36.36 ms 🟢 -6.7% 72 ms 0.8 MB/s
small 1433 🟢 +9.5% 34.31 ms 🟢 -8.9% 60 ms 1.3 MB/s
medium 343 🟢 +16.3% 144.72 ms 🟢 -13.9% 219 ms 5.0 MB/s
large 33 🟢 +18.0% 1473.35 ms 🟢 -15.1% 2913 ms 3.3 MB/s
deep 901 🟢 +13.9% 54.9 ms 🟢 -12.5% 94 ms 3.0 MB/s
wide 42 🟢 +21.8% 1151.71 ms 🟢 -15.4% 2275 ms 2.3 MB/s
cached 3618 🔴 -2.0% 13.26 ms 🔴 +1.8% 28 ms 52.8 MB/s
client-min 469 🔴 -2.2% 105.67 ms 🔴 +2.3% 161 ms 2.4 MB/s
client-small 477 🔴 -3.8% 103.85 ms 🔴 +4.3% 158 ms 2.6 MB/s
client-med 360 🟢 +1.7% 138.2 ms 🟢 -1.3% 201 ms 6.9 MB/s
client-large 90 🟢 +25.3% 549.98 ms 🟢 -19.0% 1027 ms 9.4 MB/s
client-deep 446 🔴 -3.8% 110.67 ms 🔴 +3.4% 173 ms 3.5 MB/s
client-wide 139 🟢 +16.2% 346.62 ms 🟢 -16.2% 575 ms 8.2 MB/s
static-json 7064 🔴 -35.9% 6.55 ms 🔴 +69.3% 16 ms 2.9 MB/s
static-js 7264 🔴 -33.8% 6.34 ms 🔴 +63.0% 15 ms 8.7 MB/s
404-miss 5062 🔴 -23.8% 9.51 ms 🔴 +36.8% 21 ms 0.6 MB/s
hybrid-min 464 🔴 -8.3% 106.88 ms 🔴 +8.9% 167 ms 2.6 MB/s
hybrid-small 436 🔴 -10.4% 113.77 ms 🔴 +11.9% 173 ms 2.9 MB/s
hybrid-medium 200 🟢 +3.3% 248.74 ms 🟢 -2.7% 354 ms 9.0 MB/s
hybrid-large 27 🟢 +20.7% 1769.15 ms 🟢 -11.6% 3387 ms 9.0 MB/s
hybrid-deep 345 🔴 -3.0% 143.12 ms 🔴 +3.1% 220 ms 5.1 MB/s
hybrid-wide 33 🟢 +8.9% 1416.89 ms 🟢 -8.8% 2487 ms 7.2 MB/s
hybrid-cached 2992 🟢 +4.2% 16.16 ms 🟢 -4.3% 31 ms 134.0 MB/s
hybrid-client-min 500 🔴 -2.7% 99.23 ms 🔴 +2.7% 144 ms 2.6 MB/s
hybrid-client-small 480 🔴 -4.7% 103.03 ms 🔴 +4.6% 148 ms 2.7 MB/s
hybrid-client-medium 355 🔴 -3.3% 139.75 ms 🔴 +3.9% 207 ms 6.8 MB/s
hybrid-client-large 82 🟢 +9.8% 582.26 ms 🟢 -11.5% 1051 ms 8.7 MB/s
hybrid-client-deep 433 🔴 -7.0% 114.02 ms 🔴 +6.8% 175 ms 3.4 MB/s
hybrid-client-wide 142 🟢 +15.6% 341.08 ms 🟢 -13.3% 557 ms 8.4 MB/s
Legend

🟢 > 1% improvement | 🔴 > 1% regression | ⚪ within noise margin

Benchmarks run on GitHub Actions runners (shared infrastructure) — expect ~5% variance between runs. Consistent directional changes across multiple routes are more meaningful than any single number.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
925 1 924 3
View the top 3 failed test(s) by shortest run time
__test__/scroll-restoration.spec.mjs > scroll restoration: multiple back/forward preserves positions
Stack Traces | 27.7s run time
AssertionError: expected 0 to be greater than 400
 ❯ __test__/scroll-restoration.spec.mjs:158:25
__test__/apps/react-query.spec.mjs > react-query load
Stack Traces | 150s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/react-query.spec.mjs:15:3
__test__/apps/mantine.spec.mjs > mantine > form > shows validation error on empty submit
Stack Traces | 223s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:99:7
__test__/apps/mantine.spec.mjs > mantine > home page > renders home page with Mantine UI
Stack Traces | 255s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:75:7
__test__/apps/mantine.spec.mjs > mantine > carousel > navigates carousel slides
Stack Traces | 255s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:222:7
__test__/apps/mantine.spec.mjs > mantine > dates > locale select changes date format
Stack Traces | 255s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:129:7
__test__/apps/mantine.spec.mjs > mantine > home page > increment button updates count
Stack Traces | 255s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:83:7
__test__/apps/mantine.spec.mjs > mantine > setup > start server
Stack Traces | 281s run time
Error: waitForHydration timed out after 60000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:63:9
__test__/apps/mantine.spec.mjs > mantine > modals manager > opens and confirms modal
Stack Traces | 286s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:274:7
__test__/apps/mantine.spec.mjs > mantine > navigation progress > shows progress bar on start
Stack Traces | 286s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:251:7
__test__/apps/mantine.spec.mjs > mantine > spotlight > opens spotlight and searches for items
Stack Traces | 286s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:184:7
__test__/apps/mantine.spec.mjs > mantine > dates > date input formats value
Stack Traces | 286s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:115:7
__test__/bun.spec.mjs > preset: blank-ts
Stack Traces | 300s run time
Error: Hook timed out in 300000ms.
If this is a long-running hook, pass a timeout value as the last argument or configure it globally with "hookTimeout".
 ❯ __test__/bun.spec.mjs:43:18
__test__/apps/mantine.spec.mjs > mantine > rich text editor > renders rich text editor content
Stack Traces | 318s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:313:7
__test__/apps/mantine.spec.mjs > mantine > charts > renders chart SVGs
Stack Traces | 318s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:153:7
__test__/apps/mantine.spec.mjs > mantine > notification system > shows notification on button click
Stack Traces | 318s run time
Error: waitForHydration timed out after 30000ms
 ❯ waitForHydration utils.mjs:117:13
 ❯ __test__/apps/mantine.spec.mjs:166:7

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@lazarv lazarv merged commit 0d059c7 into main Apr 10, 2026
107 of 110 checks passed
@lazarv lazarv deleted the fix/use-cache-plugin branch April 10, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants