Skip to content

Fix theme-toggle/anti-flash mismatch, Norwegian BCP-47 lang tag, and inline script CSP exposure#829

Merged
pethers merged 2 commits intomain-7a9239b964b147d1from
copilot/sub-pr-817
Mar 5, 2026
Merged

Fix theme-toggle/anti-flash mismatch, Norwegian BCP-47 lang tag, and inline script CSP exposure#829
pethers merged 2 commits intomain-7a9239b964b147d1from
copilot/sub-pr-817

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

Three independent bugs in the article generation pipeline, all introduced in recent sub-PRs:

Theme-toggle ↔ anti-flash snippet mismatch

The inline <script> used localStorage['theme'] and toggled document.body.classList, while the anti-flash head snippet uses riksdagsmonitor-theme and drives document.documentElement[data-theme]. Result: theme preference never persisted correctly across page loads.

Fix: Extracted to js/theme-toggle.js (external, cacheable) using the same key and same DOM hook:

// Before (inline, wrong key/target)
var STORAGE_KEY = 'theme';
document.body.classList.toggle('dark-theme', isDark);

// After (js/theme-toggle.js, aligned with anti-flash snippet)
var STORAGE_KEY = 'riksdagsmonitor-theme';
document.documentElement.setAttribute('data-theme', theme);

Norwegian BCP-47 language tag

<html lang="no"> and "inLanguage": "no" in JSON-LD — inconsistent with the already-correct hreflang="nb" tags on the same page. Template now uses hreflangCode(lang) for both attributes, so 'no''nb' everywhere.

Inline script CSP exposure

Moving theme-toggle to an external file eliminates the need for unsafe-inline for this script. Template replaced the 55-line inline block with <script src="../js/theme-toggle.js"></script>.

Scope

  • template.ts — all three fixes, affects all future-generated articles
  • All 14 2026-03-05-opposition-motions-*.html — inline script replaced with external reference
  • 2026-03-05-opposition-motions-no.htmllang/inLanguage patched directly
  • Two unit tests updated to assert nb (not no) for Norwegian output

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

…cript CSP issue

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copilot AI changed the title [WIP] Add opposition motions articles analysis for March 2026 Fix theme-toggle/anti-flash mismatch, Norwegian BCP-47 lang tag, and inline script CSP exposure Mar 5, 2026
@pethers pethers marked this pull request as ready for review March 5, 2026 13:06
@pethers pethers merged commit 5998e2c into main-7a9239b964b147d1 Mar 5, 2026
@pethers pethers deleted the copilot/sub-pr-817 branch March 5, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants