Skip to content

fix(lazy-loader): bump default rootMargin to 2000px so dedicated dashboard pages load without user scroll#2465

Merged
pethers merged 3 commits into
mainfrom
copilot/improve-cypress-dashboard-tests
May 13, 2026
Merged

fix(lazy-loader): bump default rootMargin to 2000px so dedicated dashboard pages load without user scroll#2465
pethers merged 3 commits into
mainfrom
copilot/improve-cypress-dashboard-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

Plan

Live regression: on dedicated /dashboards/<name>.html pages the single dashboard container sits ~1 156 px below the fold of a 720 px viewport. With the previous rootMargin: '200px', the IntersectionObserver in lazy-loader.ts never fired without user scroll → Chart.js / D3 / PapaParse were never registered → all charts rendered empty and dashboards' init() failed with misleading error fallbacks ("Cannot access 'o' before initialization", "Unable to load risk assessment data from CIA Platform"). The per-chart Cypress suite did not catch this because cy.visitDashboard() unconditionally scrollIntoView()s the container.

Fix

  • src/browser/lazy-loader.ts
    • New exported DEFAULT_ROOT_MARGIN = '2000px' (≈ 2 viewport heights — covers the ~1 156 px below-fold offset on every dedicated dashboard page) and DEFAULT_THRESHOLD = 0.01 constants.
    • initLazyDashboards() now defaults to these.
    • Belt-and-suspenders eager-load fallback: one requestAnimationFrame after registration, the loader probes each container's getBoundingClientRect() against the configured rootMargin and synthesises a load for anything that would intersect — fires the loader exactly once even in browser/iframe contexts that don't deliver an initial IO entry without user-driven scroll.
    • New exported parseRootMarginPx() helper.
  • tests/lazy-loader.test.js
    • Lock the DEFAULT_ROOT_MARGIN = "2000px" / DEFAULT_THRESHOLD = 0.01 regression contract.
    • Assert initLazyDashboards() passes those values to the IntersectionObserver by default.
    • 7 new parseRootMarginPx() unit tests covering px / negative / percentage / undefined / empty / malformed inputs.
    • 30 / 30 passing (npx vitest run tests/lazy-loader.test.js).
  • cypress/e2e/dashboards-no-scroll.cy.js (new spec — would have caught the live regression)
    • Visits all 9 dedicated dashboard pages (parties, committees, coalitions, election-cycle, seasonal-patterns, pre-election, anomaly-detection, ministers, risk).
    • Does NOT scroll — asserts what a user actually sees on first paint.
    • Per page: hashed main-*.js bundle is served (no /src/browser/main.ts dev path); window.Chart + window.d3 register within 15 s without any scroll; no visible .error-message / [role="alert"] containing user-facing error text is rendered (skips empty placeholder banners like risk.html's #earlyWarnings).
    • 27 / 27 passing locally against vite preview (npx cypress run --spec cypress/e2e/dashboards-no-scroll.cy.js).
  • npx tsc --noEmit -p tsconfig.browser.json → clean.

Geometry that proves the fix

viewport: 0…720 px
container (#committee-dashboard / #risk-dashboard / …): top=1156, bottom=2916
old effective root (200 px margin):   −200 …  920  → no intersection → no load → broken charts
new effective root (2000 px margin):  −2000… 2720  → intersects     → eager load → charts render

Copilot AI and others added 2 commits May 13, 2026 20:21
@pethers pethers marked this pull request as ready for review May 13, 2026 20:43
Copilot AI review requested due to automatic review settings May 13, 2026 20:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@github-actions github-actions Bot added documentation Documentation updates html-css HTML/CSS changes javascript JavaScript code changes translation Translation updates rtl RTL language support (Arabic, Hebrew) testing Test coverage news News articles and content generation size-xl Extra large change (> 1000 lines) labels May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🏷️ Automatic Labeling Summary

This PR has been automatically labeled based on the files changed and PR metadata.

Applied Labels: documentation,html-css,javascript,translation,rtl,testing,size-xl,news

Label Categories

  • 🗳️ Content: news, dashboard, visualization, intelligence
  • 💻 Technology: html-css, javascript, workflow, security
  • 📊 Data: cia-data, riksdag-data, data-pipeline, schema
  • 🌍 I18n: i18n, translation, rtl
  • 🔒 ISMS: isms, iso-27001, nist-csf, cis-controls
  • 🏗️ Infrastructure: ci-cd, deployment, performance, monitoring
  • 🔄 Quality: testing, accessibility, documentation, refactor
  • 🤖 AI: agent, skill, agentic-workflow

For more information, see .github/labeler.yml.

Copilot AI requested a review from pethers May 13, 2026 21:03
@pethers pethers requested a review from Copilot May 13, 2026 21:04
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@pethers pethers merged commit cb08b89 into main May 13, 2026
24 checks passed
@pethers pethers deleted the copilot/improve-cypress-dashboard-tests branch May 13, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation updates html-css HTML/CSS changes javascript JavaScript code changes news News articles and content generation rtl RTL language support (Arabic, Hebrew) size-xl Extra large change (> 1000 lines) testing Test coverage translation Translation updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants