Skip to content

Commit

Permalink
Use the actual node count rather than the dirty node count (#3569)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Dec 17, 2022
1 parent 028612c commit 82dafbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
25 changes: 14 additions & 11 deletions packages/lexical-react/src/LexicalTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,23 @@ export function TreeView({
);

useEffect(() => {
setContent(
generateContent(
editor.getEditorState(),
editor._config,
editor._compositionKey,
editor._editable,
),
);
}, [editor]);
const editorState = editor.getEditorState();
if (!showLimited && editorState._nodeMap.size > 1000) {
setContent(
generateContent(
editorState,
editor._config,
editor._compositionKey,
editor._editable,
),
);
}
}, [editor, showLimited]);

useEffect(() => {
return mergeRegister(
editor.registerUpdateListener(({editorState, dirtyLeaves}) => {
if (!showLimited && dirtyLeaves.size > 1000) {
editor.registerUpdateListener(({editorState}) => {
if (!showLimited && editorState._nodeMap.size > 1000) {
lastEditorStateRef.current = editorState;
setIsLimited(true);
if (!showLimited) {
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2743,7 +2743,7 @@ export function updateDOMSelection(
domSelection: Selection,
tags: Set<string>,
rootElement: HTMLElement,
dirtyLeavesCount: number,
nodeCount: number,
): void {
const anchorDOMNode = domSelection.anchorNode;
const focusDOMNode = domSelection.focusNode;
Expand Down Expand Up @@ -2852,7 +2852,7 @@ export function updateDOMSelection(
// The downside is that is makes the computation within Lexical more
// complex, as now, we've sync update the DOM, but selection no longer
// matches.
if (IS_CHROME && dirtyLeavesCount > 1000) {
if (IS_CHROME && nodeCount > 1000) {
window.requestAnimationFrame(() =>
domSelection.setBaseAndExtent(
nextAnchorNode as Node,
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical/src/LexicalUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ export function commitPendingUpdates(editor: LexicalEditor): void {
const normalizedNodes = editor._normalizedNodes;
const tags = editor._updateTags;
const deferred = editor._deferred;
const dirtyLeavesCount = dirtyLeaves.size;
const nodeCount = pendingEditorState._nodeMap.size;

if (needsUpdate) {
editor._dirtyType = NO_DIRTY_NODES;
Expand Down Expand Up @@ -569,7 +569,7 @@ export function commitPendingUpdates(editor: LexicalEditor): void {
domSelection,
tags,
rootElement as HTMLElement,
dirtyLeavesCount,
nodeCount,
);
}
updateDOMBlockCursorElement(
Expand Down

2 comments on commit 82dafbe

@vercel
Copy link

@vercel vercel bot commented on 82dafbe Dec 17, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-fbopensource.vercel.app
lexical.dev
lexicaljs.org
lexical-git-main-fbopensource.vercel.app
lexicaljs.com
www.lexical.dev

@vercel
Copy link

@vercel vercel bot commented on 82dafbe Dec 17, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground.vercel.app
lexical-playground-fbopensource.vercel.app
playground.lexical.dev
lexical-playground-git-main-fbopensource.vercel.app

Please sign in to comment.