Skip to content

fix(reports): Fix/report type switch stale dimensions#245

Merged
therealbrad merged 3 commits intomainfrom
fix/report-type-switch-stale-dimensions
Apr 24, 2026
Merged

fix(reports): Fix/report type switch stale dimensions#245
therealbrad merged 3 commits intomainfrom
fix/report-type-switch-stale-dimensions

Conversation

@therealbrad
Copy link
Copy Markdown
Contributor

@therealbrad therealbrad commented Apr 24, 2026

Description

Fixes a bug where switching report types could auto-run the newly selected report with dimensions/metrics from the PREVIOUS report, producing server errors like Unsupported dimension: creator.

Two root causes, both fixed:

  1. handleTabChange preserved stale URL params. The handler built the new URL via new URLSearchParams(searchParams.toString()), inheriting dimensions=...&metrics=... from whatever the previous report was selected. handleReportTypeChange was already correctly starting from a fresh URLSearchParams — now handleTabChange matches.

  2. Metadata effect race window. When reportType changes via either handler, React may fire the metadata effect once with stale searchParams (before router.replace's URL update lands). That window loaded URL-based selections from the OLD report into the NEW report's state, and auto-run picked them up. Added a guard that skips URL-param loading when the URL's reportType doesn't match the current state.

Refactor: extracted the URL-building + race-guard logic into components/reports/reportUrlUtils.ts so both invariants can be unit tested without mounting the full component.

Related Issue

Surfaced during manual QA of PR #243 / PR #244. No tracked issue number — caught during the React Compiler lint cleanup cycle.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Refactoring (no functional changes) — extraction of URL helpers
  • New feature
  • Breaking change
  • Documentation update
  • Performance improvement

How Has This Been Tested?

  • Unit tests — 5,745 pass (9 new tests in reportUrlUtils.test.ts covering the clean-URL contract and the URL/state sync guard)
  • Integration tests
  • E2E tests — the existing e2e/tests/reports/ suite (23 tests) still passes against this branch. An E2E attempt to exercise the tab click was removed after diagnosis showed the Playwright selector was cascading through Radix Select behavior into the wrong handler — the unit tests cover the same invariants with higher precision and no flakiness.
  • Manual testing — switch report types via both the tab selector and the report-type dropdown; verify no "Unsupported dimension" error and that URL is cleaned of stale dims/metrics on every transition.

Test Configuration:

  • OS: macOS (Darwin 25.4.0)
  • Browser: Chromium (Playwright)
  • Node: v24

Suggested manual smoke test before merge:

  1. Go to a project's Reports page, pick a non-pre-built report (e.g. "Repository Statistics"), add a dimension + metric, run it.
  2. Switch to the "Reports" tab (pre-built) via the tab selector. Confirm URL resets — no dimensions=...&metrics=... — and no error toasts/banners appear.
  3. Use the report-type dropdown inside the Reports tab to switch between pre-built reports. Same assertion.
  4. Go back to "Report Builder" tab and switch custom reports via dropdown. Same assertion.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings — lint: 0 errors, 31 baseline advisory warnings unchanged
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have signed the CLA

Screenshots (if applicable)

N/A — no UI changes.

Additional Notes

Branch base: forked from main before PR #244 (refactor/ref-during-render-cleanup) was merged. If #244 lands first, this branch will need a trivial rebase — different sections of ReportBuilder.tsx so no conflicts expected.

Commits: 2 atomic commits — the behavioral fix, then the helper-extraction + unit tests.

Stats: 4 files changed across the two commits (ReportBuilder.tsx + new reportUrlUtils.ts / reportUrlUtils.test.ts + minor cleanup to e2e/tests/reports/report-builder-types.spec.ts).

therealbrad and others added 3 commits April 24, 2026 16:18
ReportBuilder preserved ?dimensions=...&metrics=... across tab switches,
causing the new report to auto-run with selections from the previous
report. When those dims were unsupported, the server returned errors
like "Unsupported dimension: creator".

- Fix handleTabChange to start URL params from a fresh URLSearchParams
  instead of copying the old query string, matching the behavior of
  handleReportTypeChange.
- Guard the metadata effect against the URL/state race: when
  searchParams.get("reportType") is still pointing at the OLD report
  (router.replace has not landed yet) skip loading URL-based
  selections, so the new report's dimOpts are not populated with the
  previous report's URL params.
- Add E2E regression test covering tab switch — asserts stale
  dimension/metric params are dropped and no "Unsupported dimension"
  error surfaces.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Follow-up to the stale-URL-param fix. Extracts the URL-building logic
from ReportBuilder into reportUrlUtils so the two invariants can be
unit tested without mounting the full component:

- buildCleanReportUrlParams — drops stale dimension/metric/date params
  when switching report types (prevents feeding them into auto-run
  against an incompatible report).
- isUrlInSyncWithReportType — guards the metadata effect from loading
  URL-based selections when router.replace is in flight and the URL
  still points at the previous report.

Tests cover the happy path, the race window, the initial-load case
(no reportType in URL), and pageSize edge cases.

Also removes an earlier E2E attempt that was testing the wrong code
path — clicking the Reports tab in the current layout cascades into
handleReportTypeChange via Radix Select behavior, making the selector
unreliable. The unit tests cover the same invariants with higher
precision.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@therealbrad therealbrad merged commit fc287db into main Apr 24, 2026
5 checks passed
@therealbrad therealbrad deleted the fix/report-type-switch-stale-dimensions branch April 24, 2026 22:37
@therealbrad
Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 0.22.13 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant