From 657e1c3bdebd6945bfd331b27d156f40a8b74158 Mon Sep 17 00:00:00 2001 From: Tiago Neves Date: Fri, 7 Aug 2026 10:20:04 +0100 Subject: [PATCH] =?UTF-8?q?fix(perf):=20BIT-28145=20follow-up=20=E2=80=94?= =?UTF-8?q?=20wire=20sanitizer=20tests=20into=20npm=20test,=20defer=20non-?= =?UTF-8?q?critical=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Post-merge Lighthouse re-verification of PR #47 confirmed article TBT regression is resolved (7416ms -> 0-348ms, Performance 60 -> 99 median, 5 runs, results in PERFORMANCE_BASELINE.md). This follow-up closes a gap found during that verification and widens the pass margin: - bridge/package.json: sanitize-html.test.ts (added in the original fix) was never wired into the test/test:coverage scripts, so the "28 bridge sanitizer tests pass" claim wasn't actually exercised by npm test. Fixed. - Defer mobile-menu and share-button click handlers to requestIdleCallback (institutional/sports headers, ArticleShareBar) so they don't compete with hydration-critical work. - Split Base.astro's theme-flash-prevention script into a minimal inline snippet (runs before paint) and the deferred click-handler logic, instead of one blocking script. - bridge articles route: /articles/:slug/related accepts an optional ?category_id= to skip a redundant WP post-by-slug fetch when the caller already has it. Paperclip-Agent: Miguel Teixeira (urlKey miguel-teixeira; id 0f722e1a-bc3e-4381-8d98-76fa3c7aea10) Paperclip-Issue: BIT-28145 --- bridge/package.json | 4 +-- bridge/src/routes/articles.ts | 21 ++++++++++----- docs/PERFORMANCE_BASELINE.md | 27 +++++++++++++++++++ .../components/article/ArticleShareBar.astro | 24 +++++++++-------- frontend/src/layouts/Base.astro | 12 ++++----- .../src/themes/institutional/Header.astro | 20 +++++++------- frontend/src/themes/sports/Header.astro | 16 ++++++----- 7 files changed, 82 insertions(+), 42 deletions(-) diff --git a/bridge/package.json b/bridge/package.json index 26e9e38..3328ee7 100644 --- a/bridge/package.json +++ b/bridge/package.json @@ -9,8 +9,8 @@ "build": "tsc", "start": "node dist/server.js", "typecheck": "tsc --noEmit", - "test": "npm run build && node --test dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js", - "test:coverage": "npm run build && node --experimental-test-coverage --test dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js" + "test": "npm run build && node --test dist/lib/sanitize-html.test.js dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js", + "test:coverage": "npm run build && node --experimental-test-coverage --test dist/lib/sanitize-html.test.js dist/services/ranking.test.js dist/services/aggregator-mapper.test.js dist/services/andeboltv.test.js dist/services/fpa-stream-match.test.js" }, "dependencies": { "@fastify/cors": "^9.0.1", diff --git a/bridge/src/routes/articles.ts b/bridge/src/routes/articles.ts index 8b841f4..36d7c84 100644 --- a/bridge/src/routes/articles.ts +++ b/bridge/src/routes/articles.ts @@ -18,6 +18,7 @@ type SlugParams = { type RelatedQuery = { limit?: string; + category_id?: string; }; async function resolve_category_id( @@ -92,6 +93,8 @@ export async function articles_routes(app: FastifyInstance): Promise { ); // GET /articles/:slug/related — related articles (same category, excluding current) + // If ?category_id= is provided, skip the article fetch and use it directly. + // This avoids a redundant WP API call when the caller already has the article. app.get( '/articles/:slug/related', async (req: FastifyRequest<{ Params: SlugParams; Querystring: RelatedQuery }>, reply) => { @@ -101,16 +104,22 @@ export async function articles_routes(app: FastifyInstance): Promise { const { slug } = req.params; const limit = Math.min(parseInt(req.query.limit ?? '4', 10), 10); - // Fetch the article first to get its category - const article = await swr_fetch( - `${host}:wp:post:${slug}`, - () => client.get_post_by_slug(slug), - ); + let category_id: number; + + if (req.query.category_id) { + category_id = parseInt(req.query.category_id, 10); + } else { + const article = await swr_fetch( + `${host}:wp:post:${slug}`, + () => client.get_post_by_slug(slug), + ); + category_id = article.category.id; + } const related = await swr_fetch( `${host}:wp:related:${slug}:${limit}`, async () => { - const posts = await client.get_posts_by_category_id(article.category.id, limit + 1); + const posts = await client.get_posts_by_category_id(category_id, limit + 1); return posts.filter(p => p.slug !== slug).slice(0, limit); }, ); diff --git a/docs/PERFORMANCE_BASELINE.md b/docs/PERFORMANCE_BASELINE.md index 67f14fb..439e84c 100644 --- a/docs/PERFORMANCE_BASELINE.md +++ b/docs/PERFORMANCE_BASELINE.md @@ -126,6 +126,33 @@ The article page (`/article/[slug]`) uses `set:html={sanitizeArticleHtml(article - Lighthouse Performance score should exceed 90 on article pages. - LCP remains unaffected (hero images already use `loading="eager"`). +### Deploy & Re-Verification — 2026-08-07 + +**Auditor:** Miguel Teixeira (Database Engineer Agent) + +Fix merged to `main` via PR [#47](https://git.bitreport.pt/BitReport.pt/news-platform/pulls/47) on 2026-08-05 (3 approvals, CI green) and confirmed live on `newsproject.bitreport.pt`. An earlier deploy-verification confirmation was rejected on 2026-08-05 with reason "`https://newsproject.bitreport.pt/article/` 404" — that URL has no slug and is not a valid route; a real article URL returns `200`. + +Lighthouse CLI 13.4.0 (Chrome for Testing 151.0.7922.71, headless, `--no-sandbox`), 5 runs against `newsproject.bitreport.pt/article/benfica-confirma-contratacao-do-guarda-redes-sueco-tobias-thulin`, plus a same-session home-page control (methodology per [[lighthouse-measurement-host-notes]] — host runs persistent background load, so multiple samples + a control page are required rather than trusting one run): + +| Run | Performance | TBT | LCP | +|---|---|---|---| +| 1 | 86 | 348ms | 2769ms | +| 2 | 99 | 0ms | 1894ms | +| 3 | 99 | 0ms | 1886ms | +| 4 | 99 | 0ms | 1910ms | +| 5 | 99 | 0ms | 2051ms | +| Home (control) | 83 | 0ms | 4669ms | + +Median article Performance 99 (target ≥90), 4/5 runs ≥90; the one 86 run and the control's 83 both track back to LCP variance from host contention (TBT is 0ms across every run), not the TBT fix. **TBT regression is resolved**: 7416ms → 0-348ms. + +Follow-up hardening committed under `fix/BIT-28145-tbt-followup` to widen the pass margin and close a test-coverage gap found during verification: +- `bridge/package.json` `test`/`test:coverage` scripts did not actually run `sanitize-html.test.ts` (added in the original fix commit but never wired into the npm script) — the "28 bridge sanitizer tests pass" claim in PR #47 wasn't exercised by `npm test`. Fixed. +- Deferred non-critical mobile-menu and share-button click handlers to `requestIdleCallback` (institutional/sports headers, `ArticleShareBar`) so they no longer compete with hydration-critical work. +- Split the theme-flash-prevention script in `Base.astro` into a minimal inline `is:inline` snippet (runs before paint) and the click-handler logic (deferred), rather than one blocking script. +- `bridge/src/routes/articles.ts` `/articles/:slug/related` accepts an optional `?category_id=` to skip a redundant WP post-by-slug fetch when the caller already has it. + +Acceptance criteria for BIT-28145 are met: root cause documented, fix implemented and deployed, Lighthouse Performance ≥90 confirmed on live article pages (median 99). + --- ## Root Cause, Fix & Deploy — BIT-28144 — andebol.net LCP ~8s / Performance ~26-38 diff --git a/frontend/src/components/article/ArticleShareBar.astro b/frontend/src/components/article/ArticleShareBar.astro index a3fcdbf..df23730 100644 --- a/frontend/src/components/article/ArticleShareBar.astro +++ b/frontend/src/components/article/ArticleShareBar.astro @@ -61,17 +61,19 @@ const encoded_title = encodeURIComponent(title); diff --git a/frontend/src/layouts/Base.astro b/frontend/src/layouts/Base.astro index 513f068..7f279b6 100644 --- a/frontend/src/layouts/Base.astro +++ b/frontend/src/layouts/Base.astro @@ -12,7 +12,7 @@ interface Props { og_image?: string | null; og_type?: string; canonical?: string; - schema?: object; + schema?: object | object[]; } const { @@ -92,13 +92,11 @@ const { Header, Footer } = getThemeComponents(config.theme);