Repository navigation
fix: handle zero-base insight deltas - #521
Conversation
gkhngyk
left a comment
There was a problem hiding this comment.
This matches #520's fix direction almost exactly — the single-meaning percentageChange helper, the raw prev counts, all four consumers updated together, and the Object.hasOwn fallback that keeps pre-existing snapshots rendering unchanged is exactly right. The prompt paragraph is accurate too (and effectively covers #514's ask — worth cross-linking there so effort isn't duplicated).
One real blocker, invisible to CI:
export function percentageChange is a sync export from a 'use server' module. tracking.ts opens with 'use server', and Next.js only allows async function exports from such modules — next build fails with "Only async functions are allowed to be exported in a 'use server' file." Nothing catches it today: CI runs prettier/eslint/tsc/vitest but no next build, the Vercel build is canceled on PR branches by the ignored-build-step, and vitest doesn't enforce the directive. Merged as-is, this breaks the production build on main.
Fix: move percentageChange into a plain module (e.g. web/src/lib/metrics.ts), import it from tracking.ts, and point the test at the new module.
Tiny nit while you're in there: CountDeltaBadge uses text-green-600 where the report viewer uses emerald-600 — matching them keeps the delta color consistent across surfaces.
Everything else is good to go — happy to approve as soon as the helper moves.
|
alright will fix it |
gkhngyk
left a comment
There was a problem hiding this comment.
Verified the fix end-to-end: percentageChange now lives in web/src/lib/metrics.ts (plain module), tracking.ts is back to async-only exports, the test moved with it, and the emerald nit is fixed too. I also ran a full next build against this branch locally — it compiles and completes cleanly, so the production-build blocker is definitively gone. Thanks for the quick, thorough turnaround!
Summary
Fixes ambiguous mentions and citations change deltas when the previous-period count is zero.
mentionsChangeandcitationsChangestrictly percentage-basednullwhen no meaningful percentage can be calculated from a zero baseprevMentionsandprevCitationsto distinguish zero-base growth from unavailable comparison data+N newinstead of an incorrect+N%Related issue
Closes #520
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Testing
git diff --checkpassesThe repository-wide format check reports existing CRLF formatting differences in untouched files in the Windows checkout. All files modified by this PR pass Prettier individually.