-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Another approach to fixing the className cache #4582
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I wonder to what extent we want to promote immutability for user's input such as a theme (but I know this was already there)
@@ -1014,6 +1014,14 @@ export function getCachedClassNameArray( | |||
classNamesTheme: EditorThemeClasses, | |||
classNameThemeType: string, | |||
): Array<string> { | |||
if (classNamesTheme.__lexicalClassNameCache === undefined) { | |||
classNamesTheme.__lexicalClassNameCache = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, why an object vs a Map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, because every other (nested) property is an object, I guess. It looks like one property is inexplicably typed as a Record, which might be how the whole theme should be typed, but let's revisit this when we discuss this issue more broadly later.
@@ -1022,7 +1030,7 @@ export function getCachedClassNameArray( | |||
// applied to classList.add()/remove(). | |||
if (typeof classNames === 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does cache work for the nested ones? Or we don't really support this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s a good point. I’m gonna try to just get rid of this caching. It’s only here to make dealing with DOMTokenList APIs easier and still performant. It might have outlived it’s usefulness.
The "cache" for getCachedClassNameArray is the theme itself. We mutate the theme object provided in the initial config, which is problematic because it can cause runtime type errors when we're looking for a string when accessing the theme properties directly, but instead we get an array.
This approach (vs #4581 ) has the advantage of leveraging the theme to keep the cache scoped to the Editor, disadvantage of still mutating the theme object, although collision probability seems low.