facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

Clamp number of registered editor above 0 #6001

Closed thegreatercurve closed 2 weeks ago

thegreatercurve commented 2 weeks ago

Description

Since #5070, there are certain circumstances in which the document counts for rootElementsRegistered can fall below 0, especially if removeRootElementEvents is called more than addRemoveRootElementEvents.

As number of registered root elements should never be fewer than 1 after addRemoveRootElementEvents is called, and because the number of root elements should never be fewer than 0 when removeRootElementEvents is called, we should clamp these values.

vercel[bot] commented 2 weeks ago

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

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2024 8:41pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2024 8:41pm
github-actions[bot] commented 2 weeks ago

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/lexical/dist/Lexical.js 23.69 KB (0%) 474 ms (0%) 494 ms (+34.45% 🔺) 968 ms
packages/lexical-rich-text/dist/LexicalRichText.js 33.99 KB (+0.23% 🔺) 680 ms (+0.23% 🔺) 1.3 s (+22.31% 🔺) 2 s
packages/lexical-plain-text/dist/LexicalPlainText.js 33.95 KB (+0.16% 🔺) 679 ms (+0.16% 🔺) 1.1 s (-17.01% 🔽) 1.8 s
Daniel15 commented 2 weeks ago

We should probably have an invariant rather than just clamping, so we can more easily find any bad code that causes this condition.

thegreatercurve commented 2 weeks ago

Closing in favour of https://github.com/facebook/lexical/pull/6003