Skip to content

Commit bda2ef0

Browse files
committed
DEBUG
DEBUG DEBUG
1 parent 253b626 commit bda2ef0

File tree

6 files changed

+113
-10
lines changed

6 files changed

+113
-10
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/ProtectionsConsumer.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useContext } from 'preact/hooks';
2-
import { ProtectionsContext, useBlockedCount, useCookiePopUpsBlockedCount } from './ProtectionsProvider.js';
1+
import { useContext, useEffect } from 'preact/hooks';
2+
import { ProtectionsContext, useBlockedCount, useCookiePopUpsBlockedCount, ProtectionsServiceContext } from './ProtectionsProvider.js';
33
import { h } from 'preact';
44
import { Protections } from './Protections.js';
5-
import { ActivityProvider } from '../../activity/ActivityProvider.js';
5+
import { ActivityProvider, ActivityServiceContext } from '../../activity/ActivityProvider.js';
66
import { ActivityConsumer } from '../../activity/components/Activity.js';
77
import { PrivacyStatsProvider } from '../../privacy-stats/components/PrivacyStatsProvider.js';
88
import { BodyExpanderProvider } from '../../privacy-stats/components/BodyExpansionProvider.js';
@@ -32,6 +32,42 @@ export function ProtectionsConsumer() {
3232
return null;
3333
}
3434

35+
/**
36+
* Bridge component that connects burn complete events to protections data refresh.
37+
* This must be inside ActivityProvider to have access to ActivityServiceContext.
38+
*/
39+
function BurnToProtectionsDataBridge() {
40+
const activityService = useContext(ActivityServiceContext);
41+
const protectionsService = useContext(ProtectionsServiceContext);
42+
43+
useEffect(() => {
44+
if (!activityService?.burns || !protectionsService) {
45+
console.log('[BurnToProtectionsDataBridge] Missing service:', {
46+
hasActivityService: !!activityService,
47+
hasBurns: !!activityService?.burns,
48+
hasProtectionsService: !!protectionsService,
49+
});
50+
return;
51+
}
52+
53+
const handleBurnComplete = () => {
54+
console.log('[BurnToProtectionsDataBridge] Burn complete event received, triggering protections data refresh');
55+
// Manually trigger protections data refresh since native doesn't send protections_onDataUpdate
56+
protectionsService?.dataService?.triggerFetch?.();
57+
};
58+
59+
const burns = activityService.burns;
60+
burns.addEventListener('activity_onBurnComplete', handleBurnComplete);
61+
console.log('[BurnToProtectionsDataBridge] Burn complete listener registered');
62+
63+
return () => {
64+
burns?.removeEventListener('activity_onBurnComplete', handleBurnComplete);
65+
};
66+
}, [activityService, protectionsService]);
67+
68+
return null; // This component doesn't render anything
69+
}
70+
3571
/**
3672
* @param {object} props
3773
* @param {ProtectionsData} props.data
@@ -54,6 +90,7 @@ function ProtectionsReadyState({ data, config }) {
5490
>
5591
{config.feed === 'activity' && (
5692
<ActivityProvider>
93+
<BurnToProtectionsDataBridge />
5794
<ActivityConsumer
5895
showBurnAnimation={config.showBurnAnimation ?? true}
5996
shouldDisplayLegacyActivity={totalCookiePopUpsBlockedSignal.value === undefined}

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ 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.useBlockedCount] Burn complete event received, setting burnCompleteTimeRef');
127128
burnCompleteTimeRef.current = Date.now();
128129
};
129-
130+
130131
const burns = activityService.burns;
131132
burns.addEventListener('activity_onBurnComplete', handleBurnComplete);
132133
return () => {
@@ -141,11 +142,22 @@ export function useBlockedCount(initial) {
141142
return service?.onData((evt) => {
142143
const newValue = evt.data.totalCount;
143144
const previousValue = signal.value;
144-
145+
console.log('[ProtectionsProvider.useBlockedCount] Protections data update received:', {
146+
source: evt.source,
147+
previousValue,
148+
newValue,
149+
totalCookiePopUpsBlocked: evt.data.totalCookiePopUpsBlocked,
150+
burnCompleteTimeSet: burnCompleteTimeRef.current !== null,
151+
});
152+
145153
// If transitioning to 0 and we just had a burn complete (within 1 second),
146154
// this is likely a "burn all" operation - skip animation and go directly to empty state
147155
if (newValue === 0 && previousValue > 0 && burnCompleteTimeRef.current !== null) {
148156
const timeSinceBurn = Date.now() - burnCompleteTimeRef.current;
157+
console.log('[ProtectionsProvider.useBlockedCount] Checking burn all condition:', {
158+
timeSinceBurn,
159+
willSkipAnimation: timeSinceBurn < 1000,
160+
});
149161
if (timeSinceBurn < 1000) {
150162
// Set skipAnimation flag before updating the signal value
151163
// This ensures useAnimatedCount immediately sets to 0 without animating
@@ -159,7 +171,7 @@ export function useBlockedCount(initial) {
159171
return;
160172
}
161173
}
162-
174+
163175
// Normal update (including single domain burns) - allow animation for both counts
164176
// This ensures both tracker count and cookie pop-ups count animate when burning a single domain
165177
skipAnimationSignal.value = false;
@@ -180,7 +192,14 @@ export function useCookiePopUpsBlockedCount(initial) {
180192

181193
useSignalEffect(() => {
182194
return service?.onData((evt) => {
183-
signal.value = evt.data.totalCookiePopUpsBlocked;
195+
const previousValue = signal.value;
196+
const newValue = evt.data.totalCookiePopUpsBlocked;
197+
console.log('[ProtectionsProvider.useCookiePopUpsBlockedCount] Cookie pop-ups count update:', {
198+
source: evt.source,
199+
previousValue,
200+
newValue,
201+
});
202+
signal.value = newValue;
184203
});
185204
});
186205

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)