Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove settimeout from the controller and use requestAnimationFrame instead

Behrokh Satarnejad2c3485312b2c
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/scroll.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/scroll.controller.ts
index 4aa1aba2537..76a6e630184 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/scroll.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/relations-tab/scroll.controller.ts
@@ -1,18 +1,17 @@
import { Controller } from '@hotwired/stimulus';
export default class ScrollController extends Controller {
- static values = { targetId: String };
- declare targetIdValue:string;
-
connect() {
- // Wait to ensure DOM is fully loaded
- setTimeout(() => {
- if (this.targetIdValue) {
- const element = document.querySelector(`[data-test-selector='op-relation-row-${this.targetIdValue}']`) as HTMLElement;
- if (element) {
- element.scrollIntoView({ behavior: 'smooth', block: 'center' });
- }
- }
- });
+ this.waitForRenderAndAct();
+ }
+
+ waitForRenderAndAct() {
+ const element = document.querySelector('[data-scroll-active="true"]');
+
+ if (element) {
+ element.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ } else {
+ requestAnimationFrame(this.waitForRenderAndAct.bind(this));
+ }
}
}