Skip to content

fix(GraphPlayground): skip editor updates for multi-block selections - #223

Open
180107072 wants to merge 1 commit into
gravity-ui:mainfrom
180107072:main
Open

fix(GraphPlayground): skip editor updates for multi-block selections#223
180107072 wants to merge 1 commit into
gravity-ui:mainfrom
180107072:main

Conversation

@180107072

@180107072180107072 commented Jan 25, 2026

Copy link
Copy Markdown

Problem

freezes when selecting 10 000 blocks

Why it happens

findBlockPositionsMonaco performs document search for each block

Solution

skip editor updates when updating multiple blocks editor highlighting only works for single selections

@180107072

Copy link
Copy Markdown
Author

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=ru.

@gravity-ui-bot

Copy link
Copy Markdown
Contributor

Preview is ready.

@draedful

Copy link
Copy Markdown
Collaborator

Hi, thanks for your contribution. I have looked at your suggestion and have some ideas. The fact is that when dragging blocks the updateBlocks() method is called on each block individually, so the current change doesn't affect the mass drag of blocks - the events are triggered for each block separately.

editorRef?.current.updateBlocks([block]);

Therefore, to solve this problem, you need to accumulate the blocks currently in the drag state, but the event block-changed is not suitable because of the granularity of changes.

graph.addEventListener('block-changed',()=>{// listen for changes to one block only// do something with the block});

Instead, I

Instead of using events, I would suggest using the DragService state to calculate the list of dragged blocks. Here's an example:

constlastDraggedBlocks=React.useRef<Array<TBlock>>([]);useEffect(()=>{// run this effect every time the graph changesgraph.dragService.state.subscribe(value=>{// at the end of a drag, update blocks in editorif(!value?.isDragging){// if no longer draggingif(lastDraggedBlocks.current){// check if we have any blockseditorRef?.updateBlocks(...lastDragged);// update editor with blockslastDragged.current=[];// clear list}}else{// during dragconstblocks=value?.components?.filter(c=>cinstanceofTBlock);// get blocks from draglastDragged?.current=blocks?.map(b=>b?.connectedState?.value);// add to list// if only one block, update editorif(blocks?.length===1){conststate=blocks?.[0]?.connectedState.value;// get state of blockeditor?.updateBlocks?.([state])// update editoreditor.scrollTo?.(state?.id)// scroll to block}}});},[graph])

In this approach, it is easier to calculate the blocks in the drag state and correctly process the editor updates.

@draedfuldraedful left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, thanks for the suggestion, but this problem cannot be solved by a simple check. I have described the reasons and solutions above.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@180107072@gravity-ui-bot@draedful