From 7cb427738c97acefeefa421874359f614fb3952d Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Wed, 20 Dec 2023 11:48:05 +0000 Subject: [PATCH] [ide-react] Only call scope watcher with the latest value from each batch (#16296) GitOrigin-RevId: 0284f99130424d50a2115853d793979a2b0387ff --- .../components/editor-navigation-toolbar-root.jsx | 2 +- .../scope-value-store/react-scope-value-store.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.jsx b/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.jsx index fe3b28a07d..ddd1d8a16e 100644 --- a/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.jsx +++ b/services/web/frontend/js/features/editor-navigation-toolbar/components/editor-navigation-toolbar-root.jsx @@ -71,7 +71,7 @@ const EditorNavigationToolbarRoot = React.memo( eventTracking.sendMB('navigation-clicked-chat', { action: isOpentoString(!chatIsOpen), }) - setChatIsOpen(value => !value) + setChatIsOpen(!chatIsOpen) }, [chatIsOpen, setChatIsOpen, markMessagesAsRead]) const toggleReviewPanelOpen = useCallback( diff --git a/services/web/frontend/js/features/ide-react/scope-value-store/react-scope-value-store.ts b/services/web/frontend/js/features/ide-react/scope-value-store/react-scope-value-store.ts index e61131ab80..3673af4721 100644 --- a/services/web/frontend/js/features/ide-react/scope-value-store/react-scope-value-store.ts +++ b/services/web/frontend/js/features/ide-react/scope-value-store/react-scope-value-store.ts @@ -60,7 +60,7 @@ export class ReactScopeValueStore implements ScopeValueStore { private readonly items = new Map() private readonly persisters: Map = new Map() - private watcherUpdates: WatcherUpdate[] = [] + private watcherUpdates = new Map() private watcherUpdateTimer: number | null = null private allowedNonExistentPaths: AllowedNonExistentPath[] = [] @@ -129,8 +129,8 @@ export class ReactScopeValueStore implements ScopeValueStore { this.watcherUpdateTimer = null } // Clone watcherUpdates in case a watcher creates new watcherUpdates - const watcherUpdates = [...this.watcherUpdates] - this.watcherUpdates = [] + const watcherUpdates = [...this.watcherUpdates.values()] + this.watcherUpdates = new Map() for (const { value, watchers } of watcherUpdates) { for (const watcher of watchers) { if (!watcher.removed) { @@ -152,7 +152,7 @@ export class ReactScopeValueStore implements ScopeValueStore { path, watchers: [...watchers], } - this.watcherUpdates.push(update) + this.watcherUpdates.set(path, update) if (!this.watcherUpdateTimer) { this.watcherUpdateTimer = window.setTimeout(() => { this.watcherUpdateTimer = null @@ -166,6 +166,7 @@ export class ReactScopeValueStore implements ScopeValueStore { } private setValue(path: string, value: T): void { + debugConsole.log('setValue', path, value) let item = this.items.get(path) if (item === undefined) { item = { value, watchers: [] }