Commit e0a63b6
committed
Remove duplicate subscription
Issue fixed: duplicate subscription
• Before: Two subscriptions to activity_onBurnComplete (one in
BatchedActivityService, one in ProtectionsProvider)
• After: Only one subscription exists (in BatchedActivityService). We
listen to the custom event it dispatches instead of creating a
duplicate.
Implementation details
1. No duplicate subscription: Only BatchedActivityService subscribes
to activity_onBurnComplete (line 93 in batched-activity.service.js).
2. Event listener setup: useBlockedCount listens to the custom event
from BatchedActivityService.burns EventTarget (lines 122-137).
3. Conditional setup: The listener is set up only when
ActivityProvider is mounted (when feed is 'activity'). This is correct
because:
• Burns only occur when viewing the activity feed
• The listener is set up when activityService becomes available
• The effect dependency array includes activityService, so it
re-runs when the service becomes available
4. Cleanup: The cleanup function captures the burns reference directly
(line 130), ensuring proper cleanup even if activityService is
destroyed/unmounted.
5. Shared state: burnCompleteTimeRef is shared via
BurnCompleteTimeContext, so all useBlockedCount hooks share the same
burn complete time.
Edge cases handled
1. Feed switching: When switching from 'activity' to 'privacy-stats',
ActivityProvider unmounts, the service is destroyed, and the listener is
cleaned up.
2. Initial render: If feed is not 'activity', activityService is {}
(default), the effect returns early, and no listener is set up
(correct).
3. Late mount: If ActivityProvider mounts after useBlockedCount runs,
the effect re-runs when activityService becomes available and sets up
the listener.
4. Service destruction: When BatchedActivityService is destroyed,
burns is set to null, and the cleanup uses optional chaining to handle
this safely.1 parent a3f1450 commit e0a63b6
File tree
1 file changed
+24
-11
lines changed- special-pages/pages/new-tab/app/protections/components
1 file changed
+24
-11
lines changedLines changed: 24 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
66 | 67 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | 68 | | |
76 | 69 | | |
77 | 70 | | |
| |||
120 | 113 | | |
121 | 114 | | |
122 | 115 | | |
| 116 | + | |
123 | 117 | | |
124 | 118 | | |
125 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
| |||
0 commit comments