Skip to content

Preview most style setting changes instantly in the styler - #3782

Merged
Crabcyborg merged 5 commits into
masterfrom
feat/styler-live-preview-more-settings
Dec 1, 2026
Merged

Crabcyborg merged 5 commits into
masterfrom
feat/styler-live-preview-more-settings

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3780. Merge that one first, then retarget this PR to master.

Companion Pro PR: https://github.com/Strategy11/formidable-pro/pull/7057

In the Visual Styler, changing a label color (and most other settings) still sent a frm_change_styling request and waited for new CSS. The live preview only sets CSS variables for settings on FrmStylesHelper::get_live_preview_settings(), and many settings were left off because a CSS template printed the raw value instead of a var(). This PR moves those templates to CSS variables and adds the settings to the list, so about 30 more settings update instantly.

Changes

  • css/_single_theme.css.php outputs these as CSS variables: field description font size, color, weight, style, align and margin, check box and radio label color, weight and font size, label width, font, border color, text color, and submit width, height, border width and shadow color. Rules that the template skips for an empty value keep their ! empty() check.
  • The focus glow keeps its rgba() line and adds a color-mix( in srgb, var(--border-color-active) 60%, transparent ) line after it, so browsers without color-mix() keep the old glow.
  • get_live_preview_settings() adds the settings above. Settings that Pro templates use directly are added in two groups:
    • Field height and field border width are only live when Pro is not active, since every Pro version uses them directly.
    • Label color, font size, text color, focus border color, field padding, error text and success text color are live when Pro is not active, or when Pro has the frm_style_live_preview_settings filter (7.0.1 and later), which removes the ones that Pro version still uses directly. Pro before 7.0.1 gets none of them.
  • js/admin/style.js still requests new CSS when:
    • a value changes to or from empty, since the template leaves out those rules;
    • field height or submit width/height is auto, which switches a template branch;
    • the corner radius or a border width is overridden by the field shape, matching FrmStylesHelper::css_var_prepare_value.
  • Changing the field width also sets --auto-width when automatic drop-down width is off, matching get_settings_for_output.

Settings that still need the server: direction, submit margin and background image, collapse icon position, the field shape itself, check box and radio layout, and progress bar colors (Pro adjusts their brightness in PHP).

With Pro 7.0.1 to 7.1.1, the flatpickr date field focus glow does not update live, because those Pro versions print it directly. The companion Pro PR fixes that.

Testing

  1. Open Formidable > Styles and edit a style. Open the browser network panel.
  2. Change Field Labels > Color. The preview labels change right away and no frm_change_styling request is sent.
  3. Repeat for label font size, field text color, border color, corner radius, field description color/weight/style, check box label color and field width. Each updates without a request.
  4. Change Font when it was empty. One request is sent. Change it again and it updates without a request.
  5. Pick the Circle field shape, then change the corner radius. A request is sent and the radius stays 30px.
  6. Focus a field in the preview and change the active border color. The border and glow change without a request.

Verified in a headless browser on a dev site with Pro active, with these results and a clean debug log. PHPUnit for the style tests passes (24 tests). The new list assertions fail without the PHP change. phpcs, php-cs-fixer, rector, mago, phpstan and oxlint pass on the changed files. ESLint reports one existing prefer-destructuring warning on an unchanged line.

tests/js/style-live-preview.test.mjs covers the JS rules: a change to or from an empty value, auto field height and submit width/height, the field shape overrides for corner radius and border widths, and the extra --auto-width variable for field width. Each new test fails when its rule is removed from style.js. node --test tests/js/*.test.mjs passes (119 tests).

🤖 Generated with Claude Code

Output field description, check box label, label width, font, border,
text and submit size settings as CSS variables in the single style
template, so the styler preview can update them with JavaScript
instead of requesting new CSS.

Add the label color, font size and other settings Pro used directly
when Pro is not active, or when Pro has the filter to remove them.
Keep settings that switch a template branch, like an empty value or
auto, and the values the field shape overrides on the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e690e5a and 2fa0ff6.

Files selected for processing: 5

  • classes/helpers/FrmStylesHelper.php
  • css/_single_theme.css.php
  • js/admin/style.js
  • tests/js/style-live-preview.test.mjs
  • tests/phpunit/styles/test_FrmStylesHelper.php
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@deepsource-io

deepsource-io Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e690e5a...2fa0ff6 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Dec 1, 2026 7:02p.m. Review ↗
JavaScript Dec 1, 2026 7:02p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.86%. Comparing base (5ceaf7d) to head (3a7a867).
⚠️ Report is 23 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3782      +/-   ##
============================================
+ Coverage     48.77%   48.86%   +0.09%     
- Complexity    14330    14342      +12     
============================================
  Files           239      239              
  Lines         48151    48211      +60     
============================================
+ Hits          23484    23558      +74     
+ Misses        24667    24653      -14     

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

Base automatically changed from fix/styler-live-submit-button to master December 1, 2026 16:25
An error occurred while trying to automatically change base from fix/styler-live-submit-button to master December 1, 2026 16:25
@franky-the-going-merry franky-the-going-merry Bot added franky-working Franky is actively reviewing this and removed franky-working Franky is actively reviewing this labels Dec 1, 2026

@franky-the-going-merry franky-the-going-merry 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.

Request Changes: the repo's existing styler JS test fails on this head, and CI skipped the job that would show it. The new live-preview behaviour itself checks out in a browser.

Blocking

  • tests/js/style-live-preview.test.mjs (CI job "JS unit tests / Run node --test" was skipped): 14/14 pass on master's style.js, 5/14 pass at 3a7a867 (9 fail). canUpdateLive now reads previousValues[key], and the tests call it with two arguments (TypeError: Cannot read properties of undefined (reading 'title_color')). The updatePreview tests fail for the same reason, plus getCssVarNames is no longer defined in their runInNewContext globals. See the inline comment for the fix.
  • The PR description says the JS rules have no unit test because the runner cannot import them. That file already does exactly this (it loads canUpdateLive etc. out of initEditPage() with @babel/core). The new rules (switchesTemplateBranch, usesFieldShapeValue, getCssVarNames, the empty-to-or-from check) have no coverage. Add tests there as part of the fix.

Verified

  • node --test tests/js/style-live-preview.test.mjs at 3a7a867: 5 pass, 9 fail (above). Tests run in the PHP harness (php@8.4, phpunit 9.6): test_FrmStylesHelper 14/314 OK; other styles tests OK except test_FrmStylesController::test_front_head, a harness WP-core stylesheet path notice unrelated to this diff. The new list assertions fail when FrmStylesHelper.php is swapped back to master.
  • Live, preview env at 3a7a867 with Pro b52f678f9 (Pro 7.0.1+ filter active), Styles page, jQuery.ajax counted for requests. No frm_change_styling request for: description color / font size, border color, check label color, border radius (5px), submit shadow color, field width, font (second change). Computed style followed each change: description color rgb(255, 0, 255), input radius 5px, --auto-width 50% after field width 50%. One request, as the PR says, for: font '' to a value, field height, field border width, submit height/width (from empty or auto), and label_color (Pro's filter removes it until the companion Pro PR lands). Circle shape + border radius 12px: one request, radius stays 30px. All 25 new variables resolve at default values on the preview wrapper.
  • Not exercised: the companion Pro PR #7057, flatpickr glow with Pro 7.0.1 to 7.1.1, a front-end page with a saved non-default style, underline shape, Safari/Firefox without color-mix().

Skills not run (manual read). The PHP side (list gating by has_action / filter, empty-aware templates) looks right.

Comment thread js/admin/style.js
*/
function canUpdateLive( key, values ) {
if ( ! livePreview.settings.has( key ) || ! isSafeLiveValue( values[ key ] ) ) {
function canUpdateLive( key, values, previousValues ) {

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.

This signature change breaks tests/js/style-live-preview.test.mjs (14/14 on master, 5/14 here; CI skipped it). Fix in that file:

  • names (line 12): add 'switchesTemplateBranch', 'usesFieldShapeValue', 'getCssVarNames' so the extracted canUpdateLive and updatePreview can find them.
  • loadDecisions(): pass a previous-values object, e.g. canUpdateLive( key, values, values ) in the existing cases, and add getCssVarNames to the updatePreview globals in loadPreview() (getCssVarNames: key => [ key ]).
  • Add cases for: a change from '' to a value and a value to '' needs the server; field_height/submit_width/submit_height set to auto (new or previous) needs the server; border_radius under circle/regular/underline and field_border_width/border_width_error under underline need the server; getCssVarNames( 'field_width', { auto_width: '0' } ) returns both variables and with auto_width: '1' returns one.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Dec 1, 2026
Crabcyborg and others added 2 commits December 1, 2026 13:39
@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Addressed franky's review in 767d342 (also merged master in aea7e9f):

  • Blocking 1 (style-live-preview.test.mjs 9/14 failing): fixed in 767d342. Added switchesTemplateBranch, usesFieldShapeValue and getCssVarNames to the extracted names, canUpdateLive calls pass previous values, and getCssVarNames is stubbed in loadPreview(). Two existing tests now expect a server request where the previous value is empty or unknown (after clearing a color, after a failed request), matching the new to-or-from-empty rule, then check the next change is live again. node --test tests/js/*.test.mjs: 119/119 pass.
  • Blocking 2 (description claim, no coverage for the new rules): fixed in 767d342 with tests for the empty-to/from check, auto field_height/submit_width/submit_height (new or previous), border_radius under circle/regular/underline and border widths under underline, and getCssVarNames with auto_width 0/unset/1. Each fails when its rule is removed from style.js. PR description corrected.
  • Added the run analysis label so the JS unit test job runs.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Dec 1, 2026

@franky-the-going-merry franky-the-going-merry 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.

Approve. Both blockers from my last review are fixed at this head, and the live-preview behaviour still checks out.

Tests run: node --test tests/js/*.test.mjs at 2fa0ff6 → 133/133 pass (style-live-preview.test.mjs is back to green; it was 5/14 at 3a7a867). CI skipped the JS unit tests job, so this was a local run.

Verified

  • Blocker 1 (existing test failing): fixed. canUpdateLive calls pass previousValues, and getCssVarNames is in the stubbed globals.
  • Blocker 2 (new rules had no coverage): fixed. I removed each new rule from style.js in turn and re-ran the file: dropping the empty-to/from check fails 3 tests, dropping switchesTemplateBranch fails 1, dropping usesFieldShapeValue fails 1. The new tests catch their rules, so they are not hollow.
  • js/admin/style.js is unchanged since my last review apart from the master merge, so the rules I read then still stand.
  • Preview env at 2fa0ff6 (Styles page, jQuery.ajax counted for frm_change_styling): description color and border color changed with 0 requests, and the preview wrapper's --description-color / input border colour followed (#ff00ff, rgb(0, 255, 0)). field_height to auto sent 1 request, and auto back to 40px sent 1 (change from auto). Base font_size sent 1, as expected since the server scales font sizes from it.

Not exercised: the companion Pro PR #7057 (it still has my open change request on the Pro-derived toggle_font_size / date_head_color variables), a front-end page with a saved non-default style, underline shape, Safari/Firefox without color-mix(). Skills not run (manual read of the diff).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Dec 1, 2026
@Crabcyborg
Crabcyborg merged commit 54868ae into master Dec 1, 2026
48 of 50 checks passed
@Crabcyborg
Crabcyborg deleted the feat/styler-live-preview-more-settings branch December 1, 2026 19:42
@Crabcyborg Crabcyborg added this to the 7.2 milestone Dec 1, 2026
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.

1 participant