Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions modules/mobianRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ const logMessage = (...args) => {
};

function makeMemoizedFetch() {
let cachedResponse = null;
const cache = new Map();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound URL cache size to prevent unbounded memory growth

The new per-URL memoization uses a process-lifetime Map with no eviction, so long-lived SPA sessions that continuously change window.location.href will accumulate entries indefinitely and retain all prior context payloads in memory. This is a regression from the previous single-entry cache footprint and can degrade performance over time in production; consider limiting the cache (e.g., last URL only, TTL, or LRU max size).

Useful? React with 👍 / 👎.

Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL-based cache implemented as an unbounded Map can lead to a memory leak in single-page applications. As the user navigates to different URLs, the cache will grow indefinitely without any cleanup mechanism or size limits. Consider implementing a cache size limit (e.g., LRU cache) or a time-based expiration strategy to prevent unbounded memory growth.

Copilot uses AI. Check for mistakes.
return async function () {
if (cachedResponse) {
return Promise.resolve(cachedResponse);
const pageUrl = window.location.href;
if (cache.has(pageUrl)) {
return Promise.resolve(cache.get(pageUrl));
}
try {
const response = await fetchContextData();
cachedResponse = makeDataFromResponse(response);
const cachedResponse = makeDataFromResponse(response);
cache.set(pageUrl, cachedResponse);
return cachedResponse;
Comment on lines 67 to 78
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL-based caching behavior should be covered by tests. Consider adding test cases that verify: 1) different URLs result in different cache entries, 2) subsequent calls with the same URL return cached data without making additional API calls, and 3) URL changes trigger new API calls. This will ensure the SPA behavior works as intended.

Copilot uses AI. Check for mistakes.
} catch (error) {
logMessage('error', error);
Expand Down