Portal Community

Automatic Cleanup

The following subscriptions are cleaned up automatically by the EdgeInteract packages:

SubscriptionCleaned Up WhenManaged By
interactions.{userId}On InteractionProvider unmount or EdgeStream disconnectInteractionProvider
interactions.dismiss.{userId}On InteractionProvider unmountInteractionProvider
interactions.callback.{interactionId}After response or timeout receivedInteractionPipeline (server)
interactions.ack.{interactionId}After ack received or ack timeoutInteractionResponsePublisher (client)

React Cleanup via useEffect

When using the React bindings, cleanup is handled automatically via React's useEffect cleanup function. The InteractionProvider ensures all subscriptions are cleaned up on unmount:

// Inside InteractionProvider (simplified)
useEffect(() => {
  const subscriber = new InteractionSubscriber();
  subscriber.start(currentUser.id, interactionQueue);

  return () => {
    // Cleanup runs on unmount or when currentUser.id changes
    subscriber.stop();
  };
}, [currentUser.id]);

Manual Cleanup for Custom Subscriptions

If you create your own EdgeStream subscriptions for interaction topics (not recommended — use the provided hooks), you must clean them up manually:

// Manual subscription cleanup — only if bypassing the built-in provider
const sub = await edgeStreamClient.subscribe('interactions.custom.topic', handler);

// In cleanup / useEffect return:
return () => {
  sub.unsubscribe();
};

Verifying No Subscription Leaks

The EdgeInteract observability package exposes an active subscription count. Use the InteractionMonitor component to verify:

The Golden Rule If you are using InteractionProvider and the built-in React hooks, subscription cleanup is fully automatic. You only need to worry about cleanup if you bypass the provider and use the client package directly.