@xstate-devtools/adapter 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core.ts +27 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate-devtools/adapter",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "exports": {
package/src/core.ts CHANGED
@@ -571,6 +571,33 @@ export function createInspector(
571
571
  const sessionId: string = actorRef.sessionId
572
572
  actorRefs.set(sessionId, actorRef)
573
573
 
574
+ // Eagerly remove the actor from both maps when it stops so we don't
575
+ // accumulate strong references to every short-lived actor indefinitely.
576
+ // Without this, actors that stop silently (no further snapshot/event) are
577
+ // only removed by checkAndNotifyStop — which never fires for them.
578
+ try {
579
+ actorRef.subscribe({
580
+ complete: () => {
581
+ if (actorRefs.has(sessionId)) {
582
+ actorRefs.delete(sessionId)
583
+ actorMachines.delete(sessionId)
584
+ const stopMsg: PageToExtensionMessage = {
585
+ type: 'XSTATE_ACTOR_STOPPED',
586
+ sessionId: tag(sessionId),
587
+ }
588
+ debugLog(source, 'actor completed; notifying transport', summarizeMessage(stopMsg))
589
+ transport.send(stopMsg)
590
+ }
591
+ },
592
+ error: () => {
593
+ actorRefs.delete(sessionId)
594
+ actorMachines.delete(sessionId)
595
+ },
596
+ })
597
+ } catch {
598
+ // subscribe is best-effort; older actor implementations may not support it
599
+ }
600
+
574
601
  const actorLogic = (actorRef as { logic?: unknown }).logic as any
575
602
  const machine = actorLogic?.root
576
603
  ? serializeMachine(