Skip to content

Commit 34cd210

Browse files
authored
fix: canvas autoscroll issue when selecting instances (#4174)
## Description closes #4169 ## Steps for reproduction Shoud be tested well as having various scroll/resize/mutation obserevers we have, everything can cause infinite cycle ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 334caf4 commit 34cd210

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

apps/builder/app/canvas/collapsed.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ const recalculate = () => {
179179
}
180180
}
181181

182+
// If most elements are collapsed at the next step, scrollHeight becomes equal to clientHeight,
183+
// which resets the scroll position. To prevent this, we set the document's height to the current scrollHeight
184+
// to preserve the scroll position.
185+
const preserveHeight = document.documentElement.style.height;
186+
document.documentElement.style.height = `${document.documentElement.scrollHeight}px`;
187+
182188
// Now combine all operations in batches.
183189

184190
// 1. Remove all collapsed attributes
@@ -222,6 +228,8 @@ const recalculate = () => {
222228
for (const [element, value] of collapsedElements.entries()) {
223229
element.setAttribute(collapsedAttribute, value);
224230
}
231+
232+
document.documentElement.style.height = preserveHeight;
225233
};
226234

227235
/**

0 commit comments

Comments
 (0)