Uh oh!
There was an error while loading. Please reload this page.
fix(GraphPlayground): skip editor updates for multi-block selections - #223
fix(GraphPlayground): skip editor updates for multi-block selections#223180107072 wants to merge 1 commit into
Conversation
180107072
commented
Jan 25, 2026
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=ru. |
gravity-ui-bot
commented
Jan 25, 2026
Preview is ready. |
draedful
commented
Jan 28, 2026
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. 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. |
draedful
left a comment
There was a problem hiding this comment.
Hi, thanks for the suggestion, but this problem cannot be solved by a simple check. I have described the reasons and solutions above.
Problem
freezes when selecting 10 000 blocks
Why it happens
findBlockPositionsMonacoperforms document search for each blockSolution
skip editor updates when updating multiple blocks editor highlighting only works for single selections