Skip to content

fix(utils): add size cap to routePrefetch prefetchCache Map to prevent memory leak #58

Description

@tmdeveloper007

Summary of What Needs to be Done

src/utils/routePrefetch.js uses a module-level prefetchCache Map to store dynamic import promises. There is no cap on the number of entries — over time, as users navigate through the app and different routes are prefetched, the Map grows indefinitely. In long-running sessions or SPAs, this causes unbounded memory growth.

Changes

Add a MAX_PREFETCH_CACHE_SIZE constant (e.g., 50) and evict the oldest entry when the cap is exceeded, similar to the fix already applied in prefetchUtils.js.

Impact

  • Memory leak: The prefetchCache Map grows without bound as users navigate, eventually exhausting browser memory in long-running sessions.
  • Note: prefetchUtils.js already has this fix applied; routePrefetch.js is the older module that needs the same treatment.

Please assign this task to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssoc:approvedApproved for GSSoC contributionlevel:beginnerSmall, low-risk change (≤3 files, ≤50 lines)type:bugSomething is broken or incorrect

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions