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

Do not use global cache for createCache() to avoid memory leaks #3110

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-dancers-wash.md
@@ -0,0 +1,5 @@
---
'@emotion/cache': patch
---

Ensure that caches are not reused for different createCache calls
18 changes: 9 additions & 9 deletions packages/cache/src/index.js
Expand Up @@ -32,18 +32,18 @@ export type Options = {
insertionPoint?: HTMLElement
}

let getServerStylisCache = isBrowser
? undefined
: weakMemoize(() =>
memoize(() => {
let cache = {}
return name => cache[name]
})
)

const defaultStylisPlugins = [prefixer]

let createCache = (options: Options): EmotionCache => {
let getServerStylisCache = isBrowser
? undefined
: weakMemoize(() =>
memoize(() => {
let cache = {}
return cache
})
)

let key = options.key

if (process.env.NODE_ENV !== 'production' && !key) {
Expand Down