Skip to content

Comments

Fix SRI blocking Google Fonts and Chart.js/D3.js globals not registered#421

Merged
pethers merged 4 commits intomainfrom
copilot/fix-charts-in-dashboard
Feb 21, 2026
Merged

Fix SRI blocking Google Fonts and Chart.js/D3.js globals not registered#421
pethers merged 4 commits intomainfrom
copilot/fix-charts-in-dashboard

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

Charts broken on index and dashboard pages due to two independent issues: vite-plugin-sri-gen adding integrity hashes to Google Fonts links (which don't support CORS for SRI verification, causing browser to block them), and ES module side-effect imports (import 'chart.js/auto', import 'd3') not assigning to globalThis while all dashboard modules read from it.

SRI fix

  • Added skipResources to exclude external Google Fonts URLs from SRI generation
  • Local/bundled assets still have SRI enforced

Globals fix

  • New register-globals.ts module imports Chart.js/D3.js and assigns to globalThis
  • Entry points (main.ts, cia-entry.ts) import this before dashboard modules, ensuring globals are set before module-level const d3 = (globalThis as any).d3 executes in dependency order
// src/browser/shared/register-globals.ts
import { Chart } from 'chart.js/auto';
import 'chartjs-plugin-annotation';
import * as d3 from 'd3';

(globalThis as Record<string, unknown>).Chart = Chart;
(globalThis as Record<string, unknown>).d3 = d3;

Before

broken

After (22 Chart.js instances, 6 D3.js SVGs)

working


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 21, 2026 22:57
…bals

- Add skipResources to vite-plugin-sri-gen to exclude Google Fonts URLs
  that don't support CORS for SRI verification
- Create register-globals.ts to import Chart.js and D3.js and assign to
  globalThis, since dashboard modules access them via (globalThis).Chart
  and (globalThis).d3
- Update main.ts and cia-entry.ts to use register-globals instead of
  side-effect imports that don't set globals

Co-authored-by: pethers <[email protected]>
Copilot AI changed the title [WIP] Fix Riksdagsmonitor charts not loading on dashboard Fix SRI blocking Google Fonts and Chart.js/D3.js globals not registered Feb 21, 2026
Copilot AI requested a review from pethers February 21, 2026 23:09
@pethers pethers requested a review from Copilot February 21, 2026 23:19
@github-actions github-actions bot added javascript JavaScript code changes deployment Deployment configuration performance Performance optimization size-xl Extra large change (> 1000 lines) labels Feb 21, 2026
@github-actions
Copy link
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
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 fixes two independent bugs that broke Chart.js and D3.js visualizations on index and dashboard pages:

  1. SRI Configuration Issue: vite-plugin-sri-gen was adding integrity hashes to Google Fonts links, causing browsers to block them (Google Fonts don't support CORS for SRI verification)
  2. Global Registration Issue: Side-effect imports (import 'chart.js/auto', import 'd3') don't assign to globalThis, but dashboard modules read from globalThis

Changes:

  • Added skipResources to exclude Google Fonts URLs from SRI generation (security still enforced on bundled assets)
  • Created register-globals.ts to import Chart.js/D3.js as ES modules and explicitly assign to globalThis
  • Updated entry points (main.ts, cia-entry.ts) to import register-globals.ts before dashboard modules load

Reviewed changes

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

Show a summary per file
File Description
vite.config.js Added skipResources array to vite-plugin-sri-gen config to exclude Google Fonts URLs from SRI
src/browser/shared/register-globals.ts New module that imports Chart.js and D3.js as ES modules and assigns to globalThis
src/browser/main.ts Replaced side-effect imports with register-globals.js import
src/browser/cia-entry.ts Replaced side-effect imports with register-globals.js import
sitemap.xml Generated file with timestamp updates only

@pethers pethers marked this pull request as ready for review February 21, 2026 23:24
@pethers pethers merged commit b45bf6f into main Feb 21, 2026
28 of 29 checks passed
@pethers pethers deleted the copilot/fix-charts-in-dashboard branch February 21, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deployment Deployment configuration javascript JavaScript code changes performance Performance optimization size-xl Extra large change (> 1000 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants