From 053efb61f08df95b60c82397c50de38bfea8dec1 Mon Sep 17 00:00:00 2001 From: donteatfriedrice Date: Thu, 5 Jun 2025 02:28:32 +0000 Subject: [PATCH] fix(editor): should set event dispatcher active as false when document is hidden (#12559) ## Summary by CodeRabbit - **New Features** - The application now automatically becomes inactive when the document is hidden, improving resource management and responsiveness to visibility changes. --- blocksuite/framework/std/src/event/dispatcher.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blocksuite/framework/std/src/event/dispatcher.ts b/blocksuite/framework/std/src/event/dispatcher.ts index 82ce2fee74..8d567893c7 100644 --- a/blocksuite/framework/std/src/event/dispatcher.ts +++ b/blocksuite/framework/std/src/event/dispatcher.ts @@ -220,6 +220,12 @@ export class UIEventDispatcher extends LifeCycleWatcher { this._setActive(false); }); + // When the document is hidden, the event dispatcher should be inactive + this.disposables.addFromEvent(document, 'visibilitychange', () => { + if (document.visibilityState === 'hidden') { + this._setActive(false); + } + }); } private _buildEventScopeBySelection(name: EventName) {