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

Another approach to fixing the className cache #4582

Merged
merged 1 commit into from
May 31, 2023
Merged

Another approach to fixing the className cache #4582

merged 1 commit into from
May 31, 2023

Conversation

acywatson
Copy link
Contributor

@acywatson acywatson commented May 30, 2023

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.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 30, 2023
@vercel
Copy link

vercel bot commented May 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview May 30, 2023 9:30pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2023 9:30pm

@github-actions
Copy link

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/lexical/dist/Lexical.js 27.89 KB (+0.13% 🔺) 558 ms (+0.13% 🔺) 219 ms (-20.42% 🔽) 776 ms
packages/lexical-rich-text/dist/LexicalRichText.js 38.82 KB (+0.1% 🔺) 777 ms (+0.1% 🔺) 377 ms (-48.08% 🔽) 1.2 s
packages/lexical-plain-text/dist/LexicalPlainText.js 38.8 KB (+0.1% 🔺) 776 ms (+0.1% 🔺) 333 ms (-46.59% 🔽) 1.2 s

Copy link
Member

@zurfyx zurfyx left a 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 = {};
Copy link
Member

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?

Copy link
Contributor Author

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') {
Copy link
Member

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?

Copy link
Contributor Author

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.

@acywatson acywatson merged commit 00e8fbc into main May 31, 2023
@fantactuka fantactuka deleted the fix-cache branch July 6, 2023 20:15
@zurfyx zurfyx mentioned this pull request Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants