ChunDe Claude Sonnet 4.5 commited on
Commit
aab4229
·
1 Parent(s): 49059bc

fix: Add retry mechanism and timing delays for React state sync

Browse files

- Wait 1 second after layout load for React to process
- Retry listObjects up to 3 times to ensure state is available
- Add 0.5s delays after adding new text objects
- Keep 2s wait before final export

Fixes timing issues where text updates weren't reflected in export.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

Files changed (1) hide show
  1. mcp_server_comprehensive.py +21 -4
mcp_server_comprehensive.py CHANGED
@@ -416,10 +416,18 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
416
  result = await execute_api_call(page, "loadLayout", layout_id, {})
417
  results.append({"step": "load_layout", "result": result})
418
 
 
 
 
419
  # Update title if specified
420
  if title:
421
- # Get all objects to find text objects
422
- objects_result = await execute_api_call(page, "listObjects", {})
 
 
 
 
 
423
  if objects_result.get("success"):
424
  objects = objects_result.get("objects", [])
425
  text_objects = [obj for obj in objects if obj.get("type") == "text"]
@@ -448,11 +456,18 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
448
  "fontWeight": "bold"
449
  })
450
  results.append({"step": "add_new_title"})
 
 
451
 
452
  # Update subtitle if specified
453
  if subtitle:
454
- # Get all objects to find subtitle text
455
- objects_result = await execute_api_call(page, "listObjects", {})
 
 
 
 
 
456
  if objects_result.get("success"):
457
  objects = objects_result.get("objects", [])
458
  text_objects = [obj for obj in objects if obj.get("type") == "text"]
@@ -485,6 +500,8 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
485
  "backgroundColor": first_subtitle.get("backgroundColor", "#000000")
486
  })
487
  results.append({"step": "add_new_subtitle"})
 
 
488
 
489
  # Add Huggy if specified
490
  if huggy_id:
 
416
  result = await execute_api_call(page, "loadLayout", layout_id, {})
417
  results.append({"step": "load_layout", "result": result})
418
 
419
+ # Wait for React state to update and objects to be available
420
+ await asyncio.sleep(1)
421
+
422
  # Update title if specified
423
  if title:
424
+ # Get all objects to find text objects (with retry for React state sync)
425
+ objects_result = None
426
+ for attempt in range(3):
427
+ objects_result = await execute_api_call(page, "listObjects", {})
428
+ if objects_result.get("success") and objects_result.get("count", 0) > 0:
429
+ break
430
+ await asyncio.sleep(0.5)
431
  if objects_result.get("success"):
432
  objects = objects_result.get("objects", [])
433
  text_objects = [obj for obj in objects if obj.get("type") == "text"]
 
456
  "fontWeight": "bold"
457
  })
458
  results.append({"step": "add_new_title"})
459
+ # Wait for new text to render
460
+ await asyncio.sleep(0.5)
461
 
462
  # Update subtitle if specified
463
  if subtitle:
464
+ # Get all objects to find subtitle text (with retry)
465
+ objects_result = None
466
+ for attempt in range(3):
467
+ objects_result = await execute_api_call(page, "listObjects", {})
468
+ if objects_result.get("success") and objects_result.get("count", 0) > 0:
469
+ break
470
+ await asyncio.sleep(0.5)
471
  if objects_result.get("success"):
472
  objects = objects_result.get("objects", [])
473
  text_objects = [obj for obj in objects if obj.get("type") == "text"]
 
500
  "backgroundColor": first_subtitle.get("backgroundColor", "#000000")
501
  })
502
  results.append({"step": "add_new_subtitle"})
503
+ # Wait for new text to render
504
+ await asyncio.sleep(0.5)
505
 
506
  # Add Huggy if specified
507
  if huggy_id: