code: def _find_widget_refs_by_state(widget, state):
      
      # Copy keys to allow changes to state during iteration:
      keys = tuple(state.keys())
      for key in keys:
          value = getattr(widget, key)
          # Trivial case: Direct references to other widgets:
          if isinstance(value, Widget):
              yield value
          # Also check for buried references in known, JSON-able structures
          # Note: This might miss references buried in more esoteric structures
          elif isinstance(value, (list, tuple)):
              for item in value:
                  if isinstance(item, Widget):
                      yield item
          elif isinstance(value, dict):
              for item in value.values():
                  if isinstance(item, Widget):
                      yield item
docs: Find references to other widgets in a widget's state