@@ -277,6 +277,19 @@ const IframeContent: React.FC<IframeContentProps> = ({
277277 // Set up syntax error monitoring
278278 const model = editor . getModel ( ) ;
279279 if ( model ) {
280+ // Holds the timeout id for pending syntax-error checks so we can cancel
281+ // any previously scheduled run before queuing a new one. This acts as a
282+ // lightweight, manual debounce without bringing in lodash or a similar
283+ // utility.
284+ let syntaxErrorCheckTimeoutId : ReturnType < typeof setTimeout > | null = null ;
285+
286+ const scheduleSyntaxCheck = ( delay : number ) => {
287+ if ( syntaxErrorCheckTimeoutId !== null ) {
288+ clearTimeout ( syntaxErrorCheckTimeoutId ) ;
289+ }
290+ syntaxErrorCheckTimeoutId = setTimeout ( checkSyntaxErrors , delay ) ;
291+ } ;
292+
280293 const checkSyntaxErrors = ( ) => {
281294 // Get ALL markers for our model from all sources
282295 const allMarkers = monaco . editor . getModelMarkers ( {
@@ -296,21 +309,22 @@ const IframeContent: React.FC<IframeContentProps> = ({
296309 } ;
297310
298311 // Initial check after a short delay to allow language service to initialize
299- setTimeout ( checkSyntaxErrors , 100 ) ;
312+ scheduleSyntaxCheck ( 100 ) ;
300313
301314 // Listen for marker changes - check every time markers change
302315 const disposable = monaco . editor . onDidChangeMarkers ( ( uris ) => {
303316 // Check if our model's URI is in the changed URIs
304317 if ( uris . some ( ( uri ) => uri . toString ( ) === model . uri . toString ( ) ) ) {
305318 // Add a small delay to ensure markers are updated
306- setTimeout ( checkSyntaxErrors , 50 ) ;
319+ scheduleSyntaxCheck ( 50 ) ;
307320 }
308321 } ) ;
309322
310323 // Also listen for model content changes as a backup
311324 const contentDisposable = editor . onDidChangeModelContent ( ( ) => {
312- // Debounce content changes to avoid excessive checks
313- setTimeout ( checkSyntaxErrors , 500 ) ;
325+ // Queue a syntax check, cancelling any pending one, to avoid stacking
326+ // up checks during rapid typing.
327+ scheduleSyntaxCheck ( 500 ) ;
314328 } ) ;
315329
316330 disposablesRef . current . push ( disposable ) ;
0 commit comments