Skip to content

Conversation

@Arukuen
Copy link
Contributor

@Arukuen Arukuen commented Oct 9, 2025

…vice type

fixes #3550

Summary by CodeRabbit

  • Improvements

    • Typography resets are now device-aware, preserving selector-specific styles while clearing size and spacing only for the current device.
    • Default font family is applied based on the active font pair during reset for more consistent results.
    • Detection of when a reset is needed now respects per-device values, reducing unnecessary changes.
  • Bug Fixes

    • Resolves inconsistencies where typography resets could unintentionally affect other devices or overlook device-specific settings.

@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

Walkthrough

Device-aware typography reset and comparison logic updated in src/plugins/global-settings/typography/index.js. Resets now target only the current device’s properties and derive fontFamily from the active pair. Allow-reset checks compare device-specific styles using a computed per-device snapshot and remove empty keys before applying.

Changes

Cohort / File(s) Summary
Typography device-aware reset and checks
src/plugins/global-settings/typography/index.js
- Reset builds per-selector object: preserves existing styles, sets fontFamily from default, clears device-specific keys (fontSize, fontSizeUnit, lineHeight, letterSpacing) for current device, then cleans empties
- Added getDefaultFontFamily helper
- Introduced typographyStyleOnCurrentDevice for comparisons
- Updated getIsAllowReset to use device-contextual values and short-circuit by device

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Global Typography UI
  participant Logic as Typography Logic
  participant Store as Settings Store

  rect rgba(235,245,255,0.7)
  note over UI,Logic: Determine if Reset button should show
  User->>UI: View selector (Desktop/Mobile/Tablet)
  UI->>Logic: getIsAllowReset(selector, device)
  Logic->>Logic: compute typographyStyleOnCurrentDevice
  Logic->>Store: fetch current typography + font pair
  Logic->>Logic: compare device-specific keys and fontFamily
  Logic-->>UI: allowReset (true/false)
  end

  alt User clicks Reset
    UI->>Logic: resetTypography(selector, device)
    Logic->>Store: read current per-selector styles
    Logic->>Logic: getDefaultFontFamily(fontPair)
    Logic->>Logic: clear device keys (fontSize, unit, lineHeight, letterSpacing)
    Logic->>Logic: clean empty keys
    Logic->>Store: apply updated styles
    Store-->>UI: updated state
  else No reset
    note over UI: No changes applied
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A rabbit taps through fonts with care,
Hops device to device, resets only there.
Desktop stays crisp, mobile keeps flair—
No more blanket sweeps through the air.
Ears perked high, styles clean and fair. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the main change by stating that resetting global typography now only affects the current device. It is concise, specific, and aligns with the functionality updated in the changeset. It avoids extraneous details or vague terms and is easily understood by teammates scanning the history.
Linked Issues Check ✅ Passed The code updates implement device-aware reset logic that only clears typography settings for the current device while preserving settings for other devices, fully satisfying the objectives of issue #3550. The updated getIsAllowReset function ensures the reset button only appears and operates in the correct device context, preventing desktop resets of mobile-specific settings. This maintains device-scoped global typography styles as expected by the linked issue.
Out of Scope Changes Check ✅ Passed The changes focus solely on adjusting the reset behavior for global typography on the current device and do not introduce modifications unrelated to the objectives of issue #3550. There are no unrelated features or files impacted by this pull request. The implementation is appropriately scoped to the global-settings/typography module.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/3550-typography-reset-on-device

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.

github-actions bot added a commit that referenced this pull request Oct 9, 2025
@github-actions
Copy link

github-actions bot commented Oct 9, 2025

🤖 Pull request artifacts

file commit
pr3621-stackable-3621-merge.zip 6ffec11

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 578783c and 6ffec11.

📒 Files selected for processing (1)
  • src/plugins/global-settings/typography/index.js (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/plugins/global-settings/typography/index.js (2)
src/plugins/global-settings/typography/utils.js (4)
  • getDevicePropertyKey (49-55)
  • getDevicePropertyKey (49-55)
  • cleanTypographyStyle (120-127)
  • cleanTypographyStyle (120-127)
src/plugins/global-settings/typography/editor-loader.js (1)
  • typographySettings (42-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: PHP 8.2 and WP 6.5.5
  • GitHub Check: PHP 7.3 and WP latest
  • GitHub Check: PHP 8.2 and WP latest
  • GitHub Check: PHP 8.2 and WP 6.7.2
  • GitHub Check: PHP 7.3 and WP 6.5.5
  • GitHub Check: PHP 8.2 and WP 6.6.2

Comment on lines 409 to 417
if ( ! isEditingFontPair && currentFontPair ) {
// Clean style object to be consistent with changeStyles operation
const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
if ( ! isEqual( fontPairStyle, typographyStyle ) && ! Array.isArray( typographyStyle ) ) {
if ( ! isEqual( fontPairStyle, typographyStyleOnCurrentDevice ) &&
! Array.isArray( typographyStyleOnCurrentDevice )
) {
return true
}
return false
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Comparison still trips reset in tablet/mobile

fontPairStyle retains the desktop/base keys (e.g. fontSize, fontSizeUnit), but typographyStyleOnCurrentDevice only keeps the current device keys (tabletFontSize, mobileFontSize, …). On tablet/mobile views this makes isEqual always fail—even when there are no device-specific overrides—so the Reset button still shows up. Please normalize the font pair snapshot to the current device before comparing.

-			const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
-			if ( ! isEqual( fontPairStyle, typographyStyleOnCurrentDevice ) &&
+			const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
+			const fontPairStyleOnCurrentDevice = cleanTypographyStyle( {
+				fontFamily: fontPairStyle?.fontFamily || '',
+				fontWeight: fontPairStyle?.fontWeight || '',
+				textTransform: fontPairStyle?.textTransform || '',
+				[ deviceFontSizeKey ]: fontPairStyle?.[ deviceFontSizeKey ] || '',
+				[ deviceFontSizeUnitKey ]: fontPairStyle?.[ deviceFontSizeUnitKey ] || '',
+				[ deviceLineHeightKey ]: fontPairStyle?.[ deviceLineHeightKey ] || '',
+				[ deviceLetterSpacingKey ]: fontPairStyle?.[ deviceLetterSpacingKey ] || '',
+			} ) || {}
+			if ( ! isEqual( fontPairStyleOnCurrentDevice, typographyStyleOnCurrentDevice ) &&
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ( ! isEditingFontPair && currentFontPair ) {
// Clean style object to be consistent with changeStyles operation
const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
if ( ! isEqual( fontPairStyle, typographyStyle ) && ! Array.isArray( typographyStyle ) ) {
if ( ! isEqual( fontPairStyle, typographyStyleOnCurrentDevice ) &&
! Array.isArray( typographyStyleOnCurrentDevice )
) {
return true
}
return false
if ( ! isEditingFontPair && currentFontPair ) {
// Clean style object to be consistent with changeStyles operation
const fontPairStyle = cleanTypographyStyle( currentFontPair.typography?.[ selector ] ) || {}
const fontPairStyleOnCurrentDevice = cleanTypographyStyle( {
fontFamily: fontPairStyle?.fontFamily || '',
fontWeight: fontPairStyle?.fontWeight || '',
textTransform: fontPairStyle?.textTransform || '',
[ deviceFontSizeKey ]: fontPairStyle?.[ deviceFontSizeKey ] || '',
[ deviceFontSizeUnitKey ]: fontPairStyle?.[ deviceFontSizeUnitKey ] || '',
[ deviceLineHeightKey ]: fontPairStyle?.[ deviceLineHeightKey ] || '',
[ deviceLetterSpacingKey ]: fontPairStyle?.[ deviceLetterSpacingKey ] || '',
} ) || {}
if ( ! isEqual( fontPairStyleOnCurrentDevice, typographyStyleOnCurrentDevice ) &&
! Array.isArray( typographyStyleOnCurrentDevice )
) {
return true
}
return false
🤖 Prompt for AI Agents
In src/plugins/global-settings/typography/index.js around lines 409-417, the
comparison fails because fontPairStyle contains desktop/base keys while
typographyStyleOnCurrentDevice contains only device-specific keys; normalize the
font pair snapshot to the current device before comparing by deriving a
device-specific object from currentFontPair.typography[selector] — map/translate
desktop/base properties to the current device equivalents (e.g., for device ===
'tablet' copy desktop fontSize/fontSizeUnit ->
tabletFontSize/tabletFontSizeUnit, same for mobile), then pass that normalized
device-specific object through cleanTypographyStyle and use isEqual against
typographyStyleOnCurrentDevice (keeping the existing Array.isArray guard).

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.

Global mobile typography setting displays reset button on desktop

1 participant