Skip to content

Commit 6c7e68b

Browse files
committed
fix: stop setInterval polling after all reactive features are initialized #3251
1 parent 655fd55 commit 6c7e68b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/injected.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,22 @@ const start = async () => {
577577

578578
// Call setupReactiveFeatures immediately and then periodically check for new modules
579579
setupReactiveFeatures();
580-
setInterval(setupReactiveFeatures, 1000); // Check every second for newly loaded modules
580+
581+
// Self-rescheduling timeout that stops once all features are initialized
582+
const scheduleSetupCheck = () => {
583+
const allFeaturesSetup = Object.values(setupFlags).every((flag) => flag);
584+
585+
if (!allFeaturesSetup) {
586+
setupReactiveFeatures();
587+
setTimeout(scheduleSetupCheck, 1000);
588+
} else {
589+
console.log(
590+
'[Rocket.Chat Desktop] All reactive features initialized, stopping polling'
591+
);
592+
}
593+
};
594+
595+
scheduleSetupCheck();
581596

582597
console.log('[Rocket.Chat Desktop] Injected');
583598
};

0 commit comments

Comments
 (0)