Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
6fc4554
fix(feed): refresh a cached feed left before its refresh landed
therealsama Nov 29, 2026
eaa2db1
fix(swipe): show a linked out-of-feed story once
therealsama Nov 29, 2026
537279d
fix(swipe): keep the page when a touch interrupts a snap-back
therealsama Nov 29, 2026
26e2a6b
fix(sw): serve the cached shell on a 5xx and adopt a shell only with …
therealsama Nov 29, 2026
18f0a1c
fix(comments): space out a comment's first paragraph
therealsama Nov 29, 2026
a1f6bce
fix(comments): keep keyboard focus on the replies toggle
therealsama Nov 29, 2026
ee1eec9
fix(comments): show the skeleton, not "No comments yet.", while loading
therealsama Nov 29, 2026
ea012e1
fix(sanitize): stop the email autolinker stalling and linking git rem…
therealsama Nov 29, 2026
a6258e1
fix(api): never report a negative comment count
therealsama Nov 29, 2026
7e92314
fix(domain): keep paging past empty pages short of the estimate
therealsama Nov 29, 2026
01792e8
fix(domain): treat /from/. as no domain on phones
therealsama Nov 29, 2026
e09ceb9
fix(comments): release the priority slot when a deferred panel unmounts
therealsama Nov 29, 2026
ac2fb73
fix(sw): never trim a bundle the offline shell boots with
therealsama Nov 29, 2026
927ff9d
fix(sw): keep a working offline shell when an update's bundles fail
therealsama Nov 29, 2026
c310db7
fix(sanitize): keep git remotes unlinked and link punctuation-glued e…
therealsama Nov 29, 2026
41a48a6
fix(sw): revalidate navigations so an offline launch gets the working…
therealsama Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions e2e/comment-detail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ test.describe('Comment Detail', () => {
await expect(page.getByText(/DX improvements/i).first()).toBeVisible();
});

test('spaces out every paragraph, including the bare first one', async ({ page }) => {
await page.goto('/#/item/1001');

// HN leaves the first paragraph as a bare text node: "Agreed.<p>The DX…".
const second = page.locator('.comment-content p', { hasText: /DX improvements/i }).first();
await expect(second).toBeVisible();
const gap = await second.evaluate((p) => {
const range = document.createRange();
range.selectNodeContents(p.parentElement!.firstChild!);
return p.getBoundingClientRect().top - range.getBoundingClientRect().bottom;
});

// Without a margin the gap is only line-height leading (~3.5px).
expect(gap).toBeGreaterThan(8);
});

test('parent link navigates to parent item', async ({ page }) => {
await page.goto('/#/item/1001');

Expand Down
7 changes: 7 additions & 0 deletions e2e/domain-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ test.describe('Domain Filter - Mobile Swipe', () => {
});
});

test('treats a domain of only dots as no domain', async ({ page }) => {
await page.goto('/#/from/.');

await expect(page.getByRole('heading', { name: 'No domain specified' })).toBeVisible();
await expect(page.getByTestId('swipe-container')).toHaveCount(0);
});

test('updates URL to /item/:id and carries fromDomain state on swipe', async ({ page }) => {
await page.goto('/#/from/example.com');

Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/api-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export async function setupApiMocks(page: Page) {
{
objectID: '2001',
author: 'tptacek',
comment_text: 'Agreed. The DX improvements in the latest release are substantial.',
comment_text: 'Agreed.<p>The DX improvements in the latest release are substantial.',
created_at_i: Math.floor(Date.now() / 1000) - 900,
parent_id: 1001,
story_id: 12345,
Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export const mockAlgoliaCommentItem = {
{
id: 2001,
author: 'tptacek',
text: 'Agreed. The DX improvements in the latest release are substantial.',
text: 'Agreed.<p>The DX improvements in the latest release are substantial.',
created_at_i: now() - 900,
parent_id: 1001,
children: [],
Expand Down
181 changes: 181 additions & 0 deletions e2e/pwa-update.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import { test, expect, type Page } from '@playwright/test';
import fs from 'node:fs';
import http from 'node:http';
import path from 'node:path';
import type { AddressInfo } from 'node:net';

/**
* PWA updates: a release that changes sw.js installs the new worker into the
* same caches the running one boots from, and an app-only release replaces the
* offline shell only once its bundles are cached.
*
* The browser fetches the new sw.js itself, which context.route() can't
* intercept, so these tests serve dist/ (built by the webServer) from a local
* server that can switch to a "next release" mid-test.
*
* Chromium only, like the PWA spec. The HN APIs aren't mocked: Playwright's
* route interception (setupApiMocks) intermittently keeps the old worker from
* handing over to the new one. External hosts fail to resolve instead, which is
* enough here, since only the app shell has to boot.
*/
test.use({
serviceWorkers: 'allow',
launchOptions: { args: ['--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'] },
});

interface NextRelease {
bundles: 'ok' | 'fail';
bumpVersion?: boolean;
// An app-only release: sw.js is unchanged and the page is cacheable for 10
// minutes, as on GitHub Pages.
appOnly?: boolean;
}

const DIST = path.resolve('dist');
const TYPES: Record<string, string> = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.svg': 'image/svg+xml',
'.webmanifest': 'application/manifest+json',
};

let server: http.Server | undefined;

// Serves dist/. Once `ship()` is called, it serves the next release: a changed
// sw.js and a page whose bundles are renamed /assets/next-*, which either load
// (the same files) or never arrive.
async function serveDist() {
const sw = fs.readFileSync(path.join(DIST, 'sw.js'), 'utf8');
const html = fs.readFileSync(path.join(DIST, 'index.html'), 'utf8');
let next: NextRelease | null = null;

server = http.createServer((req, res) => {
let pathname = new URL(req.url ?? '/', 'http://localhost').pathname;
const send = (body: string | Buffer, type: string, cacheControl = 'no-cache') => {
res.writeHead(200, { 'Content-Type': type, 'Cache-Control': cacheControl });
res.end(body);
};
if (pathname === '/sw.js') {
if (!next || next.appOnly) return send(sw, TYPES['.js']);
const nextSw = next.bumpVersion
? sw.replace(/const VERSION = '([^']+)'/, "const VERSION = '$1-next'")
: `${sw}\n// next release\n`;
return send(nextSw, TYPES['.js']);
}
if (next && !next.bumpVersion && (pathname === '/' || pathname === '/index.html')) {
return send(html.replaceAll('/assets/', '/assets/next-'), TYPES['.html'], next.appOnly ? 'max-age=600' : undefined);
}
if (pathname.startsWith('/assets/next-')) {
if (next?.bundles !== 'ok') return res.destroy();
pathname = pathname.replace('/assets/next-', '/assets/');
}
const file = path.join(DIST, pathname === '/' ? 'index.html' : pathname);
if (!file.startsWith(DIST) || !fs.existsSync(file) || fs.statSync(file).isDirectory()) {
res.writeHead(404);
return res.end();
}
send(fs.readFileSync(file), TYPES[path.extname(file)] ?? 'application/octet-stream');
});
await new Promise<void>((resolve) => server!.listen(0, '127.0.0.1', resolve));

return {
url: `http://127.0.0.1:${(server.address() as AddressInfo).port}/`,
ship: (release: NextRelease) => {
next = release;
},
};
}

async function installOnFirstVisit(page: Page, url: string) {
await page.goto(url);
await page.waitForFunction(() => navigator.serviceWorker.controller !== null);
await page.waitForFunction(async () => {
const runtime = (await caches.keys()).find((key) => key.includes('runtime'));
return !!runtime && (await (await caches.open(runtime)).keys()).length > 0;
});
}

// Resolves once the next release's worker has taken over this page.
async function updateServiceWorker(page: Page) {
const tookOver = await page.evaluate(
() =>
new Promise<boolean>((resolve) => {
navigator.serviceWorker.addEventListener('controllerchange', () => resolve(true), { once: true });
setTimeout(() => resolve(false), 15_000);
void navigator.serviceWorker.getRegistration().then((registration) => registration?.update());
}),
);
expect(tookOver).toBe(true);
}

const cachedShell = (page: Page) =>
page.evaluate(async () => (await (await caches.match('/index.html', { ignoreVary: true }))?.text()) ?? '');

test.describe('PWA updates', () => {
test.skip(({ browserName }) => browserName !== 'chromium', 'SW offline behavior validated in Chromium');

test.afterEach(async () => {
await new Promise((resolve) => (server ? server.close(resolve) : resolve(undefined)));
server = undefined;
});

test("keeps the working offline shell when an update's bundles fail to download", async ({ page, context }) => {
const site = await serveDist();
await installOnFirstVisit(page, site.url);

site.ship({ bundles: 'fail' });
await updateServiceWorker(page);

await context.setOffline(true);
await page.reload();
await expect(page.locator('header').first()).toBeVisible();
});

test("boots offline after visiting a release whose bundles didn't download", async ({ page, context }) => {
const site = await serveDist();
await installOnFirstVisit(page, site.url);

// Visiting it online puts the new page in the browser's HTTP cache, but its
// bundles never arrive, so the offline shell stays on the working build.
site.ship({ bundles: 'fail', appOnly: true });
await page.reload();

// A launch, not a reload: a reload would revalidate the page anyway.
await context.setOffline(true);
await page.close();
const launch = await context.newPage();
await launch.goto(site.url);
await expect(launch.locator('header').first()).toBeVisible();
});

test("adopts an update's shell once its bundles are cached", async ({ page, context }) => {
const site = await serveDist();
await installOnFirstVisit(page, site.url);

site.ship({ bundles: 'ok' });
await updateServiceWorker(page);
expect(await cachedShell(page)).toContain('/assets/next-');

await context.setOffline(true);
await page.reload();
await expect(page.locator('header').first()).toBeVisible();
});

test('boots offline after a VERSION bump replaces the caches', async ({ page, context }) => {
const site = await serveDist();
await installOnFirstVisit(page, site.url);
const before = await page.evaluate(() => caches.keys());

site.ship({ bundles: 'ok', bumpVersion: true });
await updateServiceWorker(page);
// `activate` deletes the old version's caches, bundles included.
await expect
.poll(() => page.evaluate(async (old) => (await caches.keys()).filter((key) => old.includes(key)), before))
.toEqual([]);

await context.setOffline(true);
await page.reload();
await expect(page.locator('header').first()).toBeVisible();
});
});
86 changes: 86 additions & 0 deletions e2e/pwa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,92 @@ test.describe('PWA offline app shell', () => {
expect(controlled).toBe(true);
});

test('boots from the cached shell when the server answers with a 5xx', async ({ page, context, baseURL }) => {
await setupApiMocks(page);
await page.goto('/');
await waitForSwControl(page);
await waitForCachedBundle(page);

// A GitHub Pages / CDN outage. Everything the app needs is cached.
await context.route(`${baseURL}/`, (route) => route.fulfill({ status: 503, body: 'Service Unavailable' }));
await page.reload();

await expect(page.locator('header').first()).toBeVisible();
});

test("keeps the cached shell when a new build's bundles fail to download", async ({ page, context, baseURL }) => {
await setupApiMocks(page);
await page.goto('/');
await waitForSwControl(page);
await waitForCachedBundle(page);

// A deploy ships a new page whose bundles never arrive (the connection
// drops mid-download).
const html = await (await page.request.get('/')).text();
const nextBuild = html.replaceAll('/assets/', '/assets/next-');
await context.route(`${baseURL}/`, (route) => route.fulfill({ contentType: 'text/html', body: nextBuild }));
await context.route('**/assets/next-*', (route) => route.abort());
await page.reload();
// Give the SW time to finish with the new page.
await page.waitForTimeout(1000);
await context.unrouteAll();

// The next launch is offline: the shell it gets has to be one whose bundles
// are cached, or the screen stays blank.
await context.setOffline(true);
await page.reload();

await expect(page.locator('header').first()).toBeVisible();
});

test('boots offline after a deploy that overflows the runtime cache', async ({ page, context, baseURL }) => {
await setupApiMocks(page);
await page.goto('/');
await waitForSwControl(page);
await waitForCachedBundle(page);

// Bundles from the deploys since install, all written after this shell's
// own: fill the runtime cache to its cap.
const cap = Number(/MAX_RUNTIME_ENTRIES = (\d+)/.exec(await (await page.request.get('/sw.js')).text())?.[1]);
expect(cap).toBeGreaterThan(0);
const runtimeEntries = () =>
page.evaluate(async () => {
const name = (await caches.keys()).find((key) => key.includes('runtime'));
return name ? (await (await caches.open(name)).keys()).length : 0;
});
await page.evaluate(async (cap) => {
const name = (await caches.keys()).find((key) => key.includes('runtime'))!;
const cache = await caches.open(name);
for (let i = (await cache.keys()).length; i < cap; i++) {
await cache.put(`/assets/old-${i}.js`, new Response(''));
}
}, cap);

// The next deploy changes only the app code: new index bundles, the same
// vendor and runtime chunks.
const html = await (await page.request.get('/')).text();
const appBundles = [...new Set(html.match(/\/assets\/index-[^"']+/g))];
const nextBuild = appBundles.reduce((built, bundle) => built.replaceAll(bundle, bundle.replace('index-', 'index-next-')), html);
await context.route(`${baseURL}/`, (route) => route.fulfill({ contentType: 'text/html', body: nextBuild }));
await context.route('**/assets/index-next-*', async (route) =>
route.fulfill({ response: await page.request.get(new URL(route.request().url()).pathname.replace('index-next-', 'index-')) }),
);
await page.reload();
await expect(page.locator('header').first()).toBeVisible();
await expect
.poll(() => page.evaluate(async () => (await (await caches.match('/index.html', { ignoreVary: true }))?.text()) ?? ''))
.toContain('index-next-');
await expect.poll(runtimeEntries).toBeLessThanOrEqual(cap);
await context.unrouteAll();

// Trimming the cache back to its cap must not drop a chunk the new shell
// still loads, or the next offline launch is a blank screen.
await context.setOffline(true);
await page.reload();

await expect(page.locator('header').first()).toBeVisible();
});

test('shows the offline bar on a cold reload when navigator.onLine wrongly reports online, then clears it on reconnect', async ({ page, context }) => {
await setupApiMocks(page);

Expand Down
Loading