@@ -7,12 +7,17 @@ import { isValidCslp } from "../../cslp/cslpdata";
77import { setHighlightVariantFields } from "./useVariantsPostMessageEvent" ;
88import visualBuilderPostMessage from "../utils/visualBuilderPostMessage" ;
99import { VisualBuilderPostMessageEvents } from "../utils/types/postMessage.types" ;
10+ import { debounce } from "lodash-es" ;
1011
1112const VARIANT_UPDATE_DELAY_MS : Readonly < number > = 8000 ;
12- // Debounce window after the last observed mutation before asking the visual
13- // editor to re-send discussion highlights. Short enough to feel responsive;
14- // long enough to coalesce a burst of mutations into a single request.
15- const DISCUSSION_HIGHLIGHTS_DEBOUNCE_MS : Readonly < number > = 200 ;
13+
14+ // Coalesce a burst of data-cslp mutations into a single request to the
15+ // visual editor.
16+ const requestDiscussionHighlights = debounce ( ( ) => {
17+ visualBuilderPostMessage ?. send (
18+ VisualBuilderPostMessageEvents . REQUEST_DISCUSSION_HIGHLIGHTS
19+ ) ;
20+ } , 200 ) ;
1621
1722type OnAudienceModeVariantPatchUpdate = {
1823 highlightVariantFields : boolean ;
@@ -38,21 +43,6 @@ export function updateVariantClasses(): void {
3843 const variant = VisualBuilder . VisualBuilderGlobalState . value . variant ;
3944 const observers : MutationObserver [ ] = [ ] ;
4045
41- // Ask the visual editor to re-send discussion highlights once the current
42- // burst of data-cslp mutations has settled. The VB owns the field-path list
43- // (it can be per-variant) so the iframe cannot re-mount comment icons on
44- // its own — it can only request a refresh.
45- let highlightsRequestTimer : ReturnType < typeof setTimeout > | null = null ;
46- const requestDiscussionHighlights = ( ) => {
47- if ( highlightsRequestTimer !== null ) clearTimeout ( highlightsRequestTimer ) ;
48- highlightsRequestTimer = setTimeout ( ( ) => {
49- highlightsRequestTimer = null ;
50- visualBuilderPostMessage ?. send (
51- VisualBuilderPostMessageEvents . REQUEST_DISCUSSION_HIGHLIGHTS
52- ) ;
53- } , DISCUSSION_HIGHLIGHTS_DEBOUNCE_MS ) ;
54- } ;
55-
5646 // Helper function to update element classes
5747 const updateElementClasses = (
5848 element : HTMLElement ,
0 commit comments