Skip to content

chore: update backstop to set themes via localstorage - #8279

Merged
mcoker merged 2 commits into
patternfly:mainfrom
mcoker:backstop-switch-to-localStorage
Apr 4, 2026
Merged

chore: update backstop to set themes via localstorage#8279
mcoker merged 2 commits into
patternfly:mainfrom
mcoker:backstop-switch-to-localStorage

Conversation

@mcoker

@mcoker mcoker commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Glass theme is returning a handful of random false positives, likely due to the size of the background image I imagine. This PR updates backstop to set themes via localStorage instead of adding classnames, which allows the page to load with the proper theme classes instead of adding them after the page renders.

The second commit updates the handful of false positives that this PR fixed.

Summary by CodeRabbit

  • Refactor
    • Refactored theme preference handling to use localStorage-based storage instead of CSS class injection.
    • Simplified dark mode detection by leveraging native color scheme emulation.
    • Streamlined theme application logic in the testing infrastructure.

@coderabbitai

coderabbitai Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR refactors theme handling in Backstop's Playwright engine scripts. It removes the applyThemeClasses.js helper and shifts theme application from direct DOM manipulation to localStorage-based preferences set via an init script in onBefore, enabling themes to be applied earlier during page initialization.

Changes

Cohort / File(s) Summary
Theme Handler Refactoring
backstop_data/engine_scripts/playwright/applyThemeClasses.js, backstop_data/engine_scripts/playwright/onBefore.js, backstop_data/engine_scripts/playwright/onReady.js
Removed applyThemeClasses.js helper that applied CSS theme classes via DOM manipulation. Introduced page.addInitScript() in onBefore to set localStorage keys (contrast-preference, theme-preference, theme-variant-preference) based on CLI flags (--felt, --dark, --glass, --high-contrast). Simplified onReady to only handle --dark flag with page.emulateMedia().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • srambach
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows conventional commit format with 'chore:' prefix and clearly describes the main change: updating backstop to set themes via localStorage instead of applying theme classes after page render.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@patternfly-build

patternfly-build commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backstop_data/engine_scripts/playwright/onBefore.js`:
- Around line 6-9: Detect and handle conflicting contrast flags passed via
process.argv by checking the boolean flags isGlass and isHighContrast together
and failing fast or normalizing them before any suffix or theme selection logic
runs: if both are present either throw an error (with a clear message) or pick a
single canonical preference and clear the other boolean, and then ensure the
same normalized value is used when building the rendered theme/path suffix (the
code that reads isGlass/isHighContrast to create suffix parts) so you never
produce a suffix like "_glass_hc" that won't be rendered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4a592e1c-9c12-42e1-94da-f2888fae9fe0

📥 Commits

Reviewing files that changed from the base of the PR and between 359353d and 7c4c8e3.

⛔ Files ignored due to path filters (12)
  • backstop_data/bitmaps_reference_glass/pf-core__components_clipboard-copy_html_inline-compact-with-additional-action_0_document_1_tablet.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_description-list_html_term-help-text_0_document_2_desktop.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_label_html_vertical-label-group-with-removable-category_0_document_1_tablet.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html-demos_horizontal-nav-with-horizontal-subnav_0_document_0_mobile.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html-demos_horizontal-subnav_0_document_0_mobile.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html_grouped-nav_0_document_0_mobile.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html_horizontal-subnav_0_document_1_tablet.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html_horizontal-subnav_0_document_2_desktop.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html_nav-item-icons_0_document_1_tablet.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_navigation_html_nav-item-icons_0_document_2_desktop.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_tooltip_html_top_0_document_1_tablet.png is excluded by !**/*.png
  • backstop_data/bitmaps_reference_glass/pf-core__components_tooltip_html_top_0_document_2_desktop.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • backstop_data/engine_scripts/playwright/applyThemeClasses.js
  • backstop_data/engine_scripts/playwright/onBefore.js
  • backstop_data/engine_scripts/playwright/onReady.js
💤 Files with no reviewable changes (1)
  • backstop_data/engine_scripts/playwright/applyThemeClasses.js

Comment on lines +6 to +9
const isFelt = process.argv.includes('--felt');
const isDark = process.argv.includes('--dark');
const isGlass = process.argv.includes('--glass');
const isHighContrast = process.argv.includes('--high-contrast');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Handle conflicting contrast flags explicitly.

On Line 6-9 and Line 14-18, --glass and --high-contrast can both be passed, but only one contrast preference is applied (contrast-high wins). Meanwhile backstop.js can still generate a combined suffix (e.g., _glass_hc), which risks writing/reading baselines under a theme label that is never actually rendered.

Please fail fast (or normalize flags in one shared place) to keep rendered theme and path suffix semantics aligned.

Suggested fix
   const isFelt = process.argv.includes('--felt');
   const isDark = process.argv.includes('--dark');
   const isGlass = process.argv.includes('--glass');
   const isHighContrast = process.argv.includes('--high-contrast');
+
+  if (isGlass && isHighContrast) {
+    throw new Error('`--glass` and `--high-contrast` are mutually exclusive.');
+  }

Also applies to: 14-18

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backstop_data/engine_scripts/playwright/onBefore.js` around lines 6 - 9,
Detect and handle conflicting contrast flags passed via process.argv by checking
the boolean flags isGlass and isHighContrast together and failing fast or
normalizing them before any suffix or theme selection logic runs: if both are
present either throw an error (with a clear message) or pick a single canonical
preference and clear the other boolean, and then ensure the same normalized
value is used when building the rendered theme/path suffix (the code that reads
isGlass/isHighContrast to create suffix parts) so you never produce a suffix
like "_glass_hc" that won't be rendered.

@mcoker
mcoker merged commit 9fc1a6b into patternfly:main Apr 4, 2026
5 checks passed
@mcoker
mcoker deleted the backstop-switch-to-localStorage branch April 4, 2026 05:17
@patternfly-build

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 6.5.0-prerelease.65 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants