Skip to content

Fixing empty dashboards and ensuring data loads#2407

Merged
pethers merged 8 commits into
mainfrom
copilot/fix-empty-dashboards
May 11, 2026
Merged

Fixing empty dashboards and ensuring data loads#2407
pethers merged 8 commits into
mainfrom
copilot/fix-empty-dashboards

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

  • Analyze root cause: live site serves /src/browser/main.ts (dev path) instead of hashed /assets/js/main-*.js — S3 returns index.html for unknown paths with text/html, browser silently rejects HTML as JS module → no lazy loader → no Chart.js → empty dashboards
  • scripts/vite-plugin-static-pages.js rewrites the dev script tag to the hashed production bundle in dist/dashboards/*.html
  • Add tests/dashboard-bundle-integrity.test.ts: validates all 9 dashboard HTML files in dist/ have hashed main-*.js bundle and no dev paths
  • Add deploy-s3.yml pre-flight check: verify all 9 dashboards have hashed bundle, no /src/browser/main.ts, and dist/cia-data/ exists before deploying
  • Fix cypress/e2e/all-dashboards.cy.js: replace weak canvas.width > 0 checks with waitForChart() which uses Chart.getChart() to prove the full pipeline works
  • Merge conflicts resolved (2-parent merge commit, 0 conflict markers)
  • Reviewer feedback addressed:
    • MODULE_SCRIPT_RE now requires type="module" via lookahead — classic <script> tags are no longer silently rewritten to a hashed ESM bundle
    • Rewriter strips any pre-existing crossorigin attribute before injecting crossorigin="" so the output never carries duplicate attributes
    • vite.config.js dashboards comment now lists the 9 actual slugs (was 12, breaking the 9×14=126 math)
    • 2 new regression tests in tests/vite-plugin-static-pages.test.ts (16/16 passing)
  • Fix CI failure Test Dashboard / Dashboard Tests (cypress/e2e/dashboards.cy.js): "should render charts after data loads" timed out because the IntersectionObserver-based lazy loader never fired (canvas was below the headless viewport). Added cy.get('#party-dashboard').scrollIntoView() so registerBrowserGlobals() runs and window.Chart is set.

Copilot AI and others added 2 commits May 11, 2026 09:21
@github-actions github-actions Bot added javascript JavaScript code changes performance Performance optimization testing Test coverage refactor Code refactoring size-l Large change (250-1000 lines) labels May 11, 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: javascript,performance,testing,refactor,size-l

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.

@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

@pethers pethers marked this pull request as ready for review May 11, 2026 09:44
Copilot AI review requested due to automatic review settings May 11, 2026 09:44
@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.

Pull request overview

This PR addresses a production regression where pre-rendered dashboard HTML pages shipped a dev-only module script path (/src/browser/main.ts), causing dashboards to render empty in S3/CloudFront. It does so by extending the staticPagesPlugin to rewrite module script tags to hashed production bundles and by adding regression tests in both unit and Cypress suites.

Changes:

  • Extend scripts/vite-plugin-static-pages.js to rewrite <script type="module" src="/src/browser/<name>.ts"> to the hashed /assets/js/<name>-<hash>.js bundle (using the Vite manifest or a dist scan fallback).
  • Add Vitest unit tests covering module-script rewrite scenarios (manifest lookup, fallback scan, no-op when unresolved, non-matching tags).
  • Strengthen Cypress dashboard assertions to detect missing JS execution (Chart.js instance attachment) and verify served HTML contains hashed bundle paths.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
vite.config.js Updates build comments explaining why dashboard pages require module-script rewriting to avoid empty dashboards in production.
scripts/vite-plugin-static-pages.js Implements module <script> tag rewriting (manifest-backed + fallback scan) and logs rewrite counts.
tests/vite-plugin-static-pages.test.ts Adds unit coverage for the new module-script rewrite behavior and fallbacks.
cypress/support/commands.js Improves waitForChart to verify real Chart.js runtime attachment, not just canvas dimensions.
cypress/e2e/dashboards.cy.js Adds regression tests ensuring dashboard pages ship hashed main-*.js bundles and that window.Chart is registered at runtime.

Comment thread scripts/vite-plugin-static-pages.js Outdated
Comment on lines +122 to +127
* We only match the canonical absolute `/src/browser/<name>.ts` form (the
* only one used in this codebase). Captures: 1=before-attrs, 2=name,
* 3=after-attrs.
*/
const MODULE_SCRIPT_RE =
/<script\b([^>]*?)\bsrc\s*=\s*"\/src\/browser\/([A-Za-z0-9_-]+)\.ts"([^>]*)>\s*<\/script>/gi;
Comment thread scripts/vite-plugin-static-pages.js Outdated
Comment on lines +364 to +365
const attrsBefore = before.replace(/\bsrc\s*=\s*"[^"]*"/i, '').trim();
const attrsAfter = after.replace(/\bsrc\s*=\s*"[^"]*"/i, '').trim();
Comment thread vite.config.js Outdated
Comment on lines +283 to +287
@@ -284,11 +284,16 @@ export default defineConfig({
// (parties, anomaly-detection, network-analysis, voting-cohesion,
// momentum, coalitions, seasonal-patterns, pre-election, ministers,
// risk, election-cycle, committees) × 14 languages = 126 files,
// emitted by scripts/build-dashboard-pages.py. They are pure
// static HTML that loads existing chart bundles via root-relative
// <script src="/assets/js/...">, so they don't need to be Rollup
// entry points — staticPagesPlugin just copies them to dist/ and
// rewrites the styles.css link to the hashed asset.
// emitted by scripts/build-dashboard-pages.py.
@github-actions github-actions Bot added rtl RTL language support (Arabic, Hebrew) news News articles and content generation labels May 11, 2026
@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 the size-xl Extra large change (> 1000 lines) label May 11, 2026
Copilot AI and others added 2 commits May 11, 2026 12:18
…t.js assertions

Root cause: live site served /src/browser/main.ts (dev path) instead of
hashed /assets/js/main-*.js. S3/CloudFront returns index.html for unknown
paths with text/html, browser silently rejects HTML as JS module → no lazy
loader → no charts → empty dashboards.

Changes:
- Add deploy-s3.yml pre-flight: verify all 9 dashboard HTML files have
  hashed bundle and no dev paths before deploying
- Add tests/dashboard-bundle-integrity.test.ts: validates dist/ output
  post-build (30 new assertions)
- Fix all-dashboards.cy.js: replace weak canvas.width>0 checks with
  Chart.getChart() verification (proves full pipeline: main.ts loaded →
  register-globals → dashboard module → CSV fetched → chart rendered)
- Add cia-data directory verification to deploy workflow

Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/6f0effac-0d1b-43cb-9f66-a6536d6be7a9

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
@github-actions github-actions Bot added workflow GitHub Actions workflows ci-cd CI/CD pipeline changes deployment Deployment configuration labels May 11, 2026
@pethers
Copy link
Copy Markdown
Member

pethers commented May 11, 2026

@copilot resolve the merge conflicts in this pull request must get all from main

…hboards

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot resolve the merge conflicts in this pull request must get all from main

Merged main into this branch using -X theirs to accept all changes from main. The merge commit 70900be has 2 parents (53ad92e + 5ff3e07), 0 conflict markers, and all 5461 tests pass.

@pethers pethers requested a review from Copilot May 11, 2026 12:45
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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment on lines +109 to +113
/**
* Match a single `<script type="module" src="/src/browser/<name>.ts">` dev
* tag (the one Vite expects in source) so we can rewrite it to the hashed
* production bundle (`/assets/js/<name>-<hash>.js`) emitted by Rollup.
*
Comment thread vite.config.js Outdated
Comment on lines +283 to +287
@@ -284,11 +284,16 @@ export default defineConfig({
// (parties, anomaly-detection, network-analysis, voting-cohesion,
// momentum, coalitions, seasonal-patterns, pre-election, ministers,
// risk, election-cycle, committees) × 14 languages = 126 files,
// emitted by scripts/build-dashboard-pages.py. They are pure
// static HTML that loads existing chart bundles via root-relative
// <script src="/assets/js/...">, so they don't need to be Rollup
// entry points — staticPagesPlugin just copies them to dist/ and
// rewrites the styles.css link to the hashed asset.
// emitted by scripts/build-dashboard-pages.py.
@pethers
Copy link
Copy Markdown
Member

pethers commented May 11, 2026

@copilot apply changes based on the comments in this thread and fix Test Dashboard / Dashboard Tests (cypress/e2e/dashboards.cy.js) (pull_request)
Test Dashboard / Dashboard Tests (cypress/e2e/dashboards.cy.js) (pull_request)Failing after 2m

Improve e2e test of dashboards, improve all

- Tighten MODULE_SCRIPT_RE to require type="module" (lookahead) so a
  classic <script src="/src/browser/main.ts"> can never be silently
  rewritten to a hashed ESM bundle (would throw at runtime).
- Strip pre-existing crossorigin attribute from before/after captures so
  the rewritten <script> never emits duplicate crossorigin="" attributes.
- vite.config.js dashboards comment: list the 9 actual dashboard slugs
  (anomaly-detection, coalitions, committees, election-cycle, ministers,
  parties, pre-election, risk, seasonal-patterns) so 9×14=126 math holds.
- cypress/e2e/dashboards.cy.js "should render charts after data loads":
  scrollIntoView() the #party-dashboard container before waitForChart so
  the IntersectionObserver-based lazy loader fires and registerBrowserGlobals
  attaches Chart.js to window.Chart (root cause of CI failure).
- Add 2 regression tests: duplicate-crossorigin avoidance + classic
  <script> non-rewrite (16/16 vite-plugin-static-pages tests passing).

Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/8f896bbf-f838-4686-95c6-8707b2651b9f

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot apply changes based on the comments in this thread and fix [Test Dashboard / Dashboard Test...

Done in 2e3737f:

  • MODULE_SCRIPT_RE now requires type="module" via lookahead (classic <script> tags are no longer silently rewritten to a hashed ESM bundle).
  • Rewriter strips any pre-existing crossorigin from before/after captures so the output never carries duplicate attributes.
  • vite.config.js dashboards comment fixed to list the 9 actual slugs (was 12, breaking the 9×14=126 math).
  • Cypress dashboards.cy.js "should render charts after data loads" now scrollIntoView()s #party-dashboard before waitForChart, so the IntersectionObserver-based lazy loader fires and registerBrowserGlobals() attaches Chart.js to window.Chart (root cause of the CI timeout).
  • Added 2 regression tests in tests/vite-plugin-static-pages.test.ts (16/16 passing): duplicate-crossorigin avoidance + classic <script> non-rewrite.

@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

@pethers pethers merged commit 1a3cb89 into main May 11, 2026
23 checks passed
@pethers pethers deleted the copilot/fix-empty-dashboards branch May 11, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-cd CI/CD pipeline changes deployment Deployment configuration documentation Documentation updates html-css HTML/CSS changes javascript JavaScript code changes news News articles and content generation performance Performance optimization refactor Code refactoring rtl RTL language support (Arabic, Hebrew) size-l Large change (250-1000 lines) size-xl Extra large change (> 1000 lines) testing Test coverage translation Translation updates workflow GitHub Actions workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants