Skip to content

Commit 43d86ac

Browse files
committed
DEBUG
DEBUG
1 parent 253b626 commit 43d86ac

File tree

5 files changed

+78
-8
lines changed

5 files changed

+78
-8
lines changed

special-pages/pages/new-tab/app/activity/NormalizeDataProvider.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,25 @@ export function SignalStateProvider({ children }) {
224224
if (!service) return console.warn('could not access service');
225225
const src = /** @type {import("./batched-activity.service.js").BatchedActivityService} */ (service);
226226
const unsub = src.onData((evt) => {
227+
console.log('[NormalizeDataProvider] Received activity data update:', {
228+
source: evt.source,
229+
activityCount: evt.data.activity.length,
230+
totalTrackers: evt.data.totalTrackers,
231+
urls: evt.data.urls.slice(0, 5), // Log first 5 URLs
232+
});
227233
batch(() => {
234+
const oldActivity = activity.value;
228235
activity.value = normalizeData(activity.value, {
229236
activity: evt.data.activity,
230237
urls: evt.data.urls,
231238
totalTrackers: evt.data.totalTrackers,
232239
});
240+
console.log('[NormalizeDataProvider] Activity data normalized:', {
241+
oldTotalTrackers: oldActivity.totalTrackers,
242+
newTotalTrackers: activity.value.totalTrackers,
243+
oldItemCount: Object.keys(oldActivity.items).length,
244+
newItemCount: Object.keys(activity.value.items).length,
245+
});
233246
const visible = keys.value;
234247
const all = activity.value.urls;
235248

special-pages/pages/new-tab/app/activity/batched-activity.service.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export class BatchedActivityService {
5555
},
5656
subscribe: (cb) => {
5757
const sub1 = ntp.messaging.subscribe('activity_onDataUpdate', (params) => {
58+
console.log('[BatchedActivity] activity_onDataUpdate received:', {
59+
activityCount: params.activity.length,
60+
totalTrackers: params.activity.reduce((acc, item) => acc + item.trackingStatus.totalCount, 0),
61+
urls: params.activity.map((x) => x.url),
62+
});
5863
cb({
5964
activity: params.activity,
6065
urls: params.activity.map((x) => x.url),
@@ -63,6 +68,12 @@ export class BatchedActivityService {
6368
});
6469
const sub2 = ntp.messaging.subscribe('activity_onDataPatch', (params) => {
6570
const totalTrackers = params.totalTrackersBlocked;
71+
console.log('[BatchedActivity] activity_onDataPatch received:', {
72+
hasPatch: 'patch' in params && params.patch !== null,
73+
totalTrackers,
74+
urls: params.urls,
75+
patchUrl: params.patch?.url,
76+
});
6677
if ('patch' in params && params.patch !== null) {
6778
cb({ activity: [/** @type {DomainActivity} */ (params.patch)], urls: params.urls, totalTrackers });
6879
} else {
@@ -91,6 +102,7 @@ export class BatchedActivityService {
91102
/** @type {EventTarget|null} */
92103
this.burns = new EventTarget();
93104
this.burnUnsub = this.ntp.messaging.subscribe('activity_onBurnComplete', () => {
105+
console.log('[BatchedActivity] activity_onBurnComplete received from native');
94106
this.burns?.dispatchEvent(new CustomEvent('activity_onBurnComplete'));
95107
});
96108
}
@@ -216,10 +228,12 @@ export class BatchedActivityService {
216228
}
217229

218230
enableBroadcast() {
231+
console.log('[BatchedActivity] enableBroadcast called');
219232
this.dataService.enableBroadcast();
220233
this.dataService.flush();
221234
}
222235
disableBroadcast() {
236+
console.log('[BatchedActivity] disableBroadcast called');
223237
this.dataService.disableBroadcast();
224238
}
225239
}

special-pages/pages/new-tab/app/burning/BurnProvider.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ export function BurnProvider({ children, service, showBurnAnimation = true }) {
4444
if (burning.value.length > 0 || exiting.value.length > 0) return;
4545

4646
const value = button.value;
47+
console.log('[BurnProvider] Starting burn for:', value);
4748
const response = await service?.confirmBurn(value);
48-
if (response && response.action === 'none') return;
49+
if (response && response.action === 'none') {
50+
console.log('[BurnProvider] Burn cancelled by user');
51+
return;
52+
}
4953

5054
// stop the service broadcasting any updates for a moment
55+
console.log('[BurnProvider] Disabling broadcast and marking as burning');
5156
service.disableBroadcast();
5257

5358
// mark this item as burning - this will prevent further events until we're done
@@ -65,9 +70,11 @@ export function BurnProvider({ children, service, showBurnAnimation = true }) {
6570
// but don't wait any longer than 3 seconds
6671
const withTimer = any(required, timer(3000));
6772

73+
console.log('[BurnProvider] Waiting for FE and native signals...');
6874
// exec the chain
6975
await toPromise(withTimer);
7076

77+
console.log('[BurnProvider] Burn complete, clearing state and re-enabling broadcast');
7178
// when we get here, clear out all state
7279
batch(() => {
7380
exiting.value = [];

special-pages/pages/new-tab/app/protections/components/ProtectionsProvider.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,47 @@ export function useBlockedCount(initial) {
121121
// BatchedActivityService already subscribes to activity_onBurnComplete and dispatches this event
122122
useEffect(() => {
123123
if (!activityService?.burns) return;
124-
124+
125125
const handleBurnComplete = () => {
126126
// Mark that we should skip animation if next update goes to 0
127+
console.log('[ProtectionsProvider] Burn complete event received, setting burnCompleteTimeRef');
127128
burnCompleteTimeRef.current = Date.now();
129+
130+
// WORKAROUND: Manually trigger protections data refresh since native doesn't send protections_onDataUpdate
131+
console.log('[ProtectionsProvider] WORKAROUND: Manually triggering protections data refresh');
132+
service?.dataService?.triggerFetch?.();
128133
};
129-
134+
130135
const burns = activityService.burns;
131136
burns.addEventListener('activity_onBurnComplete', handleBurnComplete);
132137
return () => {
133138
// Use the captured burns reference to ensure we remove from the correct EventTarget
134139
// even if activityService is destroyed/unmounted
135140
burns?.removeEventListener('activity_onBurnComplete', handleBurnComplete);
136141
};
137-
}, [activityService, burnCompleteTimeRef]);
142+
}, [activityService, burnCompleteTimeRef, service]);
138143

139144
// @todo jingram possibly refactor to include full object
140145
useSignalEffect(() => {
141146
return service?.onData((evt) => {
142147
const newValue = evt.data.totalCount;
143148
const previousValue = signal.value;
144-
149+
console.log('[ProtectionsProvider.useBlockedCount] Protections data update received:', {
150+
source: evt.source,
151+
previousValue,
152+
newValue,
153+
totalCookiePopUpsBlocked: evt.data.totalCookiePopUpsBlocked,
154+
burnCompleteTimeSet: burnCompleteTimeRef.current !== null,
155+
});
156+
145157
// If transitioning to 0 and we just had a burn complete (within 1 second),
146158
// this is likely a "burn all" operation - skip animation and go directly to empty state
147159
if (newValue === 0 && previousValue > 0 && burnCompleteTimeRef.current !== null) {
148160
const timeSinceBurn = Date.now() - burnCompleteTimeRef.current;
161+
console.log('[ProtectionsProvider.useBlockedCount] Checking burn all condition:', {
162+
timeSinceBurn,
163+
willSkipAnimation: timeSinceBurn < 1000,
164+
});
149165
if (timeSinceBurn < 1000) {
150166
// Set skipAnimation flag before updating the signal value
151167
// This ensures useAnimatedCount immediately sets to 0 without animating
@@ -159,7 +175,7 @@ export function useBlockedCount(initial) {
159175
return;
160176
}
161177
}
162-
178+
163179
// Normal update (including single domain burns) - allow animation for both counts
164180
// This ensures both tracker count and cookie pop-ups count animate when burning a single domain
165181
skipAnimationSignal.value = false;
@@ -180,7 +196,14 @@ export function useCookiePopUpsBlockedCount(initial) {
180196

181197
useSignalEffect(() => {
182198
return service?.onData((evt) => {
183-
signal.value = evt.data.totalCookiePopUpsBlocked;
199+
const previousValue = signal.value;
200+
const newValue = evt.data.totalCookiePopUpsBlocked;
201+
console.log('[ProtectionsProvider.useCookiePopUpsBlockedCount] Cookie pop-ups count update:', {
202+
source: evt.source,
203+
previousValue,
204+
newValue,
205+
});
206+
signal.value = newValue;
184207
});
185208
});
186209

special-pages/pages/new-tab/app/service.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ export class Service {
109109
}
110110

111111
disableBroadcast() {
112+
console.log('[Service] disableBroadcast called');
112113
this._broadcast = false;
113114
}
114115

115116
enableBroadcast() {
117+
console.log('[Service] enableBroadcast called');
116118
this._broadcast = true;
117119
}
118120

119121
flush() {
122+
console.log('[Service] flush called, has data:', this.data !== null);
120123
if (this.data) this._accept(this.data, 'manual');
121124
}
122125

@@ -143,6 +146,12 @@ export class Service {
143146
* @private
144147
*/
145148
_accept(data, source) {
149+
console.log('[Service] _accept called:', {
150+
source,
151+
broadcast: this._broadcast,
152+
hasData: data !== null,
153+
});
154+
146155
if (this.accept && source !== 'initial') {
147156
this.data = /** @type {NonNullable<Data>} */ (this.accept(/** @type {NonNullable<Data>} */ (this.data), data, source));
148157
} else {
@@ -155,8 +164,12 @@ export class Service {
155164
// always cancel any existing debounced timers
156165
this.clearDebounceTimer();
157166

158-
if (!this._broadcast) return console.warn('not broadcasting');
167+
if (!this._broadcast) {
168+
console.warn('[Service] NOT broadcasting - broadcast is disabled. Source:', source);
169+
return;
170+
}
159171

172+
console.log('[Service] Broadcasting data event. Source:', source);
160173
// always broadcast the change on the event target
161174
const dataEvent = new CustomEvent('data', {
162175
detail: {

0 commit comments

Comments
 (0)