Skip to content

Stop conditional variants getting different heading levels - #1738

Open
slightlyoffbeat wants to merge 3 commits into
mainfrom
danb/heading-levels
Open

Stop conditional variants getting different heading levels#1738
slightlyoffbeat wants to merge 3 commits into
mainfrom
danb/heading-levels

Conversation

@slightlyoffbeat

Copy link
Copy Markdown
Contributor

Summary

Assign heading levels in Python instead of a Jinja counter, so conditional variants of the same block share a level rather than the second one getting an <h2>.

Key changes

  • New springfield/cms/block_slots.py + BlockSlotsMixin replace the namespace(headings=0) counter that was copy-pasted across 14 loops in 11 templates. Per-page config (slot_region_groups, slot_flat_levels, slot_start_level) reproduces each page's existing levels — the download page's blocks start at h2, the roadmap's intro owns the h1.
  • Conditional blocks that genuinely exclude each other now share one logical position, and therefore one heading level.
  • Exclusivity is inferred conservatively: blocks must differ on exactly one condition with values that can't both match. platforms=[windows] next to firefox=is-firefox are both visible to a Windows Firefox user, so they stay sequential.
  • Headingless blocks no longer inherit the page's level — a line_cards block with no heading of its own was rendering <h1 class="fl-heading-size-3"> per card.
  • No migrations; the custom StreamField keeps block changes out of them.

Behaviour matrix

Blocks in a region Levels before Levels after
Three plain blocks h1, h2, h2 unchanged
is-firefox + not-firefox + plain h1, h2, h2 h1, h1, h2
platforms=[windows] + is-firefox (both can show) h1, h2 unchanged
Headingless block first inherits h1 block template's own default
Five platform sections (Thanks page) h1, h2, h2, h2, h2 h1, h1, h1, h1, h1

Testing

  • springfield/cms/tests/test_block_slots.py — 23 unit tests (heading detection, level assignment, per-page config, the exclusivity rule) plus 3 rendering tests.
  • The ~25 existing tests in test_blocks.py that re-implement the old rule inline pass untouched — the behaviour-preservation check.
  • Replayed the old rule against every page in a local DB snapshot and diffed: the only real level changes are 17 Thanks pages and one What's New page, all conditional variants collapsing as intended.
  • Suite: 1632 passing. Five failures pre-existing on this branch.

Notes for reviewer

  • The Thanks page changes visibly. Its five platform sections are exclusive, so only one renders per visitor — Windows users saw <h1> at 80px, everyone else <h2> at 64px. All platforms now get 80px. That's the platforms being made consistent, not a redesign; section.html doesn't override heading_size, so the size class follows the level.
  • __str__ added to ReferralHubPage and ReferralGetFirefoxPage — ruff flagged them once the new base made them resolvable as models.
  • Follow-up worth having: an explicit heading-level override in page Settings, per Kasey's suggestion, for variants the rule can't infer (e.g. separated by another block).

@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.55%. Comparing base (cc4978f) to head (e058338).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1738      +/-   ##
==========================================
+ Coverage   88.43%   88.55%   +0.11%     
==========================================
  Files         171      172       +1     
  Lines       12093    12217     +124     
==========================================
+ Hits        10695    10819     +124     
  Misses       1398     1398              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucianoratamero

Copy link
Copy Markdown
Collaborator

hey 👋
I've talked with Mari about this, and I think we have a simpler solution to propose for the issue.
can we keep this PR on hold while I work on a separate solution, or do you need this merged now?

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