Skip to content

Commit 260a147

Browse files
committed
fix macos list size
1 parent 4fb2937 commit 260a147

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ export function SignalStateProvider({ children }) {
227227
console.warn('unhandled action:', action);
228228
}
229229
} else if (toggle) {
230-
if (state.config?.expansion === 'collapsed') {
230+
if (state.config?.expansion === 'collapsed' && batched) {
231231
const next = activity.value.urls.slice(0, Math.min(service.INITIAL, activity.value.urls.length));
232232
setVisibleRange(next);
233233
}
234234
}
235235
}
236236

237-
const didClick = useCallback(didClick_, [service, state.config.expansion]);
237+
const didClick = useCallback(didClick_, [service, batched, state.config.expansion]);
238238
const firstUrls = state.data.activity.map((x) => x.url);
239239
const keys = useSignal(normalizeKeys([], firstUrls));
240240

@@ -276,7 +276,7 @@ export function SignalStateProvider({ children }) {
276276
fillHoles();
277277
}
278278

279-
useSignalEffect(() => {
279+
useEffect(() => {
280280
if (!service) return console.warn('could not access service');
281281
const src = /** @type {BatchedActivityService} */ (service);
282282
const unsub = src.onData((evt) => {
@@ -288,7 +288,12 @@ export function SignalStateProvider({ children }) {
288288
});
289289
const visible = keys.value;
290290
const all = activity.value.urls;
291-
const nextVisibleRange = all.slice(0, Math.max(service.INITIAL, Math.max(service.INITIAL, visible.length)));
291+
292+
// prettier-ignore
293+
const nextVisibleRange = batched
294+
? all.slice(0, Math.max(service.INITIAL, Math.max(service.INITIAL, visible.length)))
295+
: all
296+
292297
setVisibleRange(nextVisibleRange);
293298
fillHoles();
294299
});
@@ -297,7 +302,7 @@ export function SignalStateProvider({ children }) {
297302
return () => {
298303
unsub();
299304
};
300-
});
305+
}, [service, batched, activity, keys]);
301306

302307
useEffect(() => {
303308
window.addEventListener('activity.next', showNextChunk);

special-pages/pages/new-tab/app/activity/integration-tests/activity.page.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { activityMocks } from '../mocks/activity.mocks.js';
22
import { expect } from '@playwright/test';
3+
import { generateSampleData } from '../mocks/activity.mock-transport.js';
34

45
/**
56
* @typedef {import('../../../types/new-tab.js').NewTabMessages['subscriptions']['subscriptionEvent']} SubscriptionEventNames
@@ -234,6 +235,16 @@ export class ActivityPage {
234235
});
235236
}
236237

238+
/**
239+
* Simulates the subscription message with a new list of activity data.
240+
*
241+
* @param {number} count - The number of items to generate in the new list.
242+
*/
243+
async acceptsNewList(count) {
244+
const next = generateSampleData(count);
245+
await this.ntp.mocks.simulateSubscriptionMessage('activity_onDataUpdate', { activity: next });
246+
}
247+
237248
async acceptsUpdatedFavorite() {
238249
const { page } = this;
239250
const initial = structuredClone(activityMocks.few);

special-pages/pages/new-tab/app/activity/integration-tests/activity.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ test.describe('activity widget', () => {
2020

2121
await ap.didRender();
2222
});
23+
test('Accepts update (pushing items to front)', async ({ page }, workerInfo) => {
24+
const ntp = NewtabPage.create(page, workerInfo);
25+
const widget = new ActivityPage(page, ntp).withEntries(5);
26+
await ntp.reducedMotion();
27+
await ntp.openPage({ additional: { feed: 'activity', activity: widget.entries } });
28+
await widget.didRender();
29+
await widget.acceptsNewList(6);
30+
await widget.hasRows(6);
31+
await widget.canCollapseList();
32+
await widget.hasRows(6);
33+
});
2334
test('Accepts update (subscription)', async ({ page }, workerInfo) => {
2435
const ntp = NewtabPage.create(page, workerInfo);
2536
const ap = new ActivityPage(page, ntp);
@@ -175,8 +186,9 @@ test.describe('activity widget', () => {
175186
await widget.hasRows(5);
176187
await batching.triggerNext();
177188
await widget.hasRows(15);
189+
await page.waitForTimeout(500);
178190
await batching.triggerNext();
179-
await page.waitForTimeout(100);
191+
await page.waitForTimeout(500);
180192
await widget.hasRows(25);
181193
});
182194
test('patching in place', async ({ page }, workerInfo) => {

0 commit comments

Comments
 (0)