Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename caches to commonCaches #628

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

lekoaf
Copy link

@lekoaf lekoaf commented Dec 14, 2023

Renames the caches variable because it interferes with the global browser API.

https://developer.mozilla.org/en-US/docs/Web/API/caches

Fixes #492

Renames the `caches` variable because
it interferes with the global browser
API.

Fixes benjamn#492
@@ -131,7 +131,7 @@ export interface OptionsWithCacheInstance<
cache: CommonCache<NoInfer<TCacheKey>, Entry<NoInfer<TArgs>, NoInfer<TResult>>>;
};

const caches = new Set<CommonCache<any, AnyEntry>>();
const commonCaches = new Set<CommonCache<any, AnyEntry>>();
Copy link
Author

Choose a reason for hiding this comment

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

__caches might be another alternative since it just seems like a local variable and it seems to be unintended to be accessed in the global scope.

@benjamn
Copy link
Owner

benjamn commented Dec 14, 2023

Can you say more about why this causes problems? In my understanding, index.ts is not global scope, but (gets compiled to) a JS module, so it has its own top-level module scope, distinct from global scope.

If the optimism package code is getting compiled to something other than ESM or CommonJS modules, and the top-level scopes of the modules are all becoming global, that's very much not the intended usage.

@steabert
Copy link

I wrote the #492 issue, but realize now I probably made a mistake when migrating from an IIFE bundle loaded as text/javascript to ESM with code splitting loaded as module. The only way I can reproduce the issue is if I create an ESM bundle and then load it as text/javascript in the browser. Since it's bundled, there are no ESM features that could trip up the browser, so I didn't notice that.

Thanks for pointing in the right direction!

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.

caches collides with the Browser API
3 participants